sql

package module
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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

func NewMySQL(db *sql.DB) *Adapter

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

func NewPostgreSQL(db *sql.DB) *Adapter

NewPostgreSQL wraps a standard *sql.DB with sqlx for PostgreSQL and returns an adapter.

func NewSQLite

func NewSQLite(db *sql.DB) *Adapter

NewSQLite wraps a standard *sql.DB with sqlx for SQLite and returns an adapter.

func (*Adapter) BeginTx

func (a *Adapter) BeginTx(ctx context.Context) (limen.DatabaseTx, error)

func (*Adapter) Commit

func (a *Adapter) Commit() error

func (*Adapter) Count

func (a *Adapter) Count(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where) (int64, error)

func (*Adapter) Create

func (a *Adapter) Create(ctx context.Context, tableName limen.SchemaTableName, data map[string]any) error

func (*Adapter) Delete

func (a *Adapter) Delete(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where) error

func (*Adapter) Exists

func (a *Adapter) Exists(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where) (bool, error)

func (*Adapter) FindMany

func (a *Adapter) FindMany(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where, options *limen.QueryOptions) ([]map[string]any, error)

func (*Adapter) FindOne

func (a *Adapter) FindOne(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where, orderBy []limen.OrderBy) (map[string]any, error)

func (*Adapter) Rollback

func (a *Adapter) Rollback() error

func (*Adapter) Update

func (a *Adapter) Update(ctx context.Context, tableName limen.SchemaTableName, conditions []limen.Where, updates map[string]any) (int64, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL