Versions in this module Expand all Collapse all v0 v0.1.0 Mar 30, 2026 Changes in this version + var ErrNestedTxControlNotAllowed = errors.New("rain: nested RunInTx callbacks cannot call Commit or Rollback directly") + var ErrNestedTxNotSupported = errors.New("rain: nested transactions are not supported by this dialect") + var ErrNoConnection = errors.New("rain: no database connection configured") + var ErrPrepareNotSupported = errors.New("rain: query runner does not support prepared statements") + var ErrPreparedArgsRequired = errors.New(...) + func BindModel[T any](table schema.TableReference) error + func BindTableModel[T any](table schema.TableReference) error + func MustBindModel[T any](table schema.TableReference) + func MustBindTableModel[T any](table schema.TableReference) + type DB struct + func Open(driver, dsn string) (*DB, error) + func OpenDialect(driver string) (*DB, error) + func WithReplicas(primary *DB, replicas []*DB, selector ReplicaSelector) (*DB, error) + func (db *DB) AddConstraintSQL(table schema.TableReference, constraintName string) (string, error) + func (db *DB) AddForeignKeySQL(table schema.TableReference, foreignKeyName string) (string, error) + func (db *DB) Begin(ctx context.Context) (*Tx, error) + func (db *DB) Close() error + func (db *DB) ColumnDefaultSQL(table schema.TableReference, columnName string) (string, error) + func (db *DB) ColumnDefinitionSQL(table schema.TableReference, columnName string) (string, error) + func (db *DB) CreateIndexesSQL(table schema.TableReference) ([]string, error) + func (db *DB) CreateTableSQL(table schema.TableReference) (string, error) + func (db *DB) Delete() *DeleteQuery + func (db *DB) Dialect() dialect.Dialect + func (db *DB) Exec(ctx context.Context, query string, args ...any) (sql.Result, error) + func (db *DB) Insert() *InsertQuery + func (db *DB) InvalidateQueryCache(ctx context.Context, tags ...string) error + func (db *DB) Primary() *DB + func (db *DB) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error) + func (db *DB) QueryRow(ctx context.Context, query string, args ...any) *sql.Row + func (db *DB) RunInTx(ctx context.Context, fn func(*Tx) error) error + func (db *DB) Select() *SelectQuery + func (db *DB) Update() *UpdateQuery + func (db *DB) WithQueryCache(cache QueryCache) *DB + type DeleteQuery struct + func (q *DeleteQuery) Exec(ctx context.Context) (sql.Result, error) + func (q *DeleteQuery) Returning(exprs ...schema.Expression) *DeleteQuery + func (q *DeleteQuery) Scan(ctx context.Context, dest any) error + func (q *DeleteQuery) Table(table schema.TableReference) *DeleteQuery + func (q *DeleteQuery) ToSQL() (string, []any, error) + func (q *DeleteQuery) Unbounded() *DeleteQuery + func (q *DeleteQuery) Where(predicate schema.Predicate) *DeleteQuery + type InsertConflictBuilder struct + func (b *InsertConflictBuilder) DoNothing() *InsertQuery + func (b *InsertConflictBuilder) DoUpdateSet(columns ...schema.ColumnReference) *InsertQuery + type InsertQuery struct + func (q *InsertQuery) Exec(ctx context.Context) (sql.Result, error) + func (q *InsertQuery) Model(model any) *InsertQuery + func (q *InsertQuery) Models(models any) *InsertQuery + func (q *InsertQuery) OnConflict(columns ...schema.ColumnReference) *InsertConflictBuilder + func (q *InsertQuery) Returning(exprs ...schema.Expression) *InsertQuery + func (q *InsertQuery) Scan(ctx context.Context, dest any) error + func (q *InsertQuery) Set(column schema.ColumnReference, value any) *InsertQuery + func (q *InsertQuery) Table(table schema.TableReference) *InsertQuery + func (q *InsertQuery) ToSQL() (string, []any, error) + func (q *InsertQuery) Values(rows ...map[schema.ColumnReference]any) *InsertQuery + type JSON struct + V T + func (j *JSON[T]) Scan(src any) error + func (j JSON[T]) Value() (driver.Value, error) + type MemoryQueryCache struct + func NewMemoryQueryCache() *MemoryQueryCache + func (c *MemoryQueryCache) Get(_ context.Context, key string) ([]byte, bool, error) + func (c *MemoryQueryCache) InvalidateTags(_ context.Context, tags ...string) error + func (c *MemoryQueryCache) Set(_ context.Context, key string, value []byte, ttl time.Duration, tags []string) error + type PreparedArgs map[string]any + type PreparedSelectQuery struct + func (p *PreparedSelectQuery) Close() error + func (p *PreparedSelectQuery) Count(ctx context.Context, args PreparedArgs) (int64, error) + func (p *PreparedSelectQuery) Exists(ctx context.Context, args PreparedArgs) (bool, error) + func (p *PreparedSelectQuery) Scan(ctx context.Context, args PreparedArgs, dest any) error + type QueryCache interface + Get func(ctx context.Context, key string) ([]byte, bool, error) + InvalidateTags func(ctx context.Context, tags ...string) error + Set func(ctx context.Context, key string, value []byte, ttl time.Duration, ...) error + type QueryCacheOptions struct + Bypass bool + Key string + Namespace string + TTL time.Duration + Tags []string + type ReplicaSelector func(replicas []*DB) *DB + type SelectQuery struct + func (q *SelectQuery) Cache(options QueryCacheOptions) *SelectQuery + func (q *SelectQuery) Column(cols ...schema.Expression) *SelectQuery + func (q *SelectQuery) Count(ctx context.Context) (int64, error) + func (q *SelectQuery) Distinct() *SelectQuery + func (q *SelectQuery) Exists(ctx context.Context) (bool, error) + func (q *SelectQuery) GroupBy(exprs ...schema.Expression) *SelectQuery + func (q *SelectQuery) Having(predicate schema.Predicate) *SelectQuery + func (q *SelectQuery) Join(table schema.TableReference, on schema.Predicate) *SelectQuery + func (q *SelectQuery) JoinSubquery(query *SelectQuery, alias string, on schema.Predicate) *SelectQuery + func (q *SelectQuery) LeftJoin(table schema.TableReference, on schema.Predicate) *SelectQuery + func (q *SelectQuery) LeftJoinSubquery(query *SelectQuery, alias string, on schema.Predicate) *SelectQuery + func (q *SelectQuery) Limit(limit int) *SelectQuery + func (q *SelectQuery) Offset(offset int) *SelectQuery + func (q *SelectQuery) OrderBy(order ...schema.OrderExpr) *SelectQuery + func (q *SelectQuery) Prepare(ctx context.Context) (*PreparedSelectQuery, error) + func (q *SelectQuery) Scan(ctx context.Context, dest any) error + func (q *SelectQuery) Table(table schema.TableReference) *SelectQuery + func (q *SelectQuery) TableSubquery(query *SelectQuery, alias string) *SelectQuery + func (q *SelectQuery) ToSQL() (string, []any, error) + func (q *SelectQuery) Where(predicate schema.Predicate) *SelectQuery + func (q *SelectQuery) With(name string, query *SelectQuery) *SelectQuery + func (q *SelectQuery) WithRelations(names ...string) *SelectQuery + type Set struct + Valid bool + Value T + type Tx struct + func (tx *Tx) Commit() error + func (tx *Tx) Delete() *DeleteQuery + func (tx *Tx) Insert() *InsertQuery + func (tx *Tx) InvalidateQueryCache(ctx context.Context, tags ...string) error + func (tx *Tx) Rollback() error + func (tx *Tx) RunInTx(ctx context.Context, fn func(*Tx) error) error + func (tx *Tx) Select() *SelectQuery + func (tx *Tx) Update() *UpdateQuery + type UpdateQuery struct + func (q *UpdateQuery) Exec(ctx context.Context) (sql.Result, error) + func (q *UpdateQuery) Returning(exprs ...schema.Expression) *UpdateQuery + func (q *UpdateQuery) Scan(ctx context.Context, dest any) error + func (q *UpdateQuery) Set(column schema.ColumnReference, value any) *UpdateQuery + func (q *UpdateQuery) Table(table schema.TableReference) *UpdateQuery + func (q *UpdateQuery) ToSQL() (string, []any, error) + func (q *UpdateQuery) Unbounded() *UpdateQuery + func (q *UpdateQuery) Where(predicate schema.Predicate) *UpdateQuery