Documentation ¶
Index ¶
- Constants
- Variables
- func Jsonb(value map[string]any) *jsonbValuer
- func QuoteIdentifier(name string) string
- func QuoteLiteral(literal string) string
- func ScanJsonb(dest any) *jsonbScanner
- type Config
- type Database
- func (d *Database) AddMigration(version, description string, prepare MigrationPrepare) error
- func (d *Database) AddMigrations(dir fs.FS) error
- func (d *Database) Begin() (*Database, error)
- func (d *Database) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Database, error)
- func (d *Database) Close() error
- func (d *Database) CloseConn() error
- func (d *Database) Commit() error
- func (d *Database) Conn() (*Database, error)
- func (d *Database) DeleteWhere(table string, condition map[string]interface{}) (sql.Result, error)
- func (d *Database) Execute(query string, args ...interface{}) (sql.Result, error)
- func (d *Database) InsertInto(schema, table string, values map[string]interface{}) (sql.Result, error)
- func (d *Database) Migrate(config *MigrationConfig) error
- func (d *Database) Prepare(query string) (*sql.Stmt, error)
- func (d *Database) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (d *Database) QueryForBoolean(query string, args ...interface{}) (bool, error)
- func (d *Database) QueryForInt(query string, args ...interface{}) (int64, error)
- func (d *Database) QueryRow(query string, args ...interface{}) (row *sql.Row, err error)
- func (d *Database) QueryRowOld(query string, args ...interface{}) *RowWraper
- func (d *Database) Rollback() error
- func (d *Database) Savepoint(savepoint string, callback func() error) error
- func (d *Database) SelectRowWhere(table string, fields map[string]interface{}, condition map[string]interface{}) error
- func (d *Database) SetLogger(logger Logger)
- func (d *Database) Transaction(callback func(db *Database) error) error
- func (d *Database) Update(schema, table string, values map[string]interface{}, ...) (sql.Result, error)
- func (d *Database) UpdateOptimisticLock(schema, table string, values map[string]interface{}, ...) (sql.Result, error)
- func (d *Database) Upsert(table string, values map[string]interface{}, conflictField string) (sql.Result, error)
- type Logger
- type Migration
- type MigrationCommandFn
- type MigrationConfig
- type MigrationInfo
- type MigrationPrepare
- type MigrationState
- type MigrationStateInfo
- type Model
- type Query
- type Row
- type RowWraper
- type Table
- type UserModel
Constants ¶
const ( MigrationPending MigrationState = 0 // This migration has not been applied yet. MigrationSuccess = 1 // This migration succeeded. (Applied) MigrationFailed = 2 // This migration failed. (Applied) )
Variables ¶
var ( ErrNoInstance = errors.New("there is no active database instance") ErrManyInstances = errors.New("there is more than one active database instance") )
var ErrOptimisticLock = errors.New("optimistic locking conflict occurs")
var ErrUnsupportedDataType = errors.New("unsupported data type")
Functions ¶
func QuoteIdentifier ¶
func QuoteLiteral ¶
Types ¶
type Config ¶
type Config struct { Username string // The username to connect with. Password string // The password to connect with Host string // Specifies the host name on which PostgreSQL is running. Port int // The TCP port of the PostgreSQL server. Database string // The PostgreSQL database to connect to. SSLMode string // Controls whether SSL is used, depending on server support. Params map[string][]string // Connection params DebugSql bool // debug queries Logger Logger // Logger instance }
Config database config
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func GetInstance ¶
func (*Database) AddMigration ¶
func (d *Database) AddMigration(version, description string, prepare MigrationPrepare) error
AddMigration register a new migration
func (*Database) AddMigrations ¶
AddMigrations automatically registers all migration files in a directory.
func (*Database) Conn ¶
Conn returns a Database with a new connection
Every Conn must be returned to the pool after use by calling Database.CloseConn.
func (*Database) DeleteWhere ¶
DeleteWhere Executa um DELETE FROM WHERE
func (*Database) Execute ¶
Execute executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Database) InsertInto ¶
func (d *Database) InsertInto(schema, table string, values map[string]interface{}) (sql.Result, error)
InsertInto Executa um Insert Into
func (*Database) Migrate ¶
func (d *Database) Migrate(config *MigrationConfig) error
Migrate run all migrations
func (*Database) Query ¶
Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.
func (*Database) QueryForBoolean ¶
func (*Database) QueryForInt ¶
QueryForInt Obtém o resultado de uma query que busca por um valor. IMPORTANTE! Quando a query nao retornar registros esse método ira retornar 0 como resposta
func (*Database) QueryRowOld ¶
func (*Database) SelectRowWhere ¶
func (d *Database) SelectRowWhere(table string, fields map[string]interface{}, condition map[string]interface{}) error
SelectRowWhere Executa um SELECT FROM WHERE
func (*Database) Transaction ¶
Transaction Executes this callback within a transaction
func (*Database) Update ¶
func (d *Database) Update( schema, table string, values map[string]interface{}, condition map[string]interface{}, ) (sql.Result, error)
Update Executa uma query UPDATE SET values WHERE condition
type Logger ¶
type Logger interface { Error(err error) Info(string, ...interface{}) Warn(string, ...interface{}) }
Logger is implemented by any logging system that is used for standard logs.
type Migration ¶
type Migration struct { Repeat bool Info *MigrationInfo Prepare MigrationPrepare // contains filtered or unexported fields }
func (*Migration) ExecFn ¶
func (m *Migration) ExecFn(name string, callback MigrationCommandFn, args ...interface{})
ExecFn Schedule the execution of a golang command in this migration
type MigrationCommandFn ¶
type MigrationConfig ¶
type MigrationConfig struct { Username string // The username to connect with. Password string // The password to connect with. Schema string // migrationHistory schema name (defaults public) Table string // migrationHistory table name (defaults pg_schema_history) }
MigrationConfig database config
type MigrationInfo ¶
type MigrationInfo struct { Version string // The Version of the schema after the migration is complete. State MigrationState // The state of the migration (MigrationPending, MigrationSuccess, ...) Description string // The description of the migration InstalledRank int // The rank of this installed migration. Checksum string // Computed checksum of the migration. }
func (*MigrationInfo) Identifier ¶
func (i *MigrationInfo) Identifier() string
type MigrationPrepare ¶
type MigrationPrepare func(context *Migration)
type MigrationState ¶
type MigrationState int
type MigrationStateInfo ¶
MigrationStateInfo The state of a migration.
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
func (*Row) ColumnTypes ¶
func (r *Row) ColumnTypes() ([]*sql.ColumnType, error)
type RowWraper ¶
type RowWraper struct {
// contains filtered or unexported fields
}
RowWraper Wraper para trabalhar com o sql.Row, que tem propriedades privadas