Versions in this module Expand all Collapse all v0 v0.0.2 May 10, 2024 v0.0.1 Nov 26, 2023 Changes in this version + const MigrationFailed + const MigrationPending + const MigrationSuccess + var ErrManyInstances = errors.New("there is more than one active database instance") + var ErrNoInstance = errors.New("there is no active database instance") + var ErrOptimisticLock = errors.New("optimistic locking conflict occurs") + var ErrUnsupportedDataType = errors.New("unsupported data type") + func Jsonb(value map[string]any) *jsonbValuer + func QuoteIdentifier(name string) string + func QuoteLiteral(literal string) string + func ScanJsonb(dest any) *jsonbScanner + type Config struct + Database string + DebugSql bool + Host string + Logger Logger + Params map[string][]string + Password string + Port int + SSLMode string + Username string + func (c *Config) ConnString(customParams map[string]string) string + type Database struct + func GetInstance() (*Database, error) + func Open(config *Config) (*Database, error) + 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 interface + Error func(err error) + Info func(string, ...interface{}) + Warn func(string, ...interface{}) + type Migration struct + Info *MigrationInfo + Prepare MigrationPrepare + Repeat bool + func (m *Migration) ExecFn(name string, callback MigrationCommandFn, args ...interface{}) + func (m *Migration) ExecSql(sql string, args ...interface{}) + type MigrationCommandFn func(db *Database, migration *Migration, args ...interface{}) error + type MigrationConfig struct + Password string + Schema string + Table string + Username string + type MigrationInfo struct + Checksum string + Description string + InstalledRank int + State MigrationState + Version string + func (i *MigrationInfo) Identifier() string + type MigrationPrepare func(context *Migration) + type MigrationState int + type MigrationStateInfo struct + Applied bool + DisplayName string + Failed bool + type Model struct + Data []T + func NewModel[T any](data []T) *Model[T] + func (m *Model[T]) Method(r *T) T + func (m Model[T]) Create() *T + type Query struct + func NewQuery(query string, mapper func(rows *Row) (model any, err error)) *Query + func (q *Query) Retry(retries int) *Query + func (q *Query) SelectAll(args ...any) (result []any, err error) + func (q *Query) SelectOne(args ...any) (result any, err error) + func (q *Query) With(db *Database) *Query + type Row struct + func (r *Row) ColumnTypes() ([]*sql.ColumnType, error) + func (r *Row) Columns() ([]string, error) + func (r *Row) Scan(dest ...any) error + type RowWraper struct + func (r *RowWraper) Err() error + func (r *RowWraper) Scan(dest ...interface{}) error + type Table struct + func NewTable[T any](schema, name string, model T) (*Table[T], error) + func (t *Table[T]) Insert(values ...T) (bool, error) + func (t *Table[T]) Using(db *Database) *Table[T] + type UserModel struct + Email string + Id string