Documentation
¶
Index ¶
- type Adapter
- func (a *Adapter) BeginTx(ctx context.Context) (limen.DatabaseTx, error)
- func (a *Adapter) Commit() error
- func (a *Adapter) Count(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where) (int64, error)
- func (a *Adapter) Create(ctx context.Context, tableName limen.SchemaTableName, data map[string]any) error
- func (a *Adapter) Delete(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where) error
- func (a *Adapter) Exists(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where) (bool, error)
- func (a *Adapter) FindMany(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where, ...) ([]map[string]any, error)
- func (a *Adapter) FindOne(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where, ...) (map[string]any, error)
- func (a *Adapter) Rollback() error
- func (a *Adapter) Update(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where, ...) (int64, error)
- func (a *Adapter) WithLogger(logger QueryLogger) *Adapter
- type QueryLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements limen.DatabaseAdapter using sqlx (extensions on database/sql).
func NewMySQL ¶
NewMySQL wraps a standard *sql.DB with sqlx for MySQL and returns an adapter.
The go-sql-driver/mysql text protocol returns []byte for string columns (see github.com/go-sql-driver/mysql/issues/407). This adapter normalizes []byte to string after MapScan so both text and binary (prepared) protocols work.
func NewPostgreSQL ¶
NewPostgreSQL wraps a standard *sql.DB with sqlx for PostgreSQL and returns an adapter.
func (*Adapter) WithLogger ¶
func (a *Adapter) WithLogger(logger QueryLogger) *Adapter
WithLogger returns a copy of the adapter with the given query logger set. When non-nil, each executed query is logged (query, args, duration, error).
type QueryLogger ¶
type QueryLogger interface {
LogQuery(ctx context.Context, query string, args any, duration time.Duration, err error)
}
QueryLogger is called for each executed query when set on the adapter. Duration is the wall-clock time of the DB round-trip; args may be []any or map for named params.