dew

package module
v0.0.0-...-0efdd43 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

README

Dew

CI codecov Go Reference Go Report Card

A lightweight, type-safe query builder for Go. No ORM magic, no repo layers — just queries.

Documentation | Getting Started | Examples

Philosophy

Dew is not an ORM — it's a query builder that's expressive enough to replace the repository layer entirely. Instead of wrapping queries behind interfaces, you write them inline where you need them:

user, err := Users.From(db).Where(Users.Email.Eq(email)).One(ctx)

Traditional repository layers add indirection without adding safety — you still write SQL-shaped code inside them. Dew gives you type-safe, composable queries that read like SQL, so the abstraction becomes unnecessary.

Every builder accepts dew.Querier (satisfied by both *DB and *Tx), so transaction support comes for free — pass tx instead of db, same code, no wrapper needed. Zero codegen, zero reflection at build time, just Go generics.

Install

go get github.com/dr3dnought/dew

Quick Start

db, err := dew.Open("postgres", connStr, dew.PostgreSQLDialect{})

// SELECT
users, err := Users.From(db).
    Where(Users.Age.Gte(18)).
    OrderBy(dew.Desc(Users.Name)).
    Limit(10).
    All(ctx)

// INSERT
err = Users.Insert(db).
    Columns(Users.Name, Users.Email).
    Values("Alice", "[email protected]").
    Exec(ctx)

// UPDATE
err = Users.Update(db).
    Set(Users.Name, "Bob").
    Where(Users.ID.Eq(1)).
    Exec(ctx)

// DELETE
err = Users.Delete(db).
    Where(Users.ID.Eq(1)).
    Exec(ctx)

Supported Dialects

Dialect Placeholders
PostgreSQL $1, $2, ...
MySQL ?, ?, ...
SQLite ?, ?, ...
MSSQL @p1, @p2, ...

Works with any database/sql driver — pgx, lib/pq, go-sql-driver/mysql, modernc/sqlite, and more.

Documentation

Full docs at dew.xenous.org — schema definition, joins, CTEs, batch insert, error mapping, JSONB, set operations, and more.

License

MIT - see LICENSE file for details.

Documentation

Overview

TODO:

Check if alias pointer is nil or not in As method

Index

Constants

View Source
const (
	InnerJoinType joinType = "INNER JOIN"
	LeftJoinType  joinType = "LEFT JOIN"
	RightJoinType joinType = "RIGHT JOIN"
)

Variables

View Source
var (
	ErrNotFound        = errors.New("dew: record not found")
	ErrUniqueViolation = errors.New("dew: unique constraint violation")
	ErrForeignKey      = errors.New("dew: foreign key violation")
	ErrCheckViolation  = errors.New("dew: check constraint violation")
	ErrNotNull         = errors.New("dew: not null violation")
)

Functions

func Avg

func Avg(col Expression) *aggColumn

func CTE

func CTE(name string, query Expression) cteClause

func Count

func Count(columns ...Column) *aggColumn

func DefineSchema

func DefineSchema[T any, S any](tableName string, dialect Dialect, builder func(Table[T]) S) S

func Max

func Max(col Expression) *aggColumn

func Min

func Min(col Expression) *aggColumn

func RecursiveCTE

func RecursiveCTE(name string, query Expression) cteClause

func Sum

func Sum(col Expression) *aggColumn

Types

type AGREGATE_FUNCTION_TYPE

type AGREGATE_FUNCTION_TYPE string
const (
	SUM   AGREGATE_FUNCTION_TYPE = "SUM"
	AVG   AGREGATE_FUNCTION_TYPE = "AVG"
	MAX   AGREGATE_FUNCTION_TYPE = "MAX"
	MIN   AGREGATE_FUNCTION_TYPE = "MIN"
	COUNT AGREGATE_FUNCTION_TYPE = "COUNT"
)

type AnyColumn

type AnyColumn struct {
	// contains filtered or unexported fields
}

func (AnyColumn) Alias

func (c AnyColumn) Alias() *string

func (AnyColumn) Args

func (c AnyColumn) Args() []any

func (AnyColumn) As

func (c AnyColumn) As(alias string) AnyColumn

func (AnyColumn) Between

func (c AnyColumn) Between(min, max any) Expression

func (AnyColumn) ColumnName

func (c AnyColumn) ColumnName() string

func (AnyColumn) Eq

func (c AnyColumn) Eq(val any) Expression

func (AnyColumn) EqSub

func (c AnyColumn) EqSub(subQuery Expression) Expression

func (AnyColumn) Gt

func (c AnyColumn) Gt(val any) Expression

func (AnyColumn) Gte

func (c AnyColumn) Gte(val any) Expression

func (AnyColumn) In

func (c AnyColumn) In(vals ...any) Expression

func (AnyColumn) InSub

func (c AnyColumn) InSub(subQuery Expression) Expression

func (AnyColumn) IsNotNull

func (c AnyColumn) IsNotNull() Expression

func (AnyColumn) IsNull

func (c AnyColumn) IsNull() Expression

func (AnyColumn) Lt

func (c AnyColumn) Lt(val any) Expression

func (AnyColumn) Lte

func (c AnyColumn) Lte(val any) Expression

func (AnyColumn) NotEq

func (c AnyColumn) NotEq(val any) Expression

func (AnyColumn) NotEqSub

func (c AnyColumn) NotEqSub(subQuery Expression) Expression

func (AnyColumn) NotIn

func (c AnyColumn) NotIn(vals ...any) Expression

func (AnyColumn) NotInSub

func (c AnyColumn) NotInSub(subQuery Expression) Expression

func (AnyColumn) Sql

func (c AnyColumn) Sql() string

func (AnyColumn) TableName

func (c AnyColumn) TableName() string

type BoolColumn

type BoolColumn struct {
	// contains filtered or unexported fields
}

func (BoolColumn) Alias

func (c BoolColumn) Alias() *string

func (BoolColumn) Args

func (c BoolColumn) Args() []any

func (BoolColumn) As

func (c BoolColumn) As(alias string) BoolColumn

func (BoolColumn) ColumnName

func (c BoolColumn) ColumnName() string

func (BoolColumn) Eq

func (c BoolColumn) Eq(val bool) Expression

func (BoolColumn) IsFalse

func (c BoolColumn) IsFalse() Expression

func (BoolColumn) IsNotNull

func (c BoolColumn) IsNotNull() Expression

func (BoolColumn) IsNull

func (c BoolColumn) IsNull() Expression

func (BoolColumn) IsTrue

func (c BoolColumn) IsTrue() Expression

func (BoolColumn) NotEq

func (c BoolColumn) NotEq(val bool) Expression

func (BoolColumn) Sql

func (c BoolColumn) Sql() string

func (BoolColumn) TableName

func (c BoolColumn) TableName() string

type BytesColumn

type BytesColumn struct {
	// contains filtered or unexported fields
}

func (BytesColumn) Alias

func (c BytesColumn) Alias() *string

func (BytesColumn) Args

func (c BytesColumn) Args() []any

func (BytesColumn) As

func (c BytesColumn) As(alias string) BytesColumn

func (BytesColumn) ColumnName

func (c BytesColumn) ColumnName() string

func (BytesColumn) Eq

func (c BytesColumn) Eq(val []byte) Expression

func (BytesColumn) IsNotNull

func (c BytesColumn) IsNotNull() Expression

func (BytesColumn) IsNull

func (c BytesColumn) IsNull() Expression

func (BytesColumn) NotEq

func (c BytesColumn) NotEq(val []byte) Expression

func (BytesColumn) Sql

func (c BytesColumn) Sql() string

func (BytesColumn) TableName

func (c BytesColumn) TableName() string

type Column

type Column interface {
	Expression
	ColumnName() string
	TableName() string
	Alias() *string
}

func As

func As(exp Expression, alias string) Column

type ConflictActionType

type ConflictActionType string
const (
	ConflictActionTypeNothing ConflictActionType = "NOTHING"
	ConflictActionTypeUpdate  ConflictActionType = "UPDATE"
)

type ConflictInserter

type ConflictInserter[T any] struct {
	*Inserter[T]
	// contains filtered or unexported fields
}

func (*ConflictInserter[T]) Batch

func (i *ConflictInserter[T]) Batch(size int) *ConflictInserter[T]

func (*ConflictInserter[T]) DoNothing

func (i *ConflictInserter[T]) DoNothing() *ConflictInserter[T]

func (*ConflictInserter[T]) Exec

func (i *ConflictInserter[T]) Exec(ctxs ...context.Context) error

func (*ConflictInserter[T]) ScanWith

func (i *ConflictInserter[T]) ScanWith(scanner func(*sql.Rows) (*T, error), ctxs ...context.Context) ([]*T, error)

func (*ConflictInserter[T]) SetUpdate

func (i *ConflictInserter[T]) SetUpdate(col Column, val any) *ConflictInserter[T]

func (*ConflictInserter[T]) ToSql

func (i *ConflictInserter[T]) ToSql() (string, []any, error)

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

func NewDB

func NewDB(db *sql.DB, dialect Dialect, opts ...DBOption) *DB

NewDB wraps an existing *sql.DB with a dialect and options.

func Open

func Open(driverName, dataSourceName string, dialect Dialect, opts ...DBOption) (*DB, error)

func (*DB) Begin

func (db *DB) Begin() (*Tx, error)

Begin starts a new transaction with default options.

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginTx starts a new transaction with the given options.

type DBOption

type DBOption func(*DB)

DBOption configures a DB instance.

func WithErrorMapper

func WithErrorMapper(mapper ErrorMapper) DBOption

WithErrorMapper sets a custom error mapper for the DB.

type DecimalColumn

type DecimalColumn struct {
	// contains filtered or unexported fields
}

func (DecimalColumn) Alias

func (c DecimalColumn) Alias() *string

func (DecimalColumn) Args

func (c DecimalColumn) Args() []any

func (DecimalColumn) As

func (c DecimalColumn) As(alias string) DecimalColumn

func (DecimalColumn) Between

func (c DecimalColumn) Between(min, max string) Expression

func (DecimalColumn) ColumnName

func (c DecimalColumn) ColumnName() string

func (DecimalColumn) Eq

func (c DecimalColumn) Eq(val string) Expression

func (DecimalColumn) EqSub

func (c DecimalColumn) EqSub(subQuery Expression) Expression

func (DecimalColumn) Gt

func (c DecimalColumn) Gt(val string) Expression

func (DecimalColumn) Gte

func (c DecimalColumn) Gte(val string) Expression

func (DecimalColumn) In

func (c DecimalColumn) In(vals ...string) Expression

func (DecimalColumn) InSub

func (c DecimalColumn) InSub(subQuery Expression) Expression

func (DecimalColumn) IsNotNull

func (c DecimalColumn) IsNotNull() Expression

func (DecimalColumn) IsNull

func (c DecimalColumn) IsNull() Expression

func (DecimalColumn) Lt

func (c DecimalColumn) Lt(val string) Expression

func (DecimalColumn) Lte

func (c DecimalColumn) Lte(val string) Expression

func (DecimalColumn) NotEq

func (c DecimalColumn) NotEq(val string) Expression

func (DecimalColumn) NotEqSub

func (c DecimalColumn) NotEqSub(subQuery Expression) Expression

func (DecimalColumn) NotIn

func (c DecimalColumn) NotIn(vals ...string) Expression

func (DecimalColumn) NotInSub

func (c DecimalColumn) NotInSub(subQuery Expression) Expression

func (DecimalColumn) Sql

func (c DecimalColumn) Sql() string

func (DecimalColumn) TableName

func (c DecimalColumn) TableName() string

type Deleter

type Deleter[T any] struct {
	// contains filtered or unexported fields
}

func Delete

func Delete[T any](db Querier, table Tabler) *Deleter[T]

func (*Deleter[T]) Clone

func (d *Deleter[T]) Clone() *Deleter[T]

func (*Deleter[T]) Exec

func (d *Deleter[T]) Exec(ctxs ...context.Context) error

func (*Deleter[T]) Returning

func (d *Deleter[T]) Returning(cols ...Column) *Deleter[T]

func (*Deleter[T]) RowsAffected

func (d *Deleter[T]) RowsAffected(ctxs ...context.Context) (int64, error)

func (*Deleter[T]) Scan

func (d *Deleter[T]) Scan(ctx context.Context, dest ...any) error

func (*Deleter[T]) ScanWith

func (d *Deleter[T]) ScanWith(scanner func(*sql.Rows) (*T, error), ctxs ...context.Context) ([]*T, error)

func (*Deleter[T]) ToSql

func (d *Deleter[T]) ToSql() (string, []any, error)

func (*Deleter[T]) Where

func (d *Deleter[T]) Where(expr ...Expression) *Deleter[T]

type Dialect

type Dialect interface {
	Placeholder(index int) string
}

type EnumColumn

type EnumColumn[T ~string] struct {
	// contains filtered or unexported fields
}

func DefineEnumColumn

func DefineEnumColumn[V ~string, T any](t Table[T], name string) EnumColumn[V]

DefineEnumColumn creates a typed enum column. Due to Go generics limitation, this is a standalone function, not a method. Usage: dew.DefineEnumColumn[Status](t, "status")

func (EnumColumn[T]) Alias

func (c EnumColumn[T]) Alias() *string

func (EnumColumn[T]) Args

func (c EnumColumn[T]) Args() []any

func (EnumColumn[T]) As

func (c EnumColumn[T]) As(alias string) EnumColumn[T]

func (EnumColumn[T]) ColumnName

func (c EnumColumn[T]) ColumnName() string

func (EnumColumn[T]) Eq

func (c EnumColumn[T]) Eq(val T) Expression

func (EnumColumn[T]) In

func (c EnumColumn[T]) In(vals ...T) Expression

func (EnumColumn[T]) IsNotNull

func (c EnumColumn[T]) IsNotNull() Expression

func (EnumColumn[T]) IsNull

func (c EnumColumn[T]) IsNull() Expression

func (EnumColumn[T]) NotEq

func (c EnumColumn[T]) NotEq(val T) Expression

func (EnumColumn[T]) NotIn

func (c EnumColumn[T]) NotIn(vals ...T) Expression

func (EnumColumn[T]) Sql

func (c EnumColumn[T]) Sql() string

func (EnumColumn[T]) TableName

func (c EnumColumn[T]) TableName() string

type ErrorMapper

type ErrorMapper func(err error) error

ErrorMapper transforms a database driver error into a dew sentinel error. Return the original error unchanged if no mapping applies.

type Expression

type Expression interface {
	Sql() string
	Args() []any
}

func And

func And(exprs ...Expression) Expression

func Asc

func Asc(col any) Expression

func Desc

func Desc(col any) Expression

func Or

func Or(exprs ...Expression) Expression

func Raw

func Raw(sql string, args ...any) Expression

type Float32Column

type Float32Column struct {
	// contains filtered or unexported fields
}

func (Float32Column) Alias

func (c Float32Column) Alias() *string

func (Float32Column) Args

func (c Float32Column) Args() []any

func (Float32Column) As

func (c Float32Column) As(alias string) Float32Column

func (Float32Column) Between

func (c Float32Column) Between(min, max float32) Expression

func (Float32Column) ColumnName

func (c Float32Column) ColumnName() string

func (Float32Column) Eq

func (c Float32Column) Eq(val float32) Expression

func (Float32Column) EqSub

func (c Float32Column) EqSub(subQuery Expression) Expression

func (Float32Column) Gt

func (c Float32Column) Gt(val float32) Expression

func (Float32Column) Gte

func (c Float32Column) Gte(val float32) Expression

func (Float32Column) In

func (c Float32Column) In(vals ...float32) Expression

func (Float32Column) InSub

func (c Float32Column) InSub(subQuery Expression) Expression

func (Float32Column) IsNotNull

func (c Float32Column) IsNotNull() Expression

func (Float32Column) IsNull

func (c Float32Column) IsNull() Expression

func (Float32Column) Lt

func (c Float32Column) Lt(val float32) Expression

func (Float32Column) Lte

func (c Float32Column) Lte(val float32) Expression

func (Float32Column) NotEq

func (c Float32Column) NotEq(val float32) Expression

func (Float32Column) NotEqSub

func (c Float32Column) NotEqSub(subQuery Expression) Expression

func (Float32Column) NotIn

func (c Float32Column) NotIn(vals ...float32) Expression

func (Float32Column) NotInSub

func (c Float32Column) NotInSub(subQuery Expression) Expression

func (Float32Column) Sql

func (c Float32Column) Sql() string

func (Float32Column) TableName

func (c Float32Column) TableName() string

type FloatColumn

type FloatColumn struct {
	// contains filtered or unexported fields
}

func (FloatColumn) Alias

func (c FloatColumn) Alias() *string

func (FloatColumn) Args

func (c FloatColumn) Args() []any

func (FloatColumn) As

func (c FloatColumn) As(alias string) FloatColumn

func (FloatColumn) Between

func (c FloatColumn) Between(min, max float64) Expression

func (FloatColumn) ColumnName

func (c FloatColumn) ColumnName() string

func (FloatColumn) Eq

func (c FloatColumn) Eq(val float64) Expression

func (FloatColumn) EqSub

func (c FloatColumn) EqSub(subQuery Expression) Expression

func (FloatColumn) Gt

func (c FloatColumn) Gt(val float64) Expression

func (FloatColumn) Gte

func (c FloatColumn) Gte(val float64) Expression

func (FloatColumn) In

func (c FloatColumn) In(vals ...float64) Expression

func (FloatColumn) InSub

func (c FloatColumn) InSub(subQuery Expression) Expression

func (FloatColumn) IsNotNull

func (c FloatColumn) IsNotNull() Expression

func (FloatColumn) IsNull

func (c FloatColumn) IsNull() Expression

func (FloatColumn) Lt

func (c FloatColumn) Lt(val float64) Expression

func (FloatColumn) Lte

func (c FloatColumn) Lte(val float64) Expression

func (FloatColumn) NotEq

func (c FloatColumn) NotEq(val float64) Expression

func (FloatColumn) NotEqSub

func (c FloatColumn) NotEqSub(subQuery Expression) Expression

func (FloatColumn) NotIn

func (c FloatColumn) NotIn(vals ...float64) Expression

func (FloatColumn) NotInSub

func (c FloatColumn) NotInSub(subQuery Expression) Expression

func (FloatColumn) Sql

func (c FloatColumn) Sql() string

func (FloatColumn) TableName

func (c FloatColumn) TableName() string

type Inserter

type Inserter[T any] struct {
	// contains filtered or unexported fields
}

func Insert

func Insert[T any](db Querier, table Tabler) *Inserter[T]

func (*Inserter[T]) Batch

func (i *Inserter[T]) Batch(size int) *Inserter[T]

func (*Inserter[T]) BatchQueries

func (i *Inserter[T]) BatchQueries() ([]string, [][]any, error)

BatchQueries returns the SQL and args for each batch chunk. If Batch() was not called, returns a single-element slice.

func (*Inserter[T]) Columns

func (i *Inserter[T]) Columns(cols ...Column) *Inserter[T]

func (*Inserter[T]) Exec

func (i *Inserter[T]) Exec(ctxs ...context.Context) error

func (*Inserter[T]) Models

func (i *Inserter[T]) Models(models ...*T) *Inserter[T]

func (*Inserter[T]) OnConflict

func (i *Inserter[T]) OnConflict(cols ...Column) *ConflictInserter[T]

func (*Inserter[T]) Returning

func (i *Inserter[T]) Returning(cols ...Column) *Inserter[T]

func (*Inserter[T]) ScanWith

func (i *Inserter[T]) ScanWith(scanner func(*sql.Rows) (*T, error), ctxs ...context.Context) ([]*T, error)

func (*Inserter[T]) ToSql

func (i *Inserter[T]) ToSql() (string, []any, error)

func (*Inserter[T]) Values

func (i *Inserter[T]) Values(vals ...any) *Inserter[T]

type Int64Column

type Int64Column struct {
	// contains filtered or unexported fields
}

func (Int64Column) Alias

func (c Int64Column) Alias() *string

func (Int64Column) Args

func (c Int64Column) Args() []any

func (Int64Column) As

func (c Int64Column) As(alias string) Int64Column

func (Int64Column) Between

func (c Int64Column) Between(min, max int64) Expression

func (Int64Column) ColumnName

func (c Int64Column) ColumnName() string

func (Int64Column) Eq

func (c Int64Column) Eq(val int64) Expression

func (Int64Column) EqSub

func (c Int64Column) EqSub(subQuery Expression) Expression

func (Int64Column) Gt

func (c Int64Column) Gt(val int64) Expression

func (Int64Column) Gte

func (c Int64Column) Gte(val int64) Expression

func (Int64Column) In

func (c Int64Column) In(vals ...int64) Expression

func (Int64Column) InSub

func (c Int64Column) InSub(subQuery Expression) Expression

func (Int64Column) IsNotNull

func (c Int64Column) IsNotNull() Expression

func (Int64Column) IsNull

func (c Int64Column) IsNull() Expression

func (Int64Column) Lt

func (c Int64Column) Lt(val int64) Expression

func (Int64Column) Lte

func (c Int64Column) Lte(val int64) Expression

func (Int64Column) NotEq

func (c Int64Column) NotEq(val int64) Expression

func (Int64Column) NotEqSub

func (c Int64Column) NotEqSub(subQuery Expression) Expression

func (Int64Column) NotIn

func (c Int64Column) NotIn(vals ...int64) Expression

func (Int64Column) NotInSub

func (c Int64Column) NotInSub(subQuery Expression) Expression

func (Int64Column) Sql

func (c Int64Column) Sql() string

func (Int64Column) TableName

func (c Int64Column) TableName() string

type IntColumn

type IntColumn struct {
	// contains filtered or unexported fields
}

func (IntColumn) Alias

func (c IntColumn) Alias() *string

func (IntColumn) Args

func (c IntColumn) Args() []any

func (IntColumn) As

func (c IntColumn) As(alias string) IntColumn

func (IntColumn) Between

func (c IntColumn) Between(min, max int) Expression

func (IntColumn) ColumnName

func (c IntColumn) ColumnName() string

func (IntColumn) Eq

func (c IntColumn) Eq(val int) Expression

func (IntColumn) EqSub

func (c IntColumn) EqSub(subQuery Expression) Expression

func (IntColumn) Gt

func (c IntColumn) Gt(val int) Expression

func (IntColumn) Gte

func (c IntColumn) Gte(val int) Expression

func (IntColumn) In

func (c IntColumn) In(vals ...int) Expression

func (IntColumn) InSub

func (c IntColumn) InSub(subQuery Expression) Expression

func (IntColumn) IsNotNull

func (c IntColumn) IsNotNull() Expression

func (IntColumn) IsNull

func (c IntColumn) IsNull() Expression

func (IntColumn) Lt

func (c IntColumn) Lt(val int) Expression

func (IntColumn) Lte

func (c IntColumn) Lte(val int) Expression

func (IntColumn) NotEq

func (c IntColumn) NotEq(val int) Expression

func (IntColumn) NotEqSub

func (c IntColumn) NotEqSub(subQuery Expression) Expression

func (IntColumn) NotIn

func (c IntColumn) NotIn(vals ...int) Expression

func (IntColumn) NotInSub

func (c IntColumn) NotInSub(subQuery Expression) Expression

func (IntColumn) Sql

func (c IntColumn) Sql() string

func (IntColumn) TableName

func (c IntColumn) TableName() string

type JSONB

type JSONB interface {
	sql.Scanner
	driver.Valuer
}

JSONB is the constraint for JSONBColumn type parameters. Types used with JSONBColumn must implement both sql.Scanner (for reading) and driver.Valuer (for writing).

type JSONBColumn

type JSONBColumn[T JSONB] struct {
	// contains filtered or unexported fields
}

func DefineJSONBColumn

func DefineJSONBColumn[V JSONB, T any](t Table[T], name string) JSONBColumn[V]

JSONBColumn creates a typed JSONB column. Due to Go generics limitation, this is a standalone function, not a method. Usage: dew.JSONBColumn[MyType](t, "column_name")

func (JSONBColumn[T]) Alias

func (c JSONBColumn[T]) Alias() *string

func (JSONBColumn[T]) Args

func (c JSONBColumn[T]) Args() []any

func (JSONBColumn[T]) As

func (c JSONBColumn[T]) As(alias string) JSONBColumn[T]

func (JSONBColumn[T]) ColumnName

func (c JSONBColumn[T]) ColumnName() string

func (JSONBColumn[T]) ContainedBy

func (c JSONBColumn[T]) ContainedBy(val T) Expression

ContainedBy checks if JSONB is contained by the given value (<@ operator)

func (JSONBColumn[T]) Contains

func (c JSONBColumn[T]) Contains(val T) Expression

Contains checks if JSONB contains the given value (@> operator)

func (JSONBColumn[T]) Eq

func (c JSONBColumn[T]) Eq(val T) Expression

func (JSONBColumn[T]) HasAllKeys

func (c JSONBColumn[T]) HasAllKeys(keys ...string) Expression

HasAllKeys checks if JSONB has all of the given keys (?& operator)

func (JSONBColumn[T]) HasAnyKey

func (c JSONBColumn[T]) HasAnyKey(keys ...string) Expression

HasAnyKey checks if JSONB has any of the given keys (?| operator)

func (JSONBColumn[T]) HasKey

func (c JSONBColumn[T]) HasKey(key string) Expression

HasKey checks if JSONB has the given key (? operator)

func (JSONBColumn[T]) IsNotNull

func (c JSONBColumn[T]) IsNotNull() Expression

func (JSONBColumn[T]) IsNull

func (c JSONBColumn[T]) IsNull() Expression

func (JSONBColumn[T]) NotEq

func (c JSONBColumn[T]) NotEq(val T) Expression

func (JSONBColumn[T]) Path

func (c JSONBColumn[T]) Path(keys ...string) JSONBColumn[T]

Path returns a new JSONBColumn for nested path access (-> operator)

func (JSONBColumn[T]) PathText

func (c JSONBColumn[T]) PathText(keys ...string) Column

PathText returns a StringColumn for text extraction (->> operator)

func (JSONBColumn[T]) Sql

func (c JSONBColumn[T]) Sql() string

func (JSONBColumn[T]) TableName

func (c JSONBColumn[T]) TableName() string

type MSSQLDialect

type MSSQLDialect struct{}

func (MSSQLDialect) Placeholder

func (d MSSQLDialect) Placeholder(index int) string

type MySQLDialect

type MySQLDialect struct{}

func (MySQLDialect) Placeholder

func (d MySQLDialect) Placeholder(index int) string

type OPERATOR

type OPERATOR string
const (
	AND OPERATOR = " AND "
	OR  OPERATOR = " OR "
)

func (OPERATOR) String

func (o OPERATOR) String() string

type PostgreSQLDialect

type PostgreSQLDialect struct{}

func (PostgreSQLDialect) Placeholder

func (d PostgreSQLDialect) Placeholder(index int) string

type Querier

type Querier interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	// contains filtered or unexported methods
}

Querier is the common interface satisfied by both *DB and *Tx. It is unexported-method-sealed: only types in this package can implement it.

type RowScanner

type RowScanner interface {
	ScanRow(rows *sql.Rows) error
}

RowScanner allows a struct to define its own scanning logic instead of relying on reflection. Implement this interface on *T to use custom scanning.

func (u *User) ScanRow(rows *sql.Rows) error {
    return rows.Scan(&u.ID, &u.Name, &u.Email)
}

type SQLiteDialect

type SQLiteDialect struct{}

func (SQLiteDialect) Placeholder

func (d SQLiteDialect) Placeholder(index int) string

type Selector

type Selector[T any] struct {
	// contains filtered or unexported fields
}

func From

func From[T any](db Querier, schema Tabler) *Selector[T]

func FromSub

func FromSub[T any](db Querier, subQuery Expression, alias string) *Selector[T]

func (*Selector[T]) All

func (s *Selector[T]) All(ctxs ...context.Context) ([]*T, error)

func (*Selector[T]) Args

func (s *Selector[T]) Args() []any

func (*Selector[T]) Clone

func (s *Selector[T]) Clone() *Selector[T]

func (*Selector[T]) Count

func (s *Selector[T]) Count(ctxs ...context.Context) (int64, error)

func (*Selector[T]) Distinct

func (s *Selector[T]) Distinct(columns ...Column) *Selector[T]

func (*Selector[T]) Exists

func (s *Selector[T]) Exists(ctxs ...context.Context) (bool, error)

func (*Selector[T]) First

func (s *Selector[T]) First() (*T, error)

func (*Selector[T]) ForShare

func (s *Selector[T]) ForShare() *Selector[T]

func (*Selector[T]) ForUpdate

func (s *Selector[T]) ForUpdate() *Selector[T]

func (*Selector[T]) GroupBy

func (s *Selector[T]) GroupBy(columns ...Expression) *Selector[T]

func (*Selector[T]) Having

func (s *Selector[T]) Having(columns ...Expression) *Selector[T]

func (*Selector[T]) InnerJoin

func (s *Selector[T]) InnerJoin(schema Tabler, onLeft Column, onRight Column) *Selector[T]

func (*Selector[T]) LeftJoin

func (s *Selector[T]) LeftJoin(schema Tabler, onLeft Column, onRight Column) *Selector[T]

func (*Selector[T]) Limit

func (s *Selector[T]) Limit(count int) *Selector[T]

func (*Selector[T]) NoWait

func (s *Selector[T]) NoWait() *Selector[T]

func (*Selector[T]) Offset

func (s *Selector[T]) Offset(count int) *Selector[T]

func (*Selector[T]) One

func (s *Selector[T]) One(ctxs ...context.Context) (*T, error)

* SELECT EXECUTION * //

func (*Selector[T]) OrderBy

func (s *Selector[T]) OrderBy(expr ...Expression) *Selector[T]

func (*Selector[T]) RightJoin

func (s *Selector[T]) RightJoin(schema Tabler, onLeft Column, onRight Column) *Selector[T]

func (*Selector[T]) Scan

func (s *Selector[T]) Scan(dest ...any) error

func (*Selector[T]) ScanCtx

func (s *Selector[T]) ScanCtx(ctx context.Context, dest ...any) error

func (*Selector[T]) ScanWith

func (s *Selector[T]) ScanWith(scanner func(*sql.Rows) (*T, error), ctxs ...context.Context) ([]*T, error)

func (*Selector[T]) Select

func (s *Selector[T]) Select(columns ...Column) *Selector[T]

func (*Selector[T]) SkipLocked

func (s *Selector[T]) SkipLocked() *Selector[T]

func (*Selector[T]) Sql

func (s *Selector[T]) Sql() string

func (*Selector[T]) ToSql

func (s *Selector[T]) ToSql() (string, []any, error)

func (*Selector[T]) Where

func (s *Selector[T]) Where(expr ...Expression) *Selector[T]

func (*Selector[T]) With

func (s *Selector[T]) With(ctes ...cteClause) *Selector[T]

type SetQuery

type SetQuery[T any] struct {
	// contains filtered or unexported fields
}

func Except

func Except[T any](db Querier, left, right Expression) *SetQuery[T]

func Intersect

func Intersect[T any](db Querier, left, right Expression) *SetQuery[T]

func Union

func Union[T any](db Querier, left, right Expression) *SetQuery[T]

func UnionAll

func UnionAll[T any](db Querier, left, right Expression) *SetQuery[T]

func (*SetQuery[T]) All

func (sq *SetQuery[T]) All(ctxs ...context.Context) ([]*T, error)

func (*SetQuery[T]) Args

func (sq *SetQuery[T]) Args() []any

func (*SetQuery[T]) Except

func (sq *SetQuery[T]) Except(query Expression) *SetQuery[T]

func (*SetQuery[T]) Intersect

func (sq *SetQuery[T]) Intersect(query Expression) *SetQuery[T]

func (*SetQuery[T]) Limit

func (sq *SetQuery[T]) Limit(count int) *SetQuery[T]

func (*SetQuery[T]) Offset

func (sq *SetQuery[T]) Offset(count int) *SetQuery[T]

func (*SetQuery[T]) OrderBy

func (sq *SetQuery[T]) OrderBy(exprs ...Expression) *SetQuery[T]

func (*SetQuery[T]) Sql

func (sq *SetQuery[T]) Sql() string

func (*SetQuery[T]) ToSql

func (sq *SetQuery[T]) ToSql() (string, []any, error)

func (*SetQuery[T]) Union

func (sq *SetQuery[T]) Union(query Expression) *SetQuery[T]

func (*SetQuery[T]) UnionAll

func (sq *SetQuery[T]) UnionAll(query Expression) *SetQuery[T]

type StringColumn

type StringColumn struct {
	// contains filtered or unexported fields
}

func (StringColumn) Alias

func (c StringColumn) Alias() *string

func (StringColumn) Args

func (c StringColumn) Args() []any

func (StringColumn) As

func (c StringColumn) As(alias string) StringColumn

func (StringColumn) ColumnName

func (c StringColumn) ColumnName() string

func (StringColumn) Eq

func (c StringColumn) Eq(val string) Expression

func (StringColumn) EqSub

func (c StringColumn) EqSub(subQuery Expression) Expression

func (StringColumn) In

func (c StringColumn) In(vals ...string) Expression

func (StringColumn) InSub

func (c StringColumn) InSub(subQuery Expression) Expression

func (StringColumn) IsNotNull

func (c StringColumn) IsNotNull() Expression

func (StringColumn) IsNull

func (c StringColumn) IsNull() Expression

func (StringColumn) Like

func (c StringColumn) Like(val string) Expression

func (StringColumn) NotEq

func (c StringColumn) NotEq(val string) Expression

func (StringColumn) NotEqSub

func (c StringColumn) NotEqSub(subQuery Expression) Expression

func (StringColumn) NotIn

func (c StringColumn) NotIn(vals ...string) Expression

func (StringColumn) NotInSub

func (c StringColumn) NotInSub(subQuery Expression) Expression

func (StringColumn) NotLike

func (c StringColumn) NotLike(val string) Expression

func (StringColumn) Sql

func (c StringColumn) Sql() string

func (StringColumn) TableName

func (c StringColumn) TableName() string

type Table

type Table[T any] struct {
	// contains filtered or unexported fields
}

func NewTable

func NewTable[T any](name string, dialect Dialect) Table[T]

func (Table[T]) AnyColumn

func (t Table[T]) AnyColumn(name string) AnyColumn

func (Table[T]) BoolColumn

func (t Table[T]) BoolColumn(name string) BoolColumn

func (Table[T]) BytesColumn

func (t Table[T]) BytesColumn(name string) BytesColumn

func (Table[T]) DecimalColumn

func (t Table[T]) DecimalColumn(name string) DecimalColumn

func (Table[T]) Delete

func (t Table[T]) Delete(db Querier) *Deleter[T]

func (Table[T]) Float32Column

func (t Table[T]) Float32Column(name string) Float32Column

func (Table[T]) FloatColumn

func (t Table[T]) FloatColumn(name string) FloatColumn

func (Table[T]) From

func (t Table[T]) From(db Querier) *Selector[T]

func (Table[T]) Insert

func (t Table[T]) Insert(db Querier) *Inserter[T]

func (Table[T]) Int64Column

func (t Table[T]) Int64Column(name string) Int64Column

func (Table[T]) IntColumn

func (t Table[T]) IntColumn(name string) IntColumn

func (Table[T]) StringColumn

func (t Table[T]) StringColumn(name string) StringColumn

func (Table[T]) TableName

func (t Table[T]) TableName() string

func (Table[T]) TimeColumn

func (t Table[T]) TimeColumn(name string) TimeColumn

func (Table[T]) UUIDColumn

func (t Table[T]) UUIDColumn(name string) UUIDColumn

func (Table[T]) Update

func (t Table[T]) Update(db Querier) *Updater[T]

type Tabler

type Tabler interface {
	TableName() string
}

func TableRef

func TableRef(name string) Tabler

TableRef creates a Tabler reference for use with CTEs or other named sources.

type TimeColumn

type TimeColumn struct {
	// contains filtered or unexported fields
}

func (TimeColumn) Alias

func (c TimeColumn) Alias() *string

func (TimeColumn) Args

func (c TimeColumn) Args() []any

func (TimeColumn) As

func (c TimeColumn) As(alias string) TimeColumn

func (TimeColumn) Between

func (c TimeColumn) Between(min, max time.Time) Expression

func (TimeColumn) ColumnName

func (c TimeColumn) ColumnName() string

func (TimeColumn) Eq

func (c TimeColumn) Eq(val time.Time) Expression

func (TimeColumn) EqSub

func (c TimeColumn) EqSub(subQuery Expression) Expression

func (TimeColumn) Gt

func (c TimeColumn) Gt(val time.Time) Expression

func (TimeColumn) Gte

func (c TimeColumn) Gte(val time.Time) Expression

func (TimeColumn) In

func (c TimeColumn) In(vals ...time.Time) Expression

func (TimeColumn) InSub

func (c TimeColumn) InSub(subQuery Expression) Expression

func (TimeColumn) IsNotNull

func (c TimeColumn) IsNotNull() Expression

func (TimeColumn) IsNull

func (c TimeColumn) IsNull() Expression

func (TimeColumn) Lt

func (c TimeColumn) Lt(val time.Time) Expression

func (TimeColumn) Lte

func (c TimeColumn) Lte(val time.Time) Expression

func (TimeColumn) NotEq

func (c TimeColumn) NotEq(val time.Time) Expression

func (TimeColumn) NotEqSub

func (c TimeColumn) NotEqSub(subQuery Expression) Expression

func (TimeColumn) NotIn

func (c TimeColumn) NotIn(vals ...time.Time) Expression

func (TimeColumn) NotInSub

func (c TimeColumn) NotInSub(subQuery Expression) Expression

func (TimeColumn) Sql

func (c TimeColumn) Sql() string

func (TimeColumn) TableName

func (c TimeColumn) TableName() string

type Tx

type Tx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

Tx wraps *sql.Tx with dialect information, satisfying the Querier interface.

type UUIDColumn

type UUIDColumn struct {
	// contains filtered or unexported fields
}

func (UUIDColumn) Alias

func (c UUIDColumn) Alias() *string

func (UUIDColumn) Args

func (c UUIDColumn) Args() []any

func (UUIDColumn) As

func (c UUIDColumn) As(alias string) UUIDColumn

func (UUIDColumn) ColumnName

func (c UUIDColumn) ColumnName() string

func (UUIDColumn) Eq

func (c UUIDColumn) Eq(val string) Expression

func (UUIDColumn) EqSub

func (c UUIDColumn) EqSub(subQuery Expression) Expression

func (UUIDColumn) In

func (c UUIDColumn) In(vals ...string) Expression

func (UUIDColumn) InSub

func (c UUIDColumn) InSub(subQuery Expression) Expression

func (UUIDColumn) IsNotNull

func (c UUIDColumn) IsNotNull() Expression

func (UUIDColumn) IsNull

func (c UUIDColumn) IsNull() Expression

func (UUIDColumn) NotEq

func (c UUIDColumn) NotEq(val string) Expression

func (UUIDColumn) NotEqSub

func (c UUIDColumn) NotEqSub(subQuery Expression) Expression

func (UUIDColumn) NotIn

func (c UUIDColumn) NotIn(vals ...string) Expression

func (UUIDColumn) NotInSub

func (c UUIDColumn) NotInSub(subQuery Expression) Expression

func (UUIDColumn) Sql

func (c UUIDColumn) Sql() string

func (UUIDColumn) TableName

func (c UUIDColumn) TableName() string

type Updater

type Updater[T any] struct {
	// contains filtered or unexported fields
}

func Update

func Update[T any](db Querier, table Tabler) *Updater[T]

func (*Updater[T]) Clone

func (u *Updater[T]) Clone() *Updater[T]

func (*Updater[T]) Exec

func (u *Updater[T]) Exec(ctxs ...context.Context) error

func (*Updater[T]) Returning

func (u *Updater[T]) Returning(cols ...Column) *Updater[T]

func (*Updater[T]) RowsAffected

func (u *Updater[T]) RowsAffected(ctxs ...context.Context) (int64, error)

func (*Updater[T]) Scan

func (u *Updater[T]) Scan(ctx context.Context, dest ...any) error

func (*Updater[T]) ScanWith

func (u *Updater[T]) ScanWith(scanner func(*sql.Rows) (*T, error), ctxs ...context.Context) ([]*T, error)

func (*Updater[T]) Set

func (u *Updater[T]) Set(col Column, val any) *Updater[T]

func (*Updater[T]) ToSql

func (u *Updater[T]) ToSql() (string, []any, error)

func (*Updater[T]) Where

func (u *Updater[T]) Where(expr ...Expression) *Updater[T]

Directories

Path Synopsis
cmd
dew-demo command

Jump to

Keyboard shortcuts

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