sq

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: MIT Imports: 22 Imported by: 18

README

GoDoc tests Go Report Card Coverage Status

code example of a select query using sq, to give viewers a quick idea of what the library is about

sq (Structured Query)

one-page documentation

sq is a type-safe data mapper and query builder for Go. Its concept is simple: you provide a callback function that maps a row to a struct, generics ensure that you get back a slice of structs at the end. Additionally, mentioning a column in the callback function automatically adds it to the SELECT clause so you don't even have to explicitly mention what columns you want to select: the act of mapping a column is the same as selecting it. This eliminates a source of errors where you have specify the columns twice (once in the query itself, once to the call to rows.Scan) and end up missing a column, getting the column order wrong or mistyping a column name.

Notable features:

  • Works across SQLite, Postgres, MySQL and SQL Server. [more info]
  • Each dialect has its own query builder, allowing you to use dialect-specific features. [more info]
  • Declarative schema migrations. [more info]
  • Supports arrays, enums, JSON and UUID. [more info]
  • Query logging. [more info]

Installation

This package only supports Go 1.19 and above.

$ go get github.com/bokwoon95/sq
$ go install -tags=fts5 github.com/bokwoon95/sqddl@latest

Features

SELECT example (Raw SQL)

db, err := sql.Open("postgres", "postgres://username:password@localhost:5432/sakila?sslmode=disable")

actors, err := sq.FetchAll(db, sq.
    Queryf("SELECT {*} FROM actor AS a WHERE a.actor_id IN ({})",
        []int{1, 2, 3, 4, 5},
    ).
    SetDialect(sq.DialectPostgres),
    func(row *sq.Row) Actor {
        return Actor{
            ActorID:     row.Int("a.actor_id"),
            FirstName:   row.String("a.first_name"),
            LastName:    row.String("a.last_name"),
            LastUpdate:  row.Time("a.last_update"),
        }
    },
)

SELECT example (Query Builder)

To use the query builder, you must first define your table structs.

type ACTOR struct {
    sq.TableStruct
    ACTOR_ID    sq.NumberField
    FIRST_NAME  sq.StringField
    LAST_NAME   sq.StringField
    LAST_UPDATE sq.TimeField
}

db, err := sql.Open("postgres", "postgres://username:password@localhost:5432/sakila?sslmode=disable")

a := sq.New[ACTOR]("a")
actors, err := sq.FetchAll(db, sq.
    From(a).
    Where(a.ACTOR_ID.In([]int{1, 2, 3, 4, 5})).
    SetDialect(sq.DialectPostgres),
    func(row *sq.Row) Actor {
        return Actor{
            ActorID:     row.IntField(a.ACTOR_ID),
            FirstName:   row.StringField(a.FIRST_NAME),
            LastName:    row.StringField(a.LAST_NAME),
            LastUpdate:  row.TimeField(a.LAST_UPDATE),
        }
    },
)

INSERT example (Raw SQL)

db, err := sql.Open("postgres", "postgres://username:password@localhost:5432/sakila?sslmode=disable")

_, err := sq.Exec(db, sq.
    Queryf("INSERT INTO actor (actor_id, first_name, last_name) VALUES {}", sq.RowValues{
        {18, "DAN", "TORN"},
        {56, "DAN", "HARRIS"},
        {166, "DAN", "STREEP"},
    }).
    SetDialect(sq.DialectPostgres),
)

INSERT example (Query Builder)

To use the query builder, you must first define your table structs.

type ACTOR struct {
    sq.TableStruct
    ACTOR_ID    sq.NumberField
    FIRST_NAME  sq.StringField
    LAST_NAME   sq.StringField
    LAST_UPDATE sq.TimeField
}

db, err := sql.Open("postgres", "postgres://username:password@localhost:5432/sakila?sslmode=disable")

a := sq.New[ACTOR]("a")
_, err := sq.Exec(db, sq.
    InsertInto(a).
    Columns(a.ACTOR_ID, a.FIRST_NAME, a.LAST_NAME).
    Values(18, "DAN", "TORN").
    Values(56, "DAN", "HARRIS").
    Values(166, "DAN", "STREEP").
    SetDialect(sq.DialectPostgres),
)

For a more detailed overview, look at the Quickstart.

Project Status

sq is done for my use case (hence it may seem inactive, but it's just complete). At this point I'm just waiting for people to ask questions or file feature requests under discussions.

Contributing

See START_HERE.md.

Documentation

Index

Constants

View Source
const (
	JoinInner = "JOIN"
	JoinLeft  = "LEFT JOIN"
	JoinRight = "RIGHT JOIN"
	JoinFull  = "FULL JOIN"
	JoinCross = "CROSS JOIN"
)

Join operators.

View Source
const (
	DialectSQLite    = "sqlite"
	DialectPostgres  = "postgres"
	DialectMySQL     = "mysql"
	DialectSQLServer = "sqlserver"
)

Dialects supported.

Variables

View Source
var (
	SQLite    sqliteQueryBuilder
	Postgres  postgresQueryBuilder
	MySQL     mysqlQueryBuilder
	SQLServer sqlserverQueryBuilder
)

Dialect-specific query builder variables.

View Source
var DefaultDialect atomic.Pointer[string]

Default dialect used by all queries (if no dialect is explicitly provided).

Functions

func ArrayValue

func ArrayValue(value any) driver.Valuer

ArrayValue takes in a []string, []int, []int64, []int32, []float64, []float32 or []bool and returns a driver.Valuer for that type. For Postgres, it serializes into a Postgres array. Otherwise, it serializes into a JSON array.

func EnumValue

func EnumValue(value Enumeration) driver.Valuer

EnumValue takes in an Enumeration and returns a driver.Valuer which serializes the enum into a string and additionally checks if the enum is valid.

func EscapeQuote

func EscapeQuote(str string, quote byte) string

EscapeQuote will escape the relevant quote in a string by doubling up on it (as per SQL rules).

func FetchAll

func FetchAll[T any](db DB, query Query, rowmapper func(*Row) T) ([]T, error)

FetchAll returns all results from running the given Query on the given DB.

func FetchAllContext

func FetchAllContext[T any](ctx context.Context, db DB, query Query, rowmapper func(*Row) T) ([]T, error)

FetchAllContext is like FetchAll but additionally requires a context.Context.

func FetchExists

func FetchExists(db DB, query Query) (exists bool, err error)

FetchExists returns a boolean indicating if running the given Query on the given DB returned any results.

func FetchExistsContext

func FetchExistsContext(ctx context.Context, db DB, query Query) (exists bool, err error)

FetchExistsContext is like FetchExists but additionally requires a context.Context.

func FetchOne

func FetchOne[T any](db DB, query Query, rowmapper func(*Row) T) (T, error)

FetchOne returns the first result from running the given Query on the given DB.

func FetchOneContext

func FetchOneContext[T any](ctx context.Context, db DB, query Query, rowmapper func(*Row) T) (T, error)

FetchOneContext is like FetchOne but additionally requires a context.Context.

func JSONValue

func JSONValue(value any) driver.Valuer

JSONValue takes in an interface{} and returns a driver.Valuer which runs the value through json.Marshal before submitting it to the database.

func Log

func Log(db DB) interface {
	DB
	SqLogger
}

Log wraps a DB and adds logging to it.

func New

func New[T Table](alias string) T

New instantiates a new table struct with the given alias. Passing in an empty string is equivalent to giving no alias to the table.

func QuoteIdentifier

func QuoteIdentifier(dialect string, identifier string) string

QuoteIdentifier quotes an identifier if necessary using dialect-specific quoting rules.

func SetDefaultLogQuery added in v0.4.0

func SetDefaultLogQuery(logQuery func(context.Context, QueryStats))

SetDefaultLogQuery sets the default logging function to call for all queries (if a logger is not explicitly passed in).

func SetDefaultLogSettings added in v0.4.0

func SetDefaultLogSettings(logSettings func(context.Context, *LogSettings))

SetDefaultLogSettings sets the function to configure the default LogSettings. This value is not used unless SetDefaultLogQuery is also configured.

func Sprint

func Sprint(dialect string, v any) (string, error)

Sprint is the equivalent of Sprintf but for converting a single value into its SQL representation.

func Sprintf

func Sprintf(dialect string, query string, args []any) (string, error)

Sprintf will interpolate SQL args into a query string containing prepared statement parameters. It returns an error if an argument cannot be properly represented in SQL. This function may be vulnerable to SQL injection and should be used for logging purposes only.

func ToSQL

func ToSQL(dialect string, w SQLWriter, params map[string][]int) (query string, args []any, err error)

ToSQL converts an SQLWriter into a query string and args slice.

The params map is used to hold the mappings between named parameters in the query to the corresponding index in the args slice and is used for rebinding args by their parameter name. If you don't need to track this, you can pass in a nil map.

func ToSQLContext

func ToSQLContext(ctx context.Context, dialect string, w SQLWriter, params map[string][]int) (query string, args []any, err error)

ToSQLContext is like ToSQL but additionally requires a context.Context.

func UUIDValue

func UUIDValue(value any) driver.Valuer

UUIDValue takes in a type whose underlying type must be a [16]byte and returns a driver.Valuer.

func VerboseLog

func VerboseLog(db DB) interface {
	DB
	SqLogger
}

VerboseLog wraps a DB and adds verbose logging to it.

func WriteValue

func WriteValue(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int, value any) error

WriteValue is the equivalent of Writef but for writing a single value into the Output.

func Writef

func Writef(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int, format string, values []any) error

Writef is a fmt.Sprintf-style function that will write a format string and values slice into an Output. The only recognized placeholder is '{}'. Placeholders can be anonymous (e.g. {}), ordinal (e.g. {1}, {2}, {3}) or named (e.g. {name}, {email}, {age}).

- Anonymous placeholders refer to successive values in the values slice. Anonymous placeholders are treated like a series of incrementing ordinal placeholders.

- Ordinal placeholders refer to a specific value in the values slice using 1-based indexing.

- Named placeholders refer to their corresponding sql.NamedArg value in the values slice. If there are multiple sql.NamedArg values with the same name, the last one wins.

If a value is an SQLWriter, its WriteSQL method will be called. Else if a value is a slice, it will undergo slice expansion (https://bokwoon.neocities.org/sq.html#value-expansion). Otherwise, the value is added to the query args slice.

Types

type Any

type Any interface {
	Array
	Binary
	Boolean
	Enum
	JSON
	Number
	String
	Time
	UUID
}

Any is a catch-all interface that covers every field type.

type AnyField

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

AnyField is a catch-all field type that satisfies the Any interface.

func NewAnyField

func NewAnyField(name string, tbl TableStruct) AnyField

NewAnyField returns a new AnyField.

func (AnyField) As

func (field AnyField) As(alias string) AnyField

As returns a new AnyField with the given alias.

func (AnyField) Asc

func (field AnyField) Asc() AnyField

Asc returns a new AnyField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (AnyField) Desc

func (field AnyField) Desc() AnyField

Desc returns a new AnyField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.

func (AnyField) Eq

func (field AnyField) Eq(value any) Predicate

Eq returns a 'field = value' Predicate.

func (AnyField) Expr

func (field AnyField) Expr(format string, values ...any) Expression

Expr returns an expression where the field is prepended to the front of the expression.

func (AnyField) Ge

func (field AnyField) Ge(value any) Predicate

Ge returns a 'field >= value' Predicate.

func (AnyField) GetAlias

func (field AnyField) GetAlias() string

GetAlias returns the alias of the AnyField.

func (AnyField) Gt

func (field AnyField) Gt(value any) Predicate

Gt returns a 'field > value' Predicate.

func (AnyField) In

func (field AnyField) In(value any) Predicate

In returns a 'field IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field IN (x, y, z)'.

func (AnyField) IsArray

func (field AnyField) IsArray()

IsArray implements the Array interface.

func (AnyField) IsBinary

func (field AnyField) IsBinary()

IsBinary implements the Binary interface.

func (AnyField) IsBoolean

func (field AnyField) IsBoolean()

IsBoolean implements the Boolean interface.

func (AnyField) IsEnum

func (field AnyField) IsEnum()

IsEnum implements the Enum interface.

func (AnyField) IsField

func (field AnyField) IsField()

IsField implements the Field interface.

func (AnyField) IsJSON

func (field AnyField) IsJSON()

IsJSON implements the JSONValue interface.

func (AnyField) IsNotNull

func (field AnyField) IsNotNull() Predicate

IsNotNull returns a 'field IS NOT NULL' Predicate.

func (AnyField) IsNull

func (field AnyField) IsNull() Predicate

IsNull returns a 'field IS NULL' Predicate.

func (AnyField) IsNumber

func (field AnyField) IsNumber()

IsNumber implements the Number interface.

func (AnyField) IsString

func (field AnyField) IsString()

IsString implements the String interface.

func (AnyField) IsTime

func (field AnyField) IsTime()

IsTime implements the Time interface.

func (AnyField) IsUUID

func (field AnyField) IsUUID()

IsUUIDType implements the UUID interface.

func (AnyField) Le

func (field AnyField) Le(value any) Predicate

Le returns a 'field <= value' Predicate.

func (AnyField) Lt

func (field AnyField) Lt(value any) Predicate

Lt returns a 'field < value' Predicate.

func (AnyField) Ne

func (field AnyField) Ne(value any) Predicate

Ne returns a 'field <> value' Predicate.

func (AnyField) NotIn added in v0.3.0

func (field AnyField) NotIn(value any) Predicate

In returns a 'field NOT IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field NOT IN (x, y, z)'.

func (AnyField) NullsFirst

func (field AnyField) NullsFirst() AnyField

NullsFirst returns a new NumberField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (AnyField) NullsLast

func (field AnyField) NullsLast() AnyField

NullsLast returns a new NumberField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

func (AnyField) Set

func (field AnyField) Set(value any) Assignment

Set returns an Assignment assigning the value to the field.

func (AnyField) Setf

func (field AnyField) Setf(format string, values ...any) Assignment

Setf returns an Assignment assigning an expression to the field.

func (AnyField) WithPrefix

func (field AnyField) WithPrefix(prefix string) Field

WithPrefix returns a new Field that with the given prefix.

func (AnyField) WriteSQL

func (field AnyField) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Array

type Array interface {
	Field
	IsArray()
}

Array is a Field of array type.

type ArrayField

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

ArrayField represents an SQL array field.

func NewArrayField

func NewArrayField(fieldName string, tableName TableStruct) ArrayField

NewArrayField returns a new ArrayField.

func (ArrayField) As

func (field ArrayField) As(alias string) ArrayField

As returns a new ArrayField with the given alias.

func (ArrayField) GetAlias

func (field ArrayField) GetAlias() string

GetAlias returns the alias of the ArrayField.

func (ArrayField) IsArray

func (field ArrayField) IsArray()

IsArray implements the Array interface.

func (ArrayField) IsField

func (field ArrayField) IsField()

IsField implements the Field interface.

func (ArrayField) IsNotNull

func (field ArrayField) IsNotNull() Predicate

IsNull returns a 'field IS NOT NULL' Predicate.

func (ArrayField) IsNull

func (field ArrayField) IsNull() Predicate

IsNull returns a 'field IS NULL' Predicate.

func (ArrayField) Set

func (field ArrayField) Set(value any) Assignment

Set returns an Assignment assigning the value to the field.

func (ArrayField) SetArray

func (field ArrayField) SetArray(value any) Assignment

SetArray returns an Assignment assigning the value to the field. It wraps the value with ArrayValue().

func (ArrayField) Setf

func (field ArrayField) Setf(format string, values ...any) Assignment

Setf returns an Assignment assigning an expression to the field.

func (ArrayField) WithPrefix

func (field ArrayField) WithPrefix(prefix string) Field

WithPrefix returns a new Field that with the given prefix.

func (ArrayField) WriteSQL

func (field ArrayField) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type ArrayParameter added in v0.3.5

type ArrayParameter sql.NamedArg

ArrayParameter is identical to sql.NamedArg, but implements the Array interface.

func ArrayParam added in v0.3.5

func ArrayParam(name string, value any) ArrayParameter

ArrayParam creates a new ArrayParameter. It wraps the value with ArrayValue().

func (ArrayParameter) IsArray added in v0.3.5

func (p ArrayParameter) IsArray()

IsArray implements the Array interface.

func (ArrayParameter) IsField added in v0.3.5

func (p ArrayParameter) IsField()

IsField implements the Field interface.

func (ArrayParameter) WriteSQL added in v0.3.5

func (p ArrayParameter) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Assignment

type Assignment interface {
	SQLWriter
	IsAssignment()
}

Assignment is an SQL assignment 'field = value'.

func Set

func Set(field Field, value any) Assignment

Set creates a new Assignment assigning the value to a field.

func Setf

func Setf(field Field, format string, values ...any) Assignment

Setf creates a new Assignment assigning a custom expression to a Field.

type Assignments

type Assignments []Assignment

Assignments represents a list of Assignments e.g. x = 1, y = 2, z = 3.

func (Assignments) WriteSQL

func (as Assignments) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Binary

type Binary interface {
	Field
	IsBinary()
}

Binary is a Field of binary type.

type BinaryField

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

BinaryField represents an SQL binary field.

func NewBinaryField

func NewBinaryField(fieldName string, tableName TableStruct) BinaryField

NewBinaryField returns a new BinaryField.

func (BinaryField) As

func (field BinaryField) As(alias string) BinaryField

As returns a new BinaryField with the given alias.

func (BinaryField) Asc

func (field BinaryField) Asc() BinaryField

Asc returns a new BinaryField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (BinaryField) Desc

func (field BinaryField) Desc() BinaryField

Desc returns a new BinaryField indicating that it should be ordered in ascending order i.e. 'ORDER BY field DESC'.

func (BinaryField) Eq

func (field BinaryField) Eq(value Binary) Predicate

Eq returns a 'field = value' Predicate.

func (BinaryField) EqBytes

func (field BinaryField) EqBytes(b []byte) Predicate

EqBytes returns a 'field = b' Predicate.

func (BinaryField) GetAlias

func (field BinaryField) GetAlias() string

GetAlias returns the alias of the BinaryField.

func (BinaryField) IsBinary

func (field BinaryField) IsBinary()

IsBinary implements the Binary interface.

func (BinaryField) IsField

func (field BinaryField) IsField()

IsField implements the Field interface.

func (BinaryField) IsNotNull

func (field BinaryField) IsNotNull() Predicate

IsNotNull returns a 'field IS NOT NULL' Predicate.

func (BinaryField) IsNull

func (field BinaryField) IsNull() Predicate

IsNull returns a 'field IS NULL' Predicate.

func (BinaryField) Ne

func (field BinaryField) Ne(value Binary) Predicate

Ne returns a 'field <> value' Predicate.

func (BinaryField) NeBytes

func (field BinaryField) NeBytes(b []byte) Predicate

NeBytes returns a 'field <> b' Predicate.

func (BinaryField) NullsFirst

func (field BinaryField) NullsFirst() BinaryField

NullsFirst returns a new BinaryField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (BinaryField) NullsLast

func (field BinaryField) NullsLast() BinaryField

NullsLast returns a new BinaryField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

func (BinaryField) Set

func (field BinaryField) Set(value any) Assignment

Set returns an Assignment assigning the value to the field.

func (BinaryField) SetBytes

func (field BinaryField) SetBytes(b []byte) Assignment

SetBytes returns an Assignment assigning a []byte to the field.

func (BinaryField) Setf

func (field BinaryField) Setf(format string, values ...any) Assignment

Setf returns an Assignment assigning an expression to the field.

func (BinaryField) WithPrefix

func (field BinaryField) WithPrefix(prefix string) Field

WithPrefix returns a new Field that with the given prefix.

func (BinaryField) WriteSQL

func (field BinaryField) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type BinaryParameter

type BinaryParameter sql.NamedArg

BinaryParameter is identical to sql.NamedArg, but implements the Binary interface.

func BytesParam

func BytesParam(name string, b []byte) BinaryParameter

BytesParam creates a new BinaryParameter using a []byte value.

func (BinaryParameter) IsBinary

func (p BinaryParameter) IsBinary()

IsBinary implements the Binary interface.

func (BinaryParameter) IsField

func (p BinaryParameter) IsField()

IsField implements the Field interface.

func (BinaryParameter) WriteSQL

func (p BinaryParameter) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Boolean

type Boolean interface {
	Field
	IsBoolean()
}

Boolean is a Field of boolean type.

type BooleanField

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

BooleanField represents an SQL boolean field.

func NewBooleanField

func NewBooleanField(fieldName string, tableName TableStruct) BooleanField

NewBooleanField returns a new BooleanField.

func (BooleanField) As

func (field BooleanField) As(alias string) BooleanField

As returns a new BooleanField with the given alias.

func (BooleanField) Asc

func (field BooleanField) Asc() BooleanField

Asc returns a new BooleanField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (BooleanField) Desc

func (f BooleanField) Desc() BooleanField

Desc returns a new BooleanField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.

func (BooleanField) Eq

func (field BooleanField) Eq(value Boolean) Predicate

Eq returns a 'field = value' Predicate.

func (BooleanField) EqBool

func (field BooleanField) EqBool(b bool) Predicate

EqBool returns a 'field = b' Predicate.

func (BooleanField) GetAlias

func (field BooleanField) GetAlias() string

GetAlias returns the alias of the BooleanField.

func (BooleanField) IsBoolean

func (field BooleanField) IsBoolean()

IsBoolean implements the Boolean interface.

func (BooleanField) IsField

func (field BooleanField) IsField()

IsField implements the Field interface.

func (BooleanField) IsNotNull

func (field BooleanField) IsNotNull() Predicate

IsNotNull returns a 'field IS NOT NULL' Predicate.

func (BooleanField) IsNull

func (field BooleanField) IsNull() Predicate

IsNull returns a 'field IS NULL' Predicate.

func (BooleanField) Ne

func (field BooleanField) Ne(value Boolean) Predicate

Ne returns a 'field <> value' Predicate.

func (BooleanField) NeBool

func (field BooleanField) NeBool(b bool) Predicate

NeBool returns a 'field <> b' Predicate.

func (BooleanField) NullsFirst

func (field BooleanField) NullsFirst() BooleanField

NullsFirst returns a new BooleanField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (BooleanField) NullsLast

func (field BooleanField) NullsLast() BooleanField

NullsLast returns a new BooleanField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

func (BooleanField) Set

func (field BooleanField) Set(value any) Assignment

Set returns an Assignment assigning the value to the field.

func (BooleanField) SetBool

func (field BooleanField) SetBool(b bool) Assignment

SetBool returns an Assignment assigning a bool to the field i.e. 'field = b'.

func (BooleanField) Setf

func (field BooleanField) Setf(format string, values ...any) Assignment

Setf returns an Assignment assigning an expression to the field.

func (BooleanField) WithPrefix

func (field BooleanField) WithPrefix(prefix string) Field

WithPrefix returns a new Field that with the given prefix.

func (BooleanField) WriteSQL

func (field BooleanField) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type BooleanParameter

type BooleanParameter sql.NamedArg

BooleanParameter is identical to sql.NamedArg, but implements the Boolean interface.

func BoolParam

func BoolParam(name string, b bool) BooleanParameter

BoolParam creates a new BooleanParameter from a bool value.

func (BooleanParameter) IsBoolean

func (p BooleanParameter) IsBoolean()

IsBoolean implements the Boolean interface.

func (BooleanParameter) IsField

func (p BooleanParameter) IsField()

IsField implements the Field interface.

func (BooleanParameter) WriteSQL

func (p BooleanParameter) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type CTE

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

CTE represents an SQL common table expression (CTE).

func NewCTE

func NewCTE(name string, columns []string, query Query) CTE

NewCTE creates a new CTE.

func NewRecursiveCTE

func NewRecursiveCTE(name string, columns []string, query Query) CTE

NewRecursiveCTE creates a new recursive CTE.

func (CTE) As

func (cte CTE) As(alias string) CTE

As returns a new CTE with the given alias.

func (CTE) Field

func (cte CTE) Field(name string) AnyField

Field returns a Field from the CTE.

func (CTE) GetAlias

func (cte CTE) GetAlias() string

GetAlias returns the alias of the CTE.

func (CTE) IsTable

func (cte CTE) IsTable()

AssertTable implements the Table interface.

func (CTE) Materialized

func (cte CTE) Materialized() CTE

Materialized returns a new CTE marked as MATERIALIZED. This only works on postgres.

func (CTE) NotMaterialized

func (cte CTE) NotMaterialized() CTE

Materialized returns a new CTE marked as NOT MATERIALIZED. This only works on postgres.

func (CTE) WriteSQL

func (cte CTE) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type CaseExpression

type CaseExpression struct {
	Cases   PredicateCases
	Default any
	// contains filtered or unexported fields
}

CaseExpression represents an SQL CASE expression.

func CaseWhen

func CaseWhen(predicate Predicate, result any) CaseExpression

CaseWhen returns a new CaseExpression.

func (CaseExpression) As

func (e CaseExpression) As(alias string) CaseExpression

As returns a new CaseExpression with the given alias.

func (CaseExpression) Else

func (e CaseExpression) Else(fallback any) CaseExpression

Else sets the fallback result of the CaseExpression.

func (CaseExpression) GetAlias

func (e CaseExpression) GetAlias() string

GetAlias returns the alias of the CaseExpression.

func (CaseExpression) IsArray

func (e CaseExpression) IsArray()

IsArray implements the Array interface.

func (CaseExpression) IsBinary

func (e CaseExpression) IsBinary()

IsBinary implements the Binary interface.

func (CaseExpression) IsBoolean

func (e CaseExpression) IsBoolean()

IsBoolean implements the Boolean interface.

func (CaseExpression) IsEnum

func (e CaseExpression) IsEnum()

IsEnum implements the Enum interface.

func (CaseExpression) IsField

func (e CaseExpression) IsField()

IsField implements the Field interface.

func (CaseExpression) IsJSON

func (e CaseExpression) IsJSON()

IsJSON implements the JSON interface.

func (CaseExpression) IsNumber

func (e CaseExpression) IsNumber()

IsNumber implements the Number interface.

func (CaseExpression) IsString

func (e CaseExpression) IsString()

IsString implements the String interface.

func (CaseExpression) IsTime

func (e CaseExpression) IsTime()

IsTime implements the Time interface.

func (CaseExpression) IsUUID

func (e CaseExpression) IsUUID()

IsUUID implements the UUID interface.

func (CaseExpression) When

func (e CaseExpression) When(predicate Predicate, result any) CaseExpression

When adds a new predicate-result pair to the CaseExpression.

func (CaseExpression) WriteSQL

func (e CaseExpression) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Column

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

Column keeps track of what the values mapped to what Field in an InsertQuery or SelectQuery.

func (*Column) Set

func (col *Column) Set(field Field, value any)

Set maps the value to the Field.

func (*Column) SetArray

func (col *Column) SetArray(field Array, value any)

SetArray maps the array value to the field. The value should be []string, []int, []int64, []int32, []float64, []float32 or []bool.

func (*Column) SetBool

func (col *Column) SetBool(field Boolean, value bool)

SetBool maps the bool value to the field.

func (*Column) SetBytes

func (col *Column) SetBytes(field Binary, value []byte)

SetBytes maps the []byte value to the field.

func (*Column) SetEnum

func (col *Column) SetEnum(field Enum, value Enumeration)

SetEnum maps the enum value to the field.

func (*Column) SetFloat64

func (col *Column) SetFloat64(field Number, value float64)

SetFloat64 maps the float64 value to the field.

func (*Column) SetInt

func (col *Column) SetInt(field Number, value int)

SetInt maps the int value to the field.

func (*Column) SetInt64

func (col *Column) SetInt64(field Number, value int64)

SetInt64 maps the int64 value to the field.

func (*Column) SetJSON

func (col *Column) SetJSON(field JSON, value any)

SetJSON maps the JSON value to the field. The value should be able to be convertible to JSON using json.Marshal.

func (*Column) SetString

func (col *Column) SetString(field String, value string)

SetString maps the string value to the field.

func (*Column) SetTime

func (col *Column) SetTime(field Time, value time.Time)

SetTime maps the time.Time value to the field.

func (*Column) SetUUID

func (col *Column) SetUUID(field UUID, value any)

SetUUID maps the UUID value to the field. The value's type or underlying type should be [16]byte.

type CompiledExec

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

CompiledExec is the result of compiling a Query down into a query string and args slice. A CompiledExec can be safely executed in parallel.

func CompileExec

func CompileExec(query Query) (*CompiledExec, error)

CompileExec returns a new CompiledExec.

func CompileExecContext

func CompileExecContext(ctx context.Context, query Query) (*CompiledExec, error)

CompileExecContext is like CompileExec but additionally requires a context.Context.

func NewCompiledExec

func NewCompiledExec(dialect string, query string, args []any, params map[string][]int) *CompiledExec

NewCompiledExec returns a new CompiledExec.

func (*CompiledExec) Exec

func (compiledExec *CompiledExec) Exec(db DB, params Params) (Result, error)

Exec executes the CompiledExec on the given DB with the given params.

func (*CompiledExec) ExecContext

func (compiledExec *CompiledExec) ExecContext(ctx context.Context, db DB, params Params) (Result, error)

ExecContext is like Exec but additionally requires a context.Context.

func (*CompiledExec) GetSQL

func (compiledExec *CompiledExec) GetSQL() (dialect string, query string, args []any, params map[string][]int)

GetSQL returns a copy of the dialect, query, args, params and rowmapper that make up the CompiledExec.

func (*CompiledExec) Prepare

func (compiledExec *CompiledExec) Prepare(db DB) (*PreparedExec, error)

Prepare creates a PreparedExec from a CompiledExec by preparing it on the given DB.

func (*CompiledExec) PrepareContext

func (compiledExec *CompiledExec) PrepareContext(ctx context.Context, db DB) (*PreparedExec, error)

PrepareContext is like Prepare but additionally requires a context.Context.

type CompiledFetch

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

CompiledFetch is the result of compiling a Query down into a query string and args slice. A CompiledFetch can be safely executed in parallel.

func CompileFetch

func CompileFetch[T any](q Query, rowmapper func(*Row) T) (*CompiledFetch[T], error)

CompileFetch returns a new CompileFetch.

func CompileFetchContext

func CompileFetchContext[T any](ctx context.Context, query Query, rowmapper func(*Row) T) (compiledFetch *CompiledFetch[T], err error)

CompileFetchContext is like CompileFetch but accepts a context.Context.

func NewCompiledFetch

func NewCompiledFetch[T any](dialect string, query string, args []any, params map[string][]int, rowmapper func(*Row) T) *CompiledFetch[T]

NewCompiledFetch returns a new CompiledFetch.

func (*CompiledFetch[T]) FetchAll

func (compiledFetch *CompiledFetch[T]) FetchAll(db DB, params Params) ([]T, error)

FetchAll returns all the results from running the CompiledFetch on the given DB with the give params.

func (*CompiledFetch[T]) FetchAllContext

func (compiledFetch *CompiledFetch[T]) FetchAllContext(ctx context.Context, db DB, params Params) ([]T, error)

FetchAllContext is like FetchAll but additionally requires a context.Context.

func (*CompiledFetch[T]) FetchCursor

func (compiledFetch *CompiledFetch[T]) FetchCursor(db DB, params Params) (*Cursor[T], error)

FetchCursor returns a new cursor.

func (*CompiledFetch[T]) FetchCursorContext

func (compiledFetch *CompiledFetch[T]) FetchCursorContext(ctx context.Context, db DB, params Params) (*Cursor[T], error)

FetchCursorContext is like FetchCursor but additionally requires a context.Context.

func (*CompiledFetch[T]) FetchOne

func (compiledFetch *CompiledFetch[T]) FetchOne(db DB, params Params) (T, error)

FetchOne returns the first result from running the CompiledFetch on the given DB with the give params.

func (*CompiledFetch[T]) FetchOneContext

func (compiledFetch *CompiledFetch[T]) FetchOneContext(ctx context.Context, db DB, params Params) (T, error)

FetchOneContext is like FetchOne but additionally requires a context.Context.

func (*CompiledFetch[T]) GetSQL

func (compiledFetch *CompiledFetch[T]) GetSQL() (dialect string, query string, args []any, params map[string][]int, rowmapper func(*Row) T)

GetSQL returns a copy of the dialect, query, args, params and rowmapper that make up the CompiledFetch.

func (*CompiledFetch[T]) Prepare

func (compiledFetch *CompiledFetch[T]) Prepare(db DB) (*PreparedFetch[T], error)

Prepare creates a PreparedFetch from a CompiledFetch by preparing it on the given DB.

func (*CompiledFetch[T]) PrepareContext

func (compiledFetch *CompiledFetch[T]) PrepareContext(ctx context.Context, db DB) (*PreparedFetch[T], error)

PrepareContext is like Prepare but additionally requires a context.Context.

type ConflictClause

type ConflictClause struct {
	ConstraintName      string
	Fields              []Field
	Predicate           Predicate
	DoNothing           bool
	Resolution          []Assignment
	ResolutionPredicate Predicate
}

ConflictClause represents an SQL conflict clause e.g. ON CONFLICT DO NOTHING/DO UPDATE or ON DUPLICATE KEY UPDATE.

func (ConflictClause) WriteSQL

func (c ConflictClause) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Cursor

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

A Cursor represents a database cursor.

func FetchCursor

func FetchCursor[T any](db DB, query Query, rowmapper func(*Row) T) (*Cursor[T], error)

FetchCursor returns a new cursor.

func FetchCursorContext

func FetchCursorContext[T any](ctx context.Context, db DB, query Query, rowmapper func(*Row) T) (*Cursor[T], error)

FetchCursorContext is like FetchCursor but additionally requires a context.Context.

func (*Cursor[T]) Close

func (cursor *Cursor[T]) Close() error

Close closes the cursor.

func (*Cursor[T]) Next

func (cursor *Cursor[T]) Next() bool

Next advances the cursor to the next result.

func (*Cursor[T]) Result

func (cursor *Cursor[T]) Result() (result T, err error)

Result returns the cursor result.

func (*Cursor[T]) RowCount

func (cursor *Cursor[T]) RowCount() int64

RowCount returns the current row number so far.

type CustomQuery

type CustomQuery struct {
	Dialect string
	Format  string
	Values  []any
	// contains filtered or unexported fields
}

CustomQuery represents a user-defined query.

func Queryf

func Queryf(format string, values ...any) CustomQuery

Queryf creates a new query using Writef syntax.

func (CustomQuery) Append added in v0.2.7

func (q CustomQuery) Append(format string, values ...any) CustomQuery

Append returns a new CustomQuery with the format string and values slice appended to the current CustomQuery.

func (CustomQuery) GetDialect

func (q CustomQuery) GetDialect() string

GetDialect gets the dialect of the query.

func (CustomQuery) GetFetchableFields

func (q CustomQuery) GetFetchableFields() []Field

GetFetchableFields gets the fetchable fields of the query.

func (CustomQuery) SetDialect

func (q CustomQuery) SetDialect(dialect string) CustomQuery

SetDialect sets the dialect of the query.

func (CustomQuery) SetFetchableFields

func (q CustomQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields sets the fetchable fields of the query.

func (CustomQuery) WriteSQL

func (q CustomQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type DB

type DB interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
}

DB is a database/sql abstraction that can query the database. *sql.Conn, *sql.DB and *sql.Tx all implement DB.

type DeleteQuery

type DeleteQuery struct {
	Dialect string
	// WITH
	CTEs []CTE
	// DELETE FROM
	DeleteTable  Table
	DeleteTables []Table
	// USING
	UsingTable Table
	JoinTables []JoinTable
	// WHERE
	WherePredicate Predicate
	// ORDER BY
	OrderByFields Fields
	// LIMIT
	LimitRows any
	// OFFSET
	OffsetRows any
	// RETURNING
	ReturningFields []Field
}

DeleteQuery represents an SQL DELETE query.

func DeleteFrom

func DeleteFrom(table Table) DeleteQuery

DeleteFrom returns a new DeleteQuery.

func (DeleteQuery) GetDialect

func (q DeleteQuery) GetDialect() string

GetDialect implements the Query interface.

func (DeleteQuery) GetFetchableFields

func (q DeleteQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (DeleteQuery) SetDialect

func (q DeleteQuery) SetDialect(dialect string) DeleteQuery

SetDialect sets the dialect of the query.

func (DeleteQuery) SetFetchableFields

func (q DeleteQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (DeleteQuery) Where

func (q DeleteQuery) Where(predicates ...Predicate) DeleteQuery

Where appends to the WherePredicate field of the DeleteQuery.

func (DeleteQuery) WriteSQL

func (q DeleteQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type DialectCase

type DialectCase struct {
	Dialect string
	Result  any
}

DialectCase holds the result to be used for a given dialect in a DialectExpression.

type DialectCases

type DialectCases = []DialectCase

DialectCases is a slice of DialectCases.

type DialectExpression

type DialectExpression struct {
	Default any
	Cases   DialectCases
}

DialectExpression represents an SQL expression that renders differently depending on the dialect.

func DialectExpr

func DialectExpr(format string, values ...any) DialectExpression

DialectExpr returns a new DialectExpression. The expression passed in is used as the default.

func DialectValue

func DialectValue(value any) DialectExpression

DialectValue returns a new DialectExpression. The value passed in is used as the default.

func (DialectExpression) DialectExpr

func (e DialectExpression) DialectExpr(dialect string, format string, values ...any) DialectExpression

DialectExpr adds a new dialect-expression pair to the DialectExpression.

func (DialectExpression) DialectValue

func (e DialectExpression) DialectValue(dialect string, value any) DialectExpression

DialectValue adds a new dialect-value pair to the DialectExpression.

func (DialectExpression) IsArray

func (e DialectExpression) IsArray()

IsArray implements the Array interface.

func (DialectExpression) IsBinary

func (e DialectExpression) IsBinary()

IsBinary implements the Binary interface.

func (DialectExpression) IsBoolean

func (e DialectExpression) IsBoolean()

IsBoolean implements the Boolean interface.

func (DialectExpression) IsEnum

func (e DialectExpression) IsEnum()

IsEnum implements the Enum interface.

func (DialectExpression) IsField

func (e DialectExpression) IsField()

IsField implements the Field interface.

func (DialectExpression) IsJSON

func (e DialectExpression) IsJSON()

IsJSON implements the JSON interface.

func (DialectExpression) IsNumber

func (e DialectExpression) IsNumber()

IsNumber implements the Number interface.

func (DialectExpression) IsString

func (e DialectExpression) IsString()

IsString implements the String interface.

func (DialectExpression) IsTable

func (e DialectExpression) IsTable()

IsTable implements the Table interface.

func (DialectExpression) IsTime

func (e DialectExpression) IsTime()

IsTime implements the Time interface.

func (DialectExpression) IsUUID

func (e DialectExpression) IsUUID()

IsUUID implements the UUID interface.

func (DialectExpression) WriteSQL

func (e DialectExpression) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type DialectValuer

type DialectValuer interface {
	DialectValuer(dialect string) (driver.Valuer, error)
}

DialectValuer is any type that will yield a different driver.Valuer depending on the SQL dialect.

type Enum

type Enum interface {
	Field
	IsEnum()
}

Enum is a Field of enum type.

type EnumField

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

EnumField represents an SQL enum field.

func NewEnumField

func NewEnumField(name string, tbl TableStruct) EnumField

NewEnumField returns a new EnumField.

func (EnumField) As

func (field EnumField) As(alias string) EnumField

As returns a new EnumField with the given alias.

func (EnumField) Eq

func (field EnumField) Eq(value any) Predicate

Eq returns a 'field = value' Predicate.

func (EnumField) EqEnum added in v0.2.1

func (field EnumField) EqEnum(value Enumeration) Predicate

EqEnum returns a 'field = value' Predicate. It wraps the value with EnumValue().

func (EnumField) GetAlias

func (field EnumField) GetAlias() string

GetAlias returns the alias of the EnumField.

func (EnumField) In added in v0.3.0

func (field EnumField) In(value any) Predicate

In returns a 'field IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field IN (x, y, z)'.

func (EnumField) IsEnum

func (field EnumField) IsEnum()

IsEnum implements the Enum interface.

func (EnumField) IsField

func (field EnumField) IsField()

IsField implements the Field interface.

func (EnumField) IsNotNull

func (field EnumField) IsNotNull() Predicate

IsNotNull returns a 'field IS NOT NULL' Predicate.

func (EnumField) IsNull

func (field EnumField) IsNull() Predicate

IsNull returns a 'field IS NULL' Predicate.

func (EnumField) Ne

func (field EnumField) Ne(value any) Predicate

Ne returns a 'field <> value' Predicate.

func (EnumField) NeEnum added in v0.2.1

func (field EnumField) NeEnum(value Enumeration) Predicate

NeEnum returns a 'field <> value' Predicate. it wraps the value with EnumValue().

func (EnumField) NotIn added in v0.3.0

func (field EnumField) NotIn(value any) Predicate

NotIn returns a 'field NOT IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field NOT IN (x, y, z)'.

func (EnumField) Set

func (field EnumField) Set(value any) Assignment

Set returns an Assignment assigning the value to the field.

func (EnumField) SetEnum

func (field EnumField) SetEnum(value Enumeration) Assignment

SetEnum returns an Assignment assigning the value to the field. It wraps the value with EnumValue().

func (EnumField) Setf

func (field EnumField) Setf(format string, values ...any) Assignment

Setf returns an Assignment assigning an expression to the field.

func (EnumField) WithPrefix

func (field EnumField) WithPrefix(prefix string) Field

WithPrefix returns a new Field that with the given prefix.

func (EnumField) WriteSQL

func (field EnumField) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type EnumParameter added in v0.3.5

type EnumParameter sql.NamedArg

EnumParameter is identical to sql.NamedArg, but implements the Enum interface.

func EnumParam added in v0.3.5

func EnumParam(name string, value Enumeration) EnumParameter

EnumParam creates a new EnumParameter. It wraps the value with EnumValue().

func (EnumParameter) IsEnum added in v0.3.5

func (p EnumParameter) IsEnum()

IsEnum implements the Enum interface.

func (EnumParameter) IsField added in v0.3.5

func (p EnumParameter) IsField()

IsField implements the Field interface.

func (EnumParameter) WriteSQL added in v0.3.5

func (p EnumParameter) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Enumeration

type Enumeration interface {
	// Enumerate returns the names of all valid enum values.
	//
	// If the enum is backed by a string, each string in the slice is the
	// corresponding enum's string value.
	//
	// If the enum is backed by an int, each int index in the slice is the
	// corresponding enum's int value and the string is the enum's name. Enums
	// with empty string names are considered invalid, unless it is the very
	// first enum (at index 0).
	Enumerate() []string
}

Enumeration represents a Go enum.

type Expression

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

Expression is an SQL expression that satisfies the Table, Field, Predicate, Binary, Boolean, Number, String and Time interfaces.

func Avg

func Avg(num Number) Expression

Avg represents an SQL AVG(<num>) expression.

func AvgOver

func AvgOver(num Number, window Window) Expression

AvgOver represents the AVG(<num>) OVER (<window>) window function.

func Count

func Count(field Field) Expression

Count represents an SQL COUNT(<field>) expression.

func CountOver

func CountOver(field Field, window Window) Expression

CountOver represents the COUNT(<field>) OVER (<window>) window function.

func CountStar

func CountStar() Expression

CountStar represents an SQL COUNT(*) expression.

func CountStarOver

func CountStarOver(window Window) Expression

CountStarOver represents the COUNT(*) OVER (<window>) window function.

func CumeDistOver

func CumeDistOver(window Window) Expression

CumeDistOver represents the CUME_DIST() OVER (<window>) window function.

func DenseRankOver

func DenseRankOver(window Window) Expression

DenseRankOver represents the DENSE_RANK() OVER (<window>) window function.

func Expr

func Expr(format string, values ...any) Expression

Expr creates a new Expression using Writef syntax.

func FirstValueOver

func FirstValueOver(field Field, window Window) Expression

FirstValueOver represents the FIRST_VALUE(<field>) OVER (<window>) window function.

func LastValueOver

func LastValueOver(field Field, window Window) Expression

LastValueOver represents the LAST_VALUE(<field>) OVER (<window>) window function.

func Max

func Max(field Field) Expression

Max represents an SQL MAX(<field>) expression.

func MaxOver

func MaxOver(field Field, window Window) Expression

MaxOver represents the MAX(<field>) OVER (<window>) window function.

func Min

func Min(field Field) Expression

Min represent an SQL MIN(<field>) expression.

func MinOver

func MinOver(field Field, window Window) Expression

MinOver represents the MIN(<field>) OVER (<window>) window function.

func RankOver

func RankOver(window Window) Expression

RankOver represents the RANK() OVER (<window>) window function.

func RowNumberOver

func RowNumberOver(window Window) Expression

RowNumberOver represents the ROW_NUMBER() OVER (<window>) window function.

func Sum

func Sum(num Number) Expression

Sum represents an SQL SUM(<num>) expression.

func SumOver

func SumOver(num Number, window Window) Expression

SumOver represents the SUM(<num>) OVER (<window>) window function.

func (Expression) As

func (expr Expression) As(alias string) Expression

As returns a new Expression with the given alias.

func (Expression) Eq

func (expr Expression) Eq(value any) Predicate

Eq returns an 'expr = value' Predicate.

func (Expression) Ge

func (expr Expression) Ge(value any) Predicate

Ge returns an 'expr >= value' Predicate.

func (Expression) GetAlias

func (expr Expression) GetAlias() string

GetAlias returns the alias of the Expression.

func (Expression) Gt

func (expr Expression) Gt(value any) Predicate

Gt returns an 'expr > value' Predicate.

func (Expression) In

func (expr Expression) In(value any) Predicate

In returns an 'expr IN (value)' Predicate.

func (Expression) IsArray

func (expr Expression) IsArray()

IsArray implements the Array interface.

func (Expression) IsAssignment

func (e Expression) IsAssignment()

func (Expression) IsBinary

func (expr Expression) IsBinary()

IsBinary implements the Binary interface.

func (Expression) IsBoolean

func (expr Expression) IsBoolean()

IsBoolean implements the Boolean interface.

func (Expression) IsEnum

func (expr Expression) IsEnum()

IsEnum implements the Enum interface.

func (Expression) IsField

func (expr Expression) IsField()

IsField implements the Field interface.

func (Expression) IsJSON

func (expr Expression) IsJSON()

IsJSON implements the JSON interface.

func (Expression) IsNumber

func (expr Expression) IsNumber()

IsNumber implements the Number interface.

func (Expression) IsString

func (expr Expression) IsString()

IsString implements the String interface.

func (Expression) IsTable

func (expr Expression) IsTable()

IsTable implements the Table interface.

func (Expression) IsTime

func (expr Expression) IsTime()

IsTime implements the Time interface.

func (Expression) IsUUID

func (expr Expression) IsUUID()

IsUUID implements the UUID interface.

func (Expression) Le

func (expr Expression) Le(value any) Predicate

Le returns an 'expr <= value' Predicate.

func (Expression) Lt

func (expr Expression) Lt(value any) Predicate

Lt returns an 'expr < value' Predicate.

func (Expression) Ne

func (expr Expression) Ne(value any) Predicate

Ne returns an 'expr <> value' Predicate.

func (Expression) NotIn added in v0.3.0

func (expr Expression) NotIn(value any) Predicate

In returns an 'expr NOT IN (value)' Predicate.

func (Expression) WriteSQL

func (expr Expression) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Field

type Field interface {
	SQLWriter
	IsField()
}

Field is either a table column or some SQL expression.

type Fields

type Fields []Field

Fields represents a list of Fields e.g. tbl.field1, tbl.field2, tbl.field3.

func (Fields) WriteSQL

func (fs Fields) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Identifier

type Identifier string

Identifier represents an SQL identifier. If necessary, it will be quoted according to the dialect.

func (Identifier) IsField

func (id Identifier) IsField()

IsField implements the Field interface.

func (Identifier) WriteSQL

func (id Identifier) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type InsertQuery

type InsertQuery struct {
	Dialect      string
	ColumnMapper func(*Column)
	// WITH
	CTEs []CTE
	// INSERT INTO
	InsertIgnore  bool
	InsertTable   Table
	InsertColumns []Field
	// VALUES
	RowValues []RowValue
	RowAlias  string
	// SELECT
	SelectQuery Query
	// ON CONFLICT
	Conflict ConflictClause
	// RETURNING
	ReturningFields []Field
}

InsertQuery represents an SQL INSERT query.

func InsertInto

func InsertInto(table Table) InsertQuery

InsertInto creates a new InsertQuery.

func (InsertQuery) ColumnValues

func (q InsertQuery) ColumnValues(colmapper func(*Column)) InsertQuery

ColumnValues sets the ColumnMapper field of the InsertQuery.

func (InsertQuery) Columns

func (q InsertQuery) Columns(fields ...Field) InsertQuery

Columns sets the InsertColumns field of the InsertQuery.

func (InsertQuery) GetDialect

func (q InsertQuery) GetDialect() string

GetDialect implements the Query interface.

func (InsertQuery) GetFetchableFields

func (q InsertQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (InsertQuery) Select

func (q InsertQuery) Select(query Query) InsertQuery

Select sets the SelectQuery field of the InsertQuery.

func (InsertQuery) SetDialect

func (q InsertQuery) SetDialect(dialect string) InsertQuery

SetDialect sets the dialect of the query.

func (InsertQuery) SetFetchableFields

func (q InsertQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (InsertQuery) Values

func (q InsertQuery) Values(values ...any) InsertQuery

Values sets the RowValues field of the InsertQuery.

func (InsertQuery) WriteSQL

func (q InsertQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) (err error)

WriteSQL implements the SQLWriter interface.

type JSON

type JSON interface {
	Field
	IsJSON()
}

JSON is a Field of json type.

type JSONField

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

JSONField represents an SQL JSON field.

func NewJSONField

func NewJSONField(name string, tbl TableStruct) JSONField

NewJSONField returns a new JSONField.

func (JSONField) As

func (field JSONField) As(alias string) JSONField

As returns a new JSONField with the given alias.

func (JSONField) GetAlias

func (field JSONField) GetAlias() string

GetAlias returns the alias of the JSONField.

func (JSONField) IsBinary added in v0.2.2

func (field JSONField) IsBinary()

IsBinary implements the Binary interface.

func (JSONField) IsField

func (field JSONField) IsField()

IsField implements the Field interface.

func (JSONField) IsJSON

func (field JSONField) IsJSON()

IsJSON implements the JSON interface.

func (JSONField) IsNotNull

func (field JSONField) IsNotNull() Predicate

IsNotNull returns a 'field IS NOT NULL' Predicate.

func (JSONField) IsNull

func (field JSONField) IsNull() Predicate

IsNull returns a 'field IS NULL' Predicate.

func (JSONField) IsString added in v0.2.2

func (field JSONField) IsString()

IsString implements the String interface.

func (JSONField) Set

func (field JSONField) Set(value any) Assignment

Set returns an Assignment assigning the value to the field.

func (JSONField) SetJSON

func (field JSONField) SetJSON(value any) Assignment

SetJSON returns an Assignment assigning the value to the field. It wraps the value in JSONValue().

func (JSONField) Setf

func (field JSONField) Setf(format string, values ...any) Assignment

Setf returns an Assignment assigning an expression to the field.

func (JSONField) WithPrefix

func (field JSONField) WithPrefix(prefix string) Field

WithPrefix returns a new Field that with the given prefix.

func (JSONField) WriteSQL

func (field JSONField) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type JSONParameter added in v0.3.5

type JSONParameter sql.NamedArg

JSONParameter is identical to sql.NamedArg, but implements the JSON interface.

func JSONParam added in v0.3.5

func JSONParam(name string, value any) JSONParameter

JSONParam creates a new JSONParameter. It wraps the value with JSONValue().

func (JSONParameter) IsField added in v0.3.5

func (p JSONParameter) IsField()

IsField implements the Field interface.

func (JSONParameter) IsJSON added in v0.3.5

func (p JSONParameter) IsJSON()

IsJSON implements the JSON interface.

func (JSONParameter) WriteSQL added in v0.3.5

func (p JSONParameter) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type JoinTable

type JoinTable struct {
	JoinOperator string
	Table        Table
	OnPredicate  Predicate
	UsingFields  []Field
}

JoinTable represents a join on a table.

func CrossJoin

func CrossJoin(table Table) JoinTable

CrossJoin creates a new JoinTable with the CROSS JOIN operator.

func CustomJoin

func CustomJoin(joinOperator string, table Table, predicates ...Predicate) JoinTable

CustomJoin creates a new JoinTable with the a custom join operator.

func FullJoin

func FullJoin(table Table, predicates ...Predicate) JoinTable

FullJoin creates a new JoinTable with the FULL JOIN operator.

func Join

func Join(table Table, predicates ...Predicate) JoinTable

Join creates a new JoinTable with the JOIN operator.

func JoinUsing

func JoinUsing(table Table, fields ...Field) JoinTable

JoinUsing creates a new JoinTable with the USING operator.

func LeftJoin

func LeftJoin(table Table, predicates ...Predicate) JoinTable

LeftJoin creates a new JoinTable with the LEFT JOIN operator.

func (JoinTable) WriteSQL

func (join JoinTable) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type LiteralValue

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

LiteralValue represents an SQL value literally interpolated into the query. Doing so potentially exposes the query to SQL injection so only do this for values that you trust e.g. literals and constants.

func Literal

func Literal(value any) LiteralValue

Literal returns a new LiteralValue.

func (LiteralValue) As

func (v LiteralValue) As(alias string) LiteralValue

As returns a new LiteralValue with the given alias.

func (LiteralValue) Eq

func (v LiteralValue) Eq(val any) Predicate

Eq returns a 'literal = val' Predicate.

func (LiteralValue) Ge

func (v LiteralValue) Ge(val any) Predicate

Ge returns a 'literal >= val' Predicate.

func (LiteralValue) GetAlias

func (v LiteralValue) GetAlias() string

GetAlias returns the alias of the LiteralValue.

func (LiteralValue) Gt

func (v LiteralValue) Gt(val any) Predicate

Gt returns a 'literal > val' Predicate.

func (LiteralValue) In

func (v LiteralValue) In(val any) Predicate

In returns a 'literal IN (val)' Predicate.

func (LiteralValue) IsBinary

func (v LiteralValue) IsBinary()

IsBinary implements the Binary interface.

func (LiteralValue) IsBoolean

func (v LiteralValue) IsBoolean()

IsBoolean implements the Boolean interface.

func (LiteralValue) IsField

func (v LiteralValue) IsField()

IsField implements the Field interface.

func (LiteralValue) IsNumber

func (v LiteralValue) IsNumber()

IsNumber implements the Number interface.

func (LiteralValue) IsString

func (v LiteralValue) IsString()

IsString implements the String interface.

func (LiteralValue) IsTime

func (v LiteralValue) IsTime()

IsTime implements the Time interfaces.

func (LiteralValue) Le

func (v LiteralValue) Le(val any) Predicate

Le returns a 'literal <= val' Predicate.

func (LiteralValue) Lt

func (v LiteralValue) Lt(val any) Predicate

Lt returns a 'literal < val' Predicate.

func (LiteralValue) Ne

func (v LiteralValue) Ne(val any) Predicate

Ne returns a 'literal <> val' Predicate.

func (LiteralValue) WriteSQL

func (v LiteralValue) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type LogSettings

type LogSettings struct {
	// Dispatch logging asynchronously (logs may arrive out of order which can be confusing, but it won't block function calls).
	LogAsynchronously bool

	// Include time taken by the query.
	IncludeTime bool

	// Include caller (filename and line number).
	IncludeCaller bool

	// Include fetched results.
	IncludeResults int
}

LogSettings are the various log settings taken into account when producing the QueryStats.

type LoggerConfig

type LoggerConfig struct {
	// Dispatch logging asynchronously (logs may arrive out of order which can be confusing, but it won't block function calls).
	LogAsynchronously bool

	// Show time taken by the query.
	ShowTimeTaken bool

	// Show caller (filename and line number).
	ShowCaller bool

	// Show fetched results.
	ShowResults int

	// If true, logs are shown as plaintext (no color).
	NoColor bool

	// Verbose query interpolation, which shows the query before and after
	// interpolating query arguments. The logged query is interpolated by
	// default, InterpolateVerbose only controls whether the query before
	// interpolation is shown. To disable query interpolation entirely, look at
	// HideArgs.
	InterpolateVerbose bool

	// Explicitly hides arguments when logging the query (only the query
	// placeholders will be shown).
	HideArgs bool
}

LoggerConfig is the config used for the sq logger.

type MySQLDeleteQuery

type MySQLDeleteQuery DeleteQuery

MySQLDeleteQuery represents a MySQL DELETE query.

func (MySQLDeleteQuery) CrossJoin

func (q MySQLDeleteQuery) CrossJoin(table Table) MySQLDeleteQuery

CrossJoin cross joins a new Table to the MySQLDeleteQuery.

func (MySQLDeleteQuery) CustomJoin

func (q MySQLDeleteQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) MySQLDeleteQuery

CustomJoin joins a new Table to the MySQLDeleteQuery with a custom join operator.

func (MySQLDeleteQuery) From

func (q MySQLDeleteQuery) From(table Table) MySQLDeleteQuery

From sets the UsingTable of the MySQLDeleteQuery.

func (MySQLDeleteQuery) FullJoin

func (q MySQLDeleteQuery) FullJoin(table Table, predicates ...Predicate) MySQLDeleteQuery

FullJoin full joins a new Table to the MySQLDeleteQuery.

func (MySQLDeleteQuery) GetDialect

func (q MySQLDeleteQuery) GetDialect() string

GetDialect implements the Query interface.

func (MySQLDeleteQuery) GetFetchableFields

func (q MySQLDeleteQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (MySQLDeleteQuery) Join

func (q MySQLDeleteQuery) Join(table Table, predicates ...Predicate) MySQLDeleteQuery

Join joins a new Table to the MySQLDeleteQuery.

func (MySQLDeleteQuery) JoinUsing

func (q MySQLDeleteQuery) JoinUsing(table Table, fields ...Field) MySQLDeleteQuery

JoinUsing joins a new Table to the MySQLDeleteQuery with the USING operator.

func (MySQLDeleteQuery) LeftJoin

func (q MySQLDeleteQuery) LeftJoin(table Table, predicates ...Predicate) MySQLDeleteQuery

LeftJoin left joins a new Table to the MySQLDeleteQuery.

func (MySQLDeleteQuery) Limit

func (q MySQLDeleteQuery) Limit(limit any) MySQLDeleteQuery

Limit sets the LimitRows field of the MySQLDeleteQuery.

func (MySQLDeleteQuery) OrderBy

func (q MySQLDeleteQuery) OrderBy(fields ...Field) MySQLDeleteQuery

OrderBy sets the OrderByFields field of the MySQLDeleteQuery.

func (MySQLDeleteQuery) Returning added in v0.2.9

func (q MySQLDeleteQuery) Returning(fields ...Field) MySQLDeleteQuery

Returning appends fields to the RETURNING clause of the MySQLDeleteQuery.

func (MySQLDeleteQuery) SetDialect

func (q MySQLDeleteQuery) SetDialect(dialect string) MySQLDeleteQuery

SetDialect sets the dialect of the query.

func (MySQLDeleteQuery) SetFetchableFields

func (q MySQLDeleteQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (MySQLDeleteQuery) Where

func (q MySQLDeleteQuery) Where(predicates ...Predicate) MySQLDeleteQuery

Where appends to the WherePredicate field of the MySQLDeleteQuery.

func (MySQLDeleteQuery) WriteSQL

func (q MySQLDeleteQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type MySQLInsertQuery

type MySQLInsertQuery InsertQuery

MySQLInsertQuery represents a MySQL INSERT query.

func (MySQLInsertQuery) As

func (q MySQLInsertQuery) As(rowAlias string) MySQLInsertQuery

As sets the RowAlias field of the MySQLInsertQuery.

func (MySQLInsertQuery) ColumnValues

func (q MySQLInsertQuery) ColumnValues(colmapper func(*Column)) MySQLInsertQuery

ColumnValues sets the ColumnMapper field of the MySQLInsertQuery.

func (MySQLInsertQuery) Columns

func (q MySQLInsertQuery) Columns(fields ...Field) MySQLInsertQuery

Columns sets the InsertColumns field of the MySQLInsertQuery.

func (MySQLInsertQuery) GetDialect

func (q MySQLInsertQuery) GetDialect() string

GetDialect implements the Query interface.

func (MySQLInsertQuery) GetFetchableFields

func (q MySQLInsertQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (MySQLInsertQuery) OnDuplicateKeyUpdate

func (q MySQLInsertQuery) OnDuplicateKeyUpdate(assignments ...Assignment) MySQLInsertQuery

OnDuplicateKeyUpdate sets the ON DUPLICATE KEY UPDATE clause of the MySQLInsertQuery.

func (MySQLInsertQuery) Returning added in v0.2.9

func (q MySQLInsertQuery) Returning(fields ...Field) MySQLInsertQuery

Returning adds fields to the RETURNING clause of the MySQLInsertQuery.

func (MySQLInsertQuery) Select

func (q MySQLInsertQuery) Select(query Query) MySQLInsertQuery

Select sets the SelectQuery field of the MySQLInsertQuery.

func (MySQLInsertQuery) SetDialect

func (q MySQLInsertQuery) SetDialect(dialect string) MySQLInsertQuery

SetDialect returns the dialect of the query.

func (MySQLInsertQuery) SetFetchableFields

func (q MySQLInsertQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (MySQLInsertQuery) Values

func (q MySQLInsertQuery) Values(values ...any) MySQLInsertQuery

Values sets the RowValues field of the MySQLInsertQuery.

func (MySQLInsertQuery) WriteSQL

func (q MySQLInsertQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type MySQLSelectQuery

type MySQLSelectQuery SelectQuery

MySQLSelectQuery represents a MySQL SELECT query.

func (MySQLSelectQuery) As

func (q MySQLSelectQuery) As(alias string, columns ...string) MySQLSelectQuery

As returns a new MySQLSelectQuery with the table alias (and optionally column aliases).

func (MySQLSelectQuery) CrossJoin

func (q MySQLSelectQuery) CrossJoin(table Table) MySQLSelectQuery

CrossJoin cross joins a new Table to the MySQLSelectQuery.

func (MySQLSelectQuery) CustomJoin

func (q MySQLSelectQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) MySQLSelectQuery

CustomJoin joins a new Table to the MySQLSelectQuery with a custom join operator.

func (MySQLSelectQuery) Field

func (q MySQLSelectQuery) Field(name string) AnyField

Field returns a new field qualified by the MySQLSelectQuery's alias.

func (MySQLSelectQuery) From

func (q MySQLSelectQuery) From(table Table) MySQLSelectQuery

From sets the FromTable field in the MySQLSelectQuery.

func (MySQLSelectQuery) FullJoin

func (q MySQLSelectQuery) FullJoin(table Table, predicates ...Predicate) MySQLSelectQuery

FullJoin full joins a new Table to the MySQLSelectQuery.

func (MySQLSelectQuery) GetAlias

func (q MySQLSelectQuery) GetAlias() string

GetAlias returns the alias of the MySQLSelectQuery.

func (MySQLSelectQuery) GetDialect

func (q MySQLSelectQuery) GetDialect() string

GetDialect implements the Query interface.

func (MySQLSelectQuery) GetFetchableFields

func (q MySQLSelectQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (MySQLSelectQuery) GroupBy

func (q MySQLSelectQuery) GroupBy(fields ...Field) MySQLSelectQuery

GroupBy appends to the GroupByFields field in the MySQLSelectQuery.

func (MySQLSelectQuery) Having

func (q MySQLSelectQuery) Having(predicates ...Predicate) MySQLSelectQuery

Having appends to the HavingPredicate field in the MySQLSelectQuery.

func (MySQLSelectQuery) IsArray

func (q MySQLSelectQuery) IsArray()

IsArray implements the Array interface.

func (MySQLSelectQuery) IsBinary

func (q MySQLSelectQuery) IsBinary()

IsBinary implements the Binary interface.

func (MySQLSelectQuery) IsBoolean

func (q MySQLSelectQuery) IsBoolean()

IsBoolean implements the Boolean interface.

func (MySQLSelectQuery) IsEnum

func (q MySQLSelectQuery) IsEnum()

IsEnum implements the Enum interface.

func (MySQLSelectQuery) IsField

func (q MySQLSelectQuery) IsField()

IsField implements the Field interface.

func (MySQLSelectQuery) IsJSON

func (q MySQLSelectQuery) IsJSON()

IsJSON implements the JSON interface.

func (MySQLSelectQuery) IsNumber

func (q MySQLSelectQuery) IsNumber()

IsNumber implements the Number interface.

func (MySQLSelectQuery) IsString

func (q MySQLSelectQuery) IsString()

IsString implements the String interface.

func (MySQLSelectQuery) IsTable

func (q MySQLSelectQuery) IsTable()

IsTable implements the Table interface.

func (MySQLSelectQuery) IsTime

func (q MySQLSelectQuery) IsTime()

IsTime implements the Time interface.

func (MySQLSelectQuery) IsUUID

func (q MySQLSelectQuery) IsUUID()

IsUUID implements the UUID interface.

func (MySQLSelectQuery) Join

func (q MySQLSelectQuery) Join(table Table, predicates ...Predicate) MySQLSelectQuery

Join joins a new Table to the MySQLSelectQuery.

func (MySQLSelectQuery) JoinUsing

func (q MySQLSelectQuery) JoinUsing(table Table, fields ...Field) MySQLSelectQuery

JoinUsing joins a new Table to the MySQLSelectQuery with the USING operator.

func (MySQLSelectQuery) LeftJoin

func (q MySQLSelectQuery) LeftJoin(table Table, predicates ...Predicate) MySQLSelectQuery

LeftJoin left joins a new Table to the MySQLSelectQuery.

func (MySQLSelectQuery) Limit

func (q MySQLSelectQuery) Limit(limit any) MySQLSelectQuery

Limit sets the LimitRows field in the MySQLSelectQuery.

func (MySQLSelectQuery) LockRows

func (q MySQLSelectQuery) LockRows(lockClause string, lockValues ...any) MySQLSelectQuery

LockRows sets the lock clause of the MySQLSelectQuery.

func (MySQLSelectQuery) Offset

func (q MySQLSelectQuery) Offset(offset any) MySQLSelectQuery

Offset sets the OffsetRows field in the MySQLSelectQuery.

func (MySQLSelectQuery) OrderBy

func (q MySQLSelectQuery) OrderBy(fields ...Field) MySQLSelectQuery

OrderBy appends to the OrderByFields field in the MySQLSelectQuery.

func (MySQLSelectQuery) Select

func (q MySQLSelectQuery) Select(fields ...Field) MySQLSelectQuery

Select appends to the SelectFields in the MySQLSelectQuery.

func (MySQLSelectQuery) SelectDistinct

func (q MySQLSelectQuery) SelectDistinct(fields ...Field) MySQLSelectQuery

SelectDistinct sets the SelectFields in the MySQLSelectQuery.

func (MySQLSelectQuery) SelectOne

func (q MySQLSelectQuery) SelectOne(fields ...Field) MySQLSelectQuery

SelectOne sets the MySQLSelectQuery to SELECT 1.

func (MySQLSelectQuery) SetDialect

func (q MySQLSelectQuery) SetDialect(dialect string) MySQLSelectQuery

SetDialect sets the dialect of the query.

func (MySQLSelectQuery) SetFetchableFields

func (q MySQLSelectQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (MySQLSelectQuery) Where

func (q MySQLSelectQuery) Where(predicates ...Predicate) MySQLSelectQuery

Where appends to the WherePredicate field in the MySQLSelectQuery.

func (MySQLSelectQuery) WriteSQL

func (q MySQLSelectQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type MySQLUpdateQuery

type MySQLUpdateQuery UpdateQuery

MySQLUpdateQuery represents a MySQL UPDATE query.

func (MySQLUpdateQuery) CrossJoin

func (q MySQLUpdateQuery) CrossJoin(table Table) MySQLUpdateQuery

CrossJoin cross joins a new Table to the MySQLUpdateQuery.

func (MySQLUpdateQuery) CustomJoin

func (q MySQLUpdateQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) MySQLUpdateQuery

CustomJoin joins a new Table to the MySQLUpdateQuery with a custom join operator.

func (MySQLUpdateQuery) FullJoin

func (q MySQLUpdateQuery) FullJoin(table Table, predicates ...Predicate) MySQLUpdateQuery

FullJoin full joins a new Table to the MySQLUpdateQuery.

func (MySQLUpdateQuery) GetDialect

func (q MySQLUpdateQuery) GetDialect() string

GetDialect implements the Query interface.

func (MySQLUpdateQuery) GetFetchableFields

func (q MySQLUpdateQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the MySQLUpdateQuery.

func (MySQLUpdateQuery) Join

func (q MySQLUpdateQuery) Join(table Table, predicates ...Predicate) MySQLUpdateQuery

Join joins a new Table to the MySQLUpdateQuery.

func (MySQLUpdateQuery) JoinUsing

func (q MySQLUpdateQuery) JoinUsing(table Table, fields ...Field) MySQLUpdateQuery

JoinUsing joins a new Table to the MySQLUpdateQuery with the USING operator.

func (MySQLUpdateQuery) LeftJoin

func (q MySQLUpdateQuery) LeftJoin(table Table, predicates ...Predicate) MySQLUpdateQuery

LeftJoin left joins a new Table to the MySQLUpdateQuery.

func (MySQLUpdateQuery) Limit

func (q MySQLUpdateQuery) Limit(limit any) MySQLUpdateQuery

Limit sets the LimitRows field of the MySQLUpdateQuery.

func (MySQLUpdateQuery) OrderBy

func (q MySQLUpdateQuery) OrderBy(fields ...Field) MySQLUpdateQuery

OrderBy sets the OrderByFields of the MySQLUpdateQuery.

func (MySQLUpdateQuery) Set

func (q MySQLUpdateQuery) Set(assignments ...Assignment) MySQLUpdateQuery

Set sets the Assignments field of the MySQLUpdateQuery.

func (MySQLUpdateQuery) SetDialect

func (q MySQLUpdateQuery) SetDialect(dialect string) MySQLUpdateQuery

SetDialect sets the dialect of the MySQLUpdateQuery.

func (MySQLUpdateQuery) SetFetchableFields

func (q MySQLUpdateQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (MySQLUpdateQuery) SetFunc

func (q MySQLUpdateQuery) SetFunc(colmapper func(*Column)) MySQLUpdateQuery

SetFunc sets the ColumnMapper of the MySQLUpdateQuery.

func (MySQLUpdateQuery) Where

func (q MySQLUpdateQuery) Where(predicates ...Predicate) MySQLUpdateQuery

Where appends to the WherePredicate field of the MySQLUpdateQuery.

func (MySQLUpdateQuery) WriteSQL

func (q MySQLUpdateQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type NamedWindow

type NamedWindow struct {
	Name       string
	Definition Window
}

NamedWindow represents an SQL named window.

func (NamedWindow) IsWindow

func (w NamedWindow) IsWindow()

IsWindow implements the Window interface.

func (NamedWindow) WriteSQL

func (w NamedWindow) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type NamedWindows

type NamedWindows []NamedWindow

NamedWindows represents a slice of NamedWindows.

func (NamedWindows) WriteSQL

func (ws NamedWindows) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL imeplements the SQLWriter interface.

type Number

type Number interface {
	Field
	IsNumber()
}

Number is a Field of numeric type.

type NumberField

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

NumberField represents an SQL number field.

func NewNumberField

func NewNumberField(name string, tbl TableStruct) NumberField

NewNumberField returns a new NumberField.

func (NumberField) As

func (field NumberField) As(alias string) NumberField

As returns a new NumberField with the given alias.

func (NumberField) Asc

func (field NumberField) Asc() NumberField

Asc returns a new NumberField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (NumberField) Desc

func (field NumberField) Desc() NumberField

Desc returns a new NumberField indicating that it should be ordered in ascending order i.e. 'ORDER BY field DESC'.

func (NumberField) Eq

func (field NumberField) Eq(value Number) Predicate

Eq returns a 'field = value' Predicate.

func (NumberField) EqFloat64

func (field NumberField) EqFloat64(num float64) Predicate

EqFloat64 returns a 'field = num' Predicate.

func (NumberField) EqInt

func (field NumberField) EqInt(num int) Predicate

EqInt returns a 'field = num' Predicate.

func (NumberField) EqInt64

func (field NumberField) EqInt64(num int64) Predicate

EqInt64 returns a 'field = num' Predicate.

func (NumberField) Ge

func (field NumberField) Ge(value Number) Predicate

Ge returns a 'field >= value' Predicate.

func (NumberField) GeFloat64

func (field NumberField) GeFloat64(num float64) Predicate

GeFloat64 returns a 'field >= num' Predicate.

func (NumberField) GeInt

func (field NumberField) GeInt(num int) Predicate

GeInt returns a 'field >= num' Predicate.

func (NumberField) GeInt64

func (field NumberField) GeInt64(num int64) Predicate

GeInt64 returns a 'field >= num' Predicate.

func (NumberField) GetAlias

func (field NumberField) GetAlias() string

GetAlias returns the alias of the NumberField.

func (NumberField) Gt

func (field NumberField) Gt(value Number) Predicate

Gt returns a 'field > value' Predicate.

func (NumberField) GtFloat64

func (field NumberField) GtFloat64(num float64) Predicate

GtFloat64 returns a 'field > num' Predicate.

func (NumberField) GtInt

func (field NumberField) GtInt(num int) Predicate

GtInt returns a 'field > num' Predicate.

func (NumberField) GtInt64

func (field NumberField) GtInt64(num int64) Predicate

GtInt64 returns a 'field > num' Predicate.

func (NumberField) In

func (field NumberField) In(value any) Predicate

In returns a 'field IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field IN (x, y, z)'.

func (NumberField) IsField

func (field NumberField) IsField()

IsField implements the Field interface.

func (NumberField) IsNotNull

func (field NumberField) IsNotNull() Predicate

IsNotNull returns a 'field IS NOT NULL' Predicate.

func (NumberField) IsNull

func (field NumberField) IsNull() Predicate

IsNull returns a 'field IS NULL' Predicate.

func (NumberField) IsNumber

func (field NumberField) IsNumber()

IsNumber implements the Number interface.

func (NumberField) Le

func (field NumberField) Le(value Number) Predicate

Le returns a 'field <= value' Predicate.

func (NumberField) LeFloat64

func (field NumberField) LeFloat64(num float64) Predicate

LeFloat64 returns a 'field <= num' Predicate.

func (NumberField) LeInt

func (field NumberField) LeInt(num int) Predicate

LeInt returns a 'field <= num' Predicate.

func (NumberField) LeInt64

func (field NumberField) LeInt64(num int64) Predicate

LeInt64 returns a 'field <= num' Predicate.

func (NumberField) Lt

func (field NumberField) Lt(value Number) Predicate

Lt returns a 'field < value' Predicate.

func (NumberField) LtFloat64

func (field NumberField) LtFloat64(num float64) Predicate

LtFloat64 returns a 'field < num' Predicate.

func (NumberField) LtInt

func (field NumberField) LtInt(num int) Predicate

LtInt returns a 'field < num' Predicate.

func (NumberField) LtInt64

func (field NumberField) LtInt64(num int64) Predicate

LtInt64 returns a 'field < num' Predicate.

func (NumberField) Ne

func (field NumberField) Ne(value Number) Predicate

Ne returns a 'field <> value' Predicate.

func (NumberField) NeFloat64

func (field NumberField) NeFloat64(num float64) Predicate

NeFloat64 returns a 'field <> num' Predicate.

func (NumberField) NeInt

func (field NumberField) NeInt(num int) Predicate

NeInt returns a 'field <> num' Predicate.

func (NumberField) NeInt64

func (field NumberField) NeInt64(num int64) Predicate

NeInt64 returns a 'field <> num' Predicate.

func (NumberField) NotIn added in v0.3.0

func (field NumberField) NotIn(value any) Predicate

NotIn returns a 'field NOT IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field IN (x, y, z)'.

func (NumberField) NullsFirst

func (field NumberField) NullsFirst() NumberField

NullsFirst returns a new NumberField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (NumberField) NullsLast

func (field NumberField) NullsLast() NumberField

NullsLast returns a new NumberField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

func (NumberField) Set

func (field NumberField) Set(value any) Assignment

Set returns an Assignment assigning the value to the field.

func (NumberField) SetFloat64

func (field NumberField) SetFloat64(num float64) Assignment

SetBytes returns an Assignment assigning an float64 to the field.

func (NumberField) SetInt

func (field NumberField) SetInt(num int) Assignment

SetBytes returns an Assignment assigning an int to the field.

func (NumberField) SetInt64

func (field NumberField) SetInt64(num int64) Assignment

SetBytes returns an Assignment assigning an int64 to the field.

func (NumberField) Setf

func (field NumberField) Setf(format string, values ...any) Assignment

Setf returns an Assignment assigning an expression to the field.

func (NumberField) WithPrefix

func (field NumberField) WithPrefix(prefix string) Field

WithPrefix returns a new Field that with the given prefix.

func (NumberField) WriteSQL

func (field NumberField) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type NumberParameter

type NumberParameter sql.NamedArg

NumberParameter is identical to sql.NamedArg, but implements the Number interface.

func Float64Param

func Float64Param(name string, num float64) NumberParameter

Float64Param creates a new NumberParameter from an float64 value.

func Int64Param

func Int64Param(name string, num int64) NumberParameter

Int64Param creates a new NumberParameter from an int64 value.

func IntParam

func IntParam(name string, num int) NumberParameter

IntParam creates a new NumberParameter from an int value.

func (NumberParameter) IsField

func (p NumberParameter) IsField()

IsField implements the Field interface.

func (NumberParameter) IsNumber

func (p NumberParameter) IsNumber()

IsNumber implements the Number interface.

func (NumberParameter) WriteSQL

func (p NumberParameter) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Parameter

type Parameter sql.NamedArg

Parameter is identical to sql.NamedArg, but implements the Field interface.

func Param

func Param(name string, value any) Parameter

Param creates a new Parameter.

func (Parameter) IsField

func (p Parameter) IsField()

IsField implements the Field interface.

func (Parameter) WriteSQL

func (p Parameter) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Params

type Params = map[string]any

Params is a shortcut for typing map[string]interface{}.

type PolicyTable

type PolicyTable interface {
	Table
	Policy(ctx context.Context, dialect string) (Predicate, error)
}

PolicyTable is a table that produces a policy (i.e. a predicate) to be enforced whenever it is invoked in a query. This is equivalent to Postgres' Row Level Security (RLS) feature but works application-side. Only SELECT, UPDATE and DELETE queries are affected.

type PostgresDeleteQuery

type PostgresDeleteQuery DeleteQuery

PostgresDeleteQuery represents a Postgres DELETE query.

func (PostgresDeleteQuery) CrossJoin

func (q PostgresDeleteQuery) CrossJoin(table Table) PostgresDeleteQuery

CrossJoin cross joins a new Table to the PostgresDeleteQuery.

func (PostgresDeleteQuery) CustomJoin

func (q PostgresDeleteQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) PostgresDeleteQuery

CustomJoin joins a new Table to the PostgresDeleteQuery with a custom join operator.

func (PostgresDeleteQuery) FullJoin

func (q PostgresDeleteQuery) FullJoin(table Table, predicates ...Predicate) PostgresDeleteQuery

FullJoin full joins a new Table to the PostgresDeleteQuery.

func (PostgresDeleteQuery) GetDialect

func (q PostgresDeleteQuery) GetDialect() string

GetDialect implements the Query interface.

func (PostgresDeleteQuery) GetFetchableFields

func (q PostgresDeleteQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (PostgresDeleteQuery) Join

func (q PostgresDeleteQuery) Join(table Table, predicates ...Predicate) PostgresDeleteQuery

Join joins a new Table to the PostgresDeleteQuery.

func (PostgresDeleteQuery) JoinUsing

func (q PostgresDeleteQuery) JoinUsing(table Table, fields ...Field) PostgresDeleteQuery

JoinUsing joins a new Table to the PostgresDeleteQuery with the USING operator.

func (PostgresDeleteQuery) LeftJoin

func (q PostgresDeleteQuery) LeftJoin(table Table, predicates ...Predicate) PostgresDeleteQuery

LeftJoin left joins a new Table to the PostgresDeleteQuery.

func (PostgresDeleteQuery) Returning

func (q PostgresDeleteQuery) Returning(fields ...Field) PostgresDeleteQuery

Returning appends fields to the RETURNING clause of the PostgresDeleteQuery.

func (PostgresDeleteQuery) SetDialect

func (q PostgresDeleteQuery) SetDialect(dialect string) PostgresDeleteQuery

SetDialect sets the dialect of the query.

func (PostgresDeleteQuery) SetFetchableFields

func (q PostgresDeleteQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (PostgresDeleteQuery) Using

Using sets the UsingTable field of the PostgresDeleteQuery.

func (PostgresDeleteQuery) Where

func (q PostgresDeleteQuery) Where(predicates ...Predicate) PostgresDeleteQuery

Where appends to the WherePredicate field of the PostgresDeleteQuery.

func (PostgresDeleteQuery) WriteSQL

func (q PostgresDeleteQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type PostgresInsertQuery

type PostgresInsertQuery InsertQuery

PostgresInsertQuery represents a Postgres INSERT query.

func (PostgresInsertQuery) ColumnValues

func (q PostgresInsertQuery) ColumnValues(colmapper func(*Column)) PostgresInsertQuery

ColumnValues sets the ColumnMapper field of the PostgresInsertQuery.

func (PostgresInsertQuery) Columns

func (q PostgresInsertQuery) Columns(fields ...Field) PostgresInsertQuery

Columns sets the InsertColumns field of the PostgresInsertQuery.

func (PostgresInsertQuery) GetDialect

func (q PostgresInsertQuery) GetDialect() string

GetDialect implements the Query interface.

func (PostgresInsertQuery) GetFetchableFields

func (q PostgresInsertQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (PostgresInsertQuery) OnConflict

func (q PostgresInsertQuery) OnConflict(fields ...Field) postgresInsertConflict

OnConflict starts the ON CONFLICT clause of the PostgresInsertQuery.

func (PostgresInsertQuery) OnConflictOnConstraint

func (q PostgresInsertQuery) OnConflictOnConstraint(constraintName string) postgresInsertConflict

OnConflict starts the ON CONFLICT clause of the PostgresInsertQuery.

func (PostgresInsertQuery) Returning

func (q PostgresInsertQuery) Returning(fields ...Field) PostgresInsertQuery

Returning adds fields to the RETURNING clause of the PostgresInsertQuery.

func (PostgresInsertQuery) Select

Select sets the SelectQuery field of the PostgresInsertQuery.

func (PostgresInsertQuery) SetDialect

func (q PostgresInsertQuery) SetDialect(dialect string) PostgresInsertQuery

SetDialect returns the dialect of the query.

func (PostgresInsertQuery) SetFetchableFields

func (q PostgresInsertQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (PostgresInsertQuery) Values

func (q PostgresInsertQuery) Values(values ...any) PostgresInsertQuery

Values sets the RowValues field of the PostgresInsertQuery.

func (PostgresInsertQuery) Where

func (q PostgresInsertQuery) Where(predicates ...Predicate) PostgresInsertQuery

Where adds predicates to the DO UPDATE SET clause of the PostgresInsertQuery.

func (PostgresInsertQuery) WriteSQL

func (q PostgresInsertQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type PostgresSelectQuery

type PostgresSelectQuery SelectQuery

PostgresSelectQuery represents a Postgres SELECT query.

func (PostgresSelectQuery) As

func (q PostgresSelectQuery) As(alias string, columns ...string) PostgresSelectQuery

As returns a new PostgresSelectQuery with the table alias (and optionally column aliases).

func (PostgresSelectQuery) CrossJoin

func (q PostgresSelectQuery) CrossJoin(table Table) PostgresSelectQuery

CrossJoin cross joins a new Table to the PostgresSelectQuery.

func (PostgresSelectQuery) CustomJoin

func (q PostgresSelectQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) PostgresSelectQuery

CustomJoin joins a new Table to the PostgresSelectQuery with a custom join operator.

func (PostgresSelectQuery) DistinctOn

func (q PostgresSelectQuery) DistinctOn(fields ...Field) PostgresSelectQuery

DistinctOn sets the DistinctOnFields in the PostgresSelectQuery.

func (PostgresSelectQuery) FetchNext

FetchNext sets the FetchNextRows field in the PostgresSelectQuery.

func (PostgresSelectQuery) Field

func (q PostgresSelectQuery) Field(name string) AnyField

Field returns a new field qualified by the PostgresSelectQuery's alias.

func (PostgresSelectQuery) From

From sets the FromTable field in the PostgresSelectQuery.

func (PostgresSelectQuery) FullJoin

func (q PostgresSelectQuery) FullJoin(table Table, predicates ...Predicate) PostgresSelectQuery

FullJoin full joins a new Table to the PostgresSelectQuery.

func (PostgresSelectQuery) GetAlias

func (q PostgresSelectQuery) GetAlias() string

GetAlias returns the alias of the PostgresSelectQuery.

func (PostgresSelectQuery) GetDialect

func (q PostgresSelectQuery) GetDialect() string

GetDialect implements the Query interface.

func (PostgresSelectQuery) GetFetchableFields

func (q PostgresSelectQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (PostgresSelectQuery) GroupBy

func (q PostgresSelectQuery) GroupBy(fields ...Field) PostgresSelectQuery

GroupBy appends to the GroupByFields field in the PostgresSelectQuery.

func (PostgresSelectQuery) Having

func (q PostgresSelectQuery) Having(predicates ...Predicate) PostgresSelectQuery

Having appends to the HavingPredicate field in the PostgresSelectQuery.

func (PostgresSelectQuery) IsArray

func (q PostgresSelectQuery) IsArray()

IsArray implements the Array interface.

func (PostgresSelectQuery) IsBinary

func (q PostgresSelectQuery) IsBinary()

IsBinary implements the Binary interface.

func (PostgresSelectQuery) IsBoolean

func (q PostgresSelectQuery) IsBoolean()

IsBoolean implements the Boolean interface.

func (PostgresSelectQuery) IsEnum

func (q PostgresSelectQuery) IsEnum()

IsEnum implements the Enum interface.

func (PostgresSelectQuery) IsField

func (q PostgresSelectQuery) IsField()

IsField implements the Field interface.

func (PostgresSelectQuery) IsJSON

func (q PostgresSelectQuery) IsJSON()

IsJSON implements the JSON interface.

func (PostgresSelectQuery) IsNumber

func (q PostgresSelectQuery) IsNumber()

IsNumber implements the Number interface.

func (PostgresSelectQuery) IsString

func (q PostgresSelectQuery) IsString()

IsString implements the String interface.

func (PostgresSelectQuery) IsTable

func (q PostgresSelectQuery) IsTable()

IsTable implements the Table interface.

func (PostgresSelectQuery) IsTime

func (q PostgresSelectQuery) IsTime()

IsTime implements the Time interface.

func (PostgresSelectQuery) IsUUID

func (q PostgresSelectQuery) IsUUID()

IsUUID implements the UUID interface.

func (PostgresSelectQuery) Join

func (q PostgresSelectQuery) Join(table Table, predicates ...Predicate) PostgresSelectQuery

Join joins a new Table to the PostgresSelectQuery.

func (PostgresSelectQuery) JoinUsing

func (q PostgresSelectQuery) JoinUsing(table Table, fields ...Field) PostgresSelectQuery

JoinUsing joins a new Table to the PostgresSelectQuery with the USING operator.

func (PostgresSelectQuery) LeftJoin

func (q PostgresSelectQuery) LeftJoin(table Table, predicates ...Predicate) PostgresSelectQuery

LeftJoin left joins a new Table to the PostgresSelectQuery.

func (PostgresSelectQuery) Limit

Limit sets the LimitRows field in the PostgresSelectQuery.

func (PostgresSelectQuery) LockRows

func (q PostgresSelectQuery) LockRows(lockClause string, lockValues ...any) PostgresSelectQuery

LockRows sets the lock clause of the PostgresSelectQuery.

func (PostgresSelectQuery) Offset

func (q PostgresSelectQuery) Offset(offset any) PostgresSelectQuery

Offset sets the OffsetRows field in the PostgresSelectQuery.

func (PostgresSelectQuery) OrderBy

func (q PostgresSelectQuery) OrderBy(fields ...Field) PostgresSelectQuery

OrderBy appends to the OrderByFields field in the PostgresSelectQuery.

func (PostgresSelectQuery) Select

func (q PostgresSelectQuery) Select(fields ...Field) PostgresSelectQuery

Select appends to the SelectFields in the PostgresSelectQuery.

func (PostgresSelectQuery) SelectDistinct

func (q PostgresSelectQuery) SelectDistinct(fields ...Field) PostgresSelectQuery

SelectDistinct sets the SelectFields in the PostgresSelectQuery.

func (PostgresSelectQuery) SelectOne

func (q PostgresSelectQuery) SelectOne(fields ...Field) PostgresSelectQuery

SelectOne sets the PostgresSelectQuery to SELECT 1.

func (PostgresSelectQuery) SetDialect

func (q PostgresSelectQuery) SetDialect(dialect string) PostgresSelectQuery

SetDialect sets the dialect of the query.

func (PostgresSelectQuery) SetFetchableFields

func (q PostgresSelectQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (PostgresSelectQuery) Where

func (q PostgresSelectQuery) Where(predicates ...Predicate) PostgresSelectQuery

Where appends to the WherePredicate field in the PostgresSelectQuery.

func (PostgresSelectQuery) WithTies

WithTies enables the FetchWithTies field in the PostgresSelectQuery.

func (PostgresSelectQuery) WriteSQL

func (q PostgresSelectQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type PostgresUpdateQuery

type PostgresUpdateQuery UpdateQuery

PostgresUpdateQuery represents a Postgres UPDATE query.

func (PostgresUpdateQuery) CrossJoin

func (q PostgresUpdateQuery) CrossJoin(table Table) PostgresUpdateQuery

CrossJoin cross joins a new Table to the PostgresUpdateQuery.

func (PostgresUpdateQuery) CustomJoin

func (q PostgresUpdateQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) PostgresUpdateQuery

CustomJoin joins a new Table to the PostgresUpdateQuery with a custom join operator.

func (PostgresUpdateQuery) From

From sets the FromTable field of the PostgresUpdateQuery.

func (PostgresUpdateQuery) FullJoin

func (q PostgresUpdateQuery) FullJoin(table Table, predicates ...Predicate) PostgresUpdateQuery

FullJoin full joins a new Table to the PostgresUpdateQuery.

func (PostgresUpdateQuery) GetDialect

func (q PostgresUpdateQuery) GetDialect() string

GetDialect implements the Query interface.

func (PostgresUpdateQuery) GetFetchableFields

func (q PostgresUpdateQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the PostgresUpdateQuery.

func (PostgresUpdateQuery) Join

func (q PostgresUpdateQuery) Join(table Table, predicates ...Predicate) PostgresUpdateQuery

Join joins a new Table to the PostgresUpdateQuery.

func (PostgresUpdateQuery) JoinUsing

func (q PostgresUpdateQuery) JoinUsing(table Table, fields ...Field) PostgresUpdateQuery

JoinUsing joins a new Table to the PostgresUpdateQuery with the USING operator.

func (PostgresUpdateQuery) LeftJoin

func (q PostgresUpdateQuery) LeftJoin(table Table, predicates ...Predicate) PostgresUpdateQuery

LeftJoin left joins a new Table to the PostgresUpdateQuery.

func (PostgresUpdateQuery) Returning

func (q PostgresUpdateQuery) Returning(fields ...Field) PostgresUpdateQuery

Returning sets the ReturningFields field of the PostgresUpdateQuery.

func (PostgresUpdateQuery) Set

func (q PostgresUpdateQuery) Set(assignments ...Assignment) PostgresUpdateQuery

Set sets the Assignments field of the PostgresUpdateQuery.

func (PostgresUpdateQuery) SetDialect

func (q PostgresUpdateQuery) SetDialect(dialect string) PostgresUpdateQuery

SetDialect sets the dialect of the PostgresUpdateQuery.

func (PostgresUpdateQuery) SetFetchableFields

func (q PostgresUpdateQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (PostgresUpdateQuery) SetFunc

func (q PostgresUpdateQuery) SetFunc(colmapper func(*Column)) PostgresUpdateQuery

SetFunc sets the ColumnMapper of the PostgresUpdateQuery.

func (PostgresUpdateQuery) Where

func (q PostgresUpdateQuery) Where(predicates ...Predicate) PostgresUpdateQuery

Where appends to the WherePredicate field of the PostgresUpdateQuery.

func (PostgresUpdateQuery) WriteSQL

func (q PostgresUpdateQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Predicate

type Predicate interface {
	Boolean
}

Predicate is an SQL expression that evaluates to true or false.

func Eq

func Eq(x, y any) Predicate

Eq returns an 'x = y' Predicate.

func Exists

func Exists(query Query) Predicate

Exists returns an 'EXISTS (query)' Predicate.

func Ge

func Ge(x, y any) Predicate

Ge returns an 'x >= y' Predicate.

func Gt

func Gt(x, y any) Predicate

Gt returns an 'x > y' Predicate.

func In

func In(x, y any) Predicate

In returns an 'x IN (y)' Predicate.

func Le

func Le(x, y any) Predicate

Le returns an 'x <= y' Predicate.

func Lt

func Lt(x, y any) Predicate

Lt returns an 'x < y' Predicate.

func Ne

func Ne(x, y any) Predicate

Ne returns an 'x <> y' Predicate.

func NotExists

func NotExists(query Query) Predicate

NotExists returns a 'NOT EXISTS (query)' Predicate.

func NotIn added in v0.3.0

func NotIn(x, y any) Predicate

NotIn returns an 'x NOT IN (y)' Predicate.

type PredicateCase

type PredicateCase struct {
	Predicate Predicate
	Result    any
}

PredicateCase holds the result to be used for a given predicate in a CaseExpression.

type PredicateCases

type PredicateCases = []PredicateCase

PredicateCases is a slice of PredicateCases.

type PreparedExec

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

PrepareExec is the result of preparing a CompiledExec on a DB.

func PrepareExec

func PrepareExec(db DB, q Query) (*PreparedExec, error)

PrepareExec returns a new PreparedExec.

func PrepareExecContext

func PrepareExecContext(ctx context.Context, db DB, q Query) (*PreparedExec, error)

PrepareExecContext is like PrepareExec but additionally requires a context.Context.

func (*PreparedExec) Close

func (preparedExec *PreparedExec) Close() error

Close closes the PreparedExec.

func (*PreparedExec) Exec

func (preparedExec *PreparedExec) Exec(params Params) (Result, error)

Exec executes the PreparedExec with the given params.

func (*PreparedExec) ExecContext

func (preparedExec *PreparedExec) ExecContext(ctx context.Context, params Params) (Result, error)

ExecContext is like Exec but additionally requires a context.Context.

type PreparedFetch

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

PreparedFetch is the result of preparing a CompiledFetch on a DB.

func PrepareFetch

func PrepareFetch[T any](db DB, q Query, rowmapper func(*Row) T) (*PreparedFetch[T], error)

PrepareFetch returns a new PreparedFetch.

func PrepareFetchContext

func PrepareFetchContext[T any](ctx context.Context, db DB, q Query, rowmapper func(*Row) T) (*PreparedFetch[T], error)

PrepareFetchContext is like PrepareFetch but additionally requires a context.Context.

func (*PreparedFetch[T]) Close

func (preparedFetch *PreparedFetch[T]) Close() error

Close closes the PreparedFetch.

func (*PreparedFetch[T]) FetchAll

func (preparedFetch *PreparedFetch[T]) FetchAll(params Params) ([]T, error)

FetchAll returns all the results from running the PreparedFetch with the give params.

func (*PreparedFetch[T]) FetchAllContext

func (preparedFetch *PreparedFetch[T]) FetchAllContext(ctx context.Context, params Params) ([]T, error)

FetchAllContext is like FetchAll but additionally requires a context.Context.

func (PreparedFetch[T]) FetchCursor

func (preparedFetch PreparedFetch[T]) FetchCursor(params Params) (*Cursor[T], error)

FetchCursor returns a new cursor.

func (PreparedFetch[T]) FetchCursorContext

func (preparedFetch PreparedFetch[T]) FetchCursorContext(ctx context.Context, params Params) (*Cursor[T], error)

FetchCursorContext is like FetchCursor but additionally requires a context.Context.

func (*PreparedFetch[T]) FetchOne

func (preparedFetch *PreparedFetch[T]) FetchOne(params Params) (T, error)

FetchOne returns the first result from running the PreparedFetch with the give params.

func (*PreparedFetch[T]) FetchOneContext

func (preparedFetch *PreparedFetch[T]) FetchOneContext(ctx context.Context, params Params) (T, error)

FetchOneContext is like FetchOne but additionally requires a context.Context.

func (*PreparedFetch[T]) GetCompiled

func (preparedFetch *PreparedFetch[T]) GetCompiled() *CompiledFetch[T]

GetCompiled returns a copy of the underlying CompiledFetch.

type Query

type Query interface {
	SQLWriter
	// SetFetchableFields should return a query with its fetchable fields set
	// to the given fields. If not applicable, it should return false as the
	// second return value.
	SetFetchableFields([]Field) (query Query, ok bool)
	GetDialect() string
}

Query is either SELECT, INSERT, UPDATE or DELETE.

type QueryStats

type QueryStats struct {
	// Dialect of the query.
	Dialect string

	// Query string.
	Query string

	// Args slice provided with the query string.
	Args []any

	// Params maps param names back to arguments in the args slice (by index).
	Params map[string][]int

	// Err is the error from running the query.
	Err error

	// RowCount from running the query. Not valid for Exec().
	RowCount sql.NullInt64

	// RowsAffected by running the query. Not valid for
	// FetchOne/FetchAll/FetchCursor.
	RowsAffected sql.NullInt64

	// LastInsertId of the query.
	LastInsertId sql.NullInt64

	// Exists is the result of FetchExists().
	Exists sql.NullBool

	// When the query started at.
	StartedAt time.Time

	// Time taken by the query.
	TimeTaken time.Duration

	// The caller file where the query was invoked.
	CallerFile string

	// The line in the caller file that invoked the query.
	CallerLine int

	// The name of the function where the query was invoked.
	CallerFunction string

	// The results from running the query (if it was provided).
	Results string
}

QueryStats represents the statistics from running a query.

type Result

type Result struct {
	LastInsertId int64
	RowsAffected int64
}

Result is the result of an Exec command.

func Exec

func Exec(db DB, query Query) (Result, error)

Exec executes the given Query on the given DB.

func ExecContext

func ExecContext(ctx context.Context, db DB, query Query) (Result, error)

ExecContext is like Exec but additionally requires a context.Context.

type Row

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

Row represents the state of a row after a call to rows.Next().

func (*Row) Array

func (row *Row) Array(destPtr any, format string, values ...any)

Array scans the array expression into destPtr. The destPtr must be a pointer to a []string, []int, []int64, []int32, []float64, []float32 or []bool.

func (*Row) ArrayField

func (row *Row) ArrayField(destPtr any, field Array)

ArrayField scans the array field into destPtr. The destPtr must be a pointer to a []string, []int, []int64, []int32, []float64, []float32 or []bool.

func (*Row) Bool

func (row *Row) Bool(format string, values ...any) bool

Bool returns the bool value of the expression.

func (*Row) BoolField

func (row *Row) BoolField(field Boolean) bool

BoolField returns the bool value of the field.

func (*Row) Bytes

func (row *Row) Bytes(format string, values ...any) []byte

Bytes returns the []byte value of the expression.

func (*Row) BytesField

func (row *Row) BytesField(field Binary) []byte

BytesField returns the []byte value of the field.

func (*Row) ColumnTypes added in v0.3.0

func (row *Row) ColumnTypes() []*sql.ColumnType

ColumnTypes returns the column types returned by the query. This method can only be called in a rowmapper if it is paired with a raw SQL query e.g. Queryf("SELECT * FROM my_table"). Otherwise, an error will be returned.

func (*Row) Columns added in v0.3.0

func (row *Row) Columns() []string

Column returns the names of the columns returned by the query. This method can only be called in a rowmapper if it is paired with a raw SQL query e.g. Queryf("SELECT * FROM my_table"). Otherwise, an error will be returned.

func (*Row) Enum

func (row *Row) Enum(destPtr Enumeration, format string, values ...any)

Enum scans the enum expression into destPtr.

func (*Row) EnumField

func (row *Row) EnumField(destPtr Enumeration, field Enum)

EnumField scans the enum field into destPtr.

func (*Row) Float64

func (row *Row) Float64(format string, values ...any) float64

Float64 returns the float64 value of the expression.

func (*Row) Float64Field

func (row *Row) Float64Field(field Number) float64

Float64Field returns the float64 value of the field.

func (*Row) Int

func (row *Row) Int(format string, values ...any) int

Int returns the int value of the expression.

func (*Row) Int64

func (row *Row) Int64(format string, values ...any) int64

Int64 returns the int64 value of the expression.

func (*Row) Int64Field

func (row *Row) Int64Field(field Number) int64

Int64Field returns the int64 value of the field.

func (*Row) IntField

func (row *Row) IntField(field Number) int

IntField returns the int value of the field.

func (*Row) JSON

func (row *Row) JSON(destPtr any, format string, values ...any)

JSON scans the JSON expression into destPtr.

func (*Row) JSONField

func (row *Row) JSONField(destPtr any, field JSON)

JSONField scans the JSON field into destPtr.

func (*Row) NullBool

func (row *Row) NullBool(format string, values ...any) sql.NullBool

NullBool returns the sql.NullBool value of the expression.

func (*Row) NullBoolField

func (row *Row) NullBoolField(field Boolean) sql.NullBool

NullBoolField returns the sql.NullBool value of the field.

func (*Row) NullFloat64

func (row *Row) NullFloat64(format string, values ...any) sql.NullFloat64

NullFloat64 returns the sql.NullFloat64 valye of the expression.

func (*Row) NullFloat64Field

func (row *Row) NullFloat64Field(field Number) sql.NullFloat64

NullFloat64Field returns the sql.NullFloat64 value of the field.

func (*Row) NullInt64

func (row *Row) NullInt64(format string, values ...any) sql.NullInt64

NullInt64 returns the sql.NullInt64 value of the expression.

func (*Row) NullInt64Field

func (row *Row) NullInt64Field(field Number) sql.NullInt64

NullInt64Field returns the sql.NullInt64 value of the field.

func (*Row) NullString

func (row *Row) NullString(format string, values ...any) sql.NullString

NullString returns the sql.NullString value of the expression.

func (*Row) NullStringField

func (row *Row) NullStringField(field String) sql.NullString

NullStringField returns the sql.NullString value of the field.

func (*Row) NullTime

func (row *Row) NullTime(format string, values ...any) sql.NullTime

NullTime returns the sql.NullTime value of the expression.

func (*Row) NullTimeField

func (row *Row) NullTimeField(field Time) sql.NullTime

NullTimeField returns the sql.NullTime value of the field.

func (*Row) Scan

func (row *Row) Scan(destPtr any, format string, values ...any)

Scan scans the expression into destPtr.

func (*Row) ScanField

func (row *Row) ScanField(destPtr any, field Field)

ScanField scans the field into destPtr.

func (*Row) String

func (row *Row) String(format string, values ...any) string

String returns the string value of the expression.

func (*Row) StringField

func (row *Row) StringField(field String) string

String returns the string value of the field.

func (*Row) Time

func (row *Row) Time(format string, values ...any) time.Time

Time returns the time.Time value of the expression.

func (*Row) TimeField

func (row *Row) TimeField(field Time) time.Time

Time returns the time.Time value of the field.

func (*Row) UUID

func (row *Row) UUID(destPtr any, format string, values ...any)

UUID scans the UUID expression into destPtr.

func (*Row) UUIDField

func (row *Row) UUIDField(destPtr any, field UUID)

UUIDField scans the UUID field into destPtr.

func (*Row) Value added in v0.3.0

func (row *Row) Value(format string, values ...any) any

Value returns the value of the expression. It is intended for use cases where you only know the name of the column but not its type to scan into. The underlying type of the value is determined by the database driver you are using.

func (*Row) Values added in v0.3.0

func (row *Row) Values() []any

Values returns the values of the current row. This method can only be called in a rowmapper if it is paired with a raw SQL query e.g. Queryf("SELECT * FROM my_table"). Otherwise, an error will be returned.

type RowValue

type RowValue []any

RowValue represents an SQL row value expression e.g. (x, y, z).

func (RowValue) Eq

func (r RowValue) Eq(v any) Predicate

Eq returns an 'rowvalue = value' Predicate.

func (RowValue) In

func (r RowValue) In(v any) Predicate

In returns an 'rowvalue IN (value)' Predicate.

func (RowValue) NotIn added in v0.3.0

func (r RowValue) NotIn(v any) Predicate

NotIn returns an 'rowvalue NOT IN (value)' Predicate.

func (RowValue) WriteSQL

func (r RowValue) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type RowValues

type RowValues []RowValue

RowValues represents a list of RowValues e.g. (x, y, z), (a, b, c).

func (RowValues) WriteSQL

func (rs RowValues) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SQLServerDeleteQuery

type SQLServerDeleteQuery DeleteQuery

SQLServerDeleteQuery represents an SQL Server DELETE query.

func (SQLServerDeleteQuery) CrossJoin

func (q SQLServerDeleteQuery) CrossJoin(table Table) SQLServerDeleteQuery

CrossJoin cross joins a new Table to the SQLServerDeleteQuery.

func (SQLServerDeleteQuery) CustomJoin

func (q SQLServerDeleteQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) SQLServerDeleteQuery

CustomJoin joins a new Table to the SQLServerDeleteQuery with a custom join operator.

func (SQLServerDeleteQuery) From

From sets the UsingTable of the SQLServerDeleteQuery.

func (SQLServerDeleteQuery) FullJoin

func (q SQLServerDeleteQuery) FullJoin(table Table, predicates ...Predicate) SQLServerDeleteQuery

FullJoin full joins a new Table to the SQLServerDeleteQuery.

func (SQLServerDeleteQuery) GetDialect

func (q SQLServerDeleteQuery) GetDialect() string

GetDialect implements the Query interface.

func (SQLServerDeleteQuery) GetFetchableFields

func (q SQLServerDeleteQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (SQLServerDeleteQuery) Join

func (q SQLServerDeleteQuery) Join(table Table, predicates ...Predicate) SQLServerDeleteQuery

Join joins a new Table to the SQLServerDeleteQuery.

func (SQLServerDeleteQuery) LeftJoin

func (q SQLServerDeleteQuery) LeftJoin(table Table, predicates ...Predicate) SQLServerDeleteQuery

LeftJoin left joins a new Table to the SQLServerDeleteQuery.

func (SQLServerDeleteQuery) SetDialect

func (q SQLServerDeleteQuery) SetDialect(dialect string) SQLServerDeleteQuery

SetDialect sets the dialect of the query.

func (SQLServerDeleteQuery) SetFetchableFields

func (q SQLServerDeleteQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (SQLServerDeleteQuery) Where

func (q SQLServerDeleteQuery) Where(predicates ...Predicate) SQLServerDeleteQuery

Where appends to the WherePredicate field of the SQLServerDeleteQuery.

func (SQLServerDeleteQuery) WriteSQL

func (q SQLServerDeleteQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SQLServerInsertQuery

type SQLServerInsertQuery InsertQuery

SQLServerInsertQuery represents an SQL Server INSERT query.

func (SQLServerInsertQuery) ColumnValues

func (q SQLServerInsertQuery) ColumnValues(colmapper func(*Column)) SQLServerInsertQuery

ColumnValues sets the ColumnMapper field of the SQLServerInsertQuery.

func (SQLServerInsertQuery) Columns

func (q SQLServerInsertQuery) Columns(fields ...Field) SQLServerInsertQuery

Columns sets the InsertColumns field of the SQLServerInsertQuery.

func (SQLServerInsertQuery) GetDialect

func (q SQLServerInsertQuery) GetDialect() string

GetDialect implements the Query interface.

func (SQLServerInsertQuery) GetFetchableFields

func (q SQLServerInsertQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (SQLServerInsertQuery) Select

Select sets the SelectQuery field of the SQLServerInsertQuery.

func (SQLServerInsertQuery) SetDialect

func (q SQLServerInsertQuery) SetDialect(dialect string) SQLServerInsertQuery

SetDialect returns the dialect of the query.

func (SQLServerInsertQuery) SetFetchableFields

func (q SQLServerInsertQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (SQLServerInsertQuery) Values

func (q SQLServerInsertQuery) Values(values ...any) SQLServerInsertQuery

Values sets the RowValues field of the SQLServerInsertQuery.

func (SQLServerInsertQuery) WriteSQL

func (q SQLServerInsertQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SQLServerSelectQuery

type SQLServerSelectQuery SelectQuery

SQLServerSelectQuery represents an SQL Server SELECT query.

func (SQLServerSelectQuery) As

func (q SQLServerSelectQuery) As(alias string, columns ...string) SQLServerSelectQuery

As returns a new SQLServerSelectQuery with the table alias (and optionally column aliases).

func (SQLServerSelectQuery) CrossJoin

func (q SQLServerSelectQuery) CrossJoin(table Table) SQLServerSelectQuery

CrossJoin cross joins a new Table to the SQLServerSelectQuery.

func (SQLServerSelectQuery) CustomJoin

func (q SQLServerSelectQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) SQLServerSelectQuery

CustomJoin joins a new Table to the SQLServerSelectQuery with a custom join operator.

func (SQLServerSelectQuery) FetchNext

FetchNext sets the FetchNextRows field in the SQLServerSelectQuery.

func (SQLServerSelectQuery) Field

func (q SQLServerSelectQuery) Field(name string) AnyField

Field returns a new field qualified by the SQLServerSelectQuery's alias.

func (SQLServerSelectQuery) From

From sets the FromTable field in the SQLServerSelectQuery.

func (SQLServerSelectQuery) FullJoin

func (q SQLServerSelectQuery) FullJoin(table Table, predicates ...Predicate) SQLServerSelectQuery

FullJoin full joins a new Table to the SQLServerSelectQuery.

func (SQLServerSelectQuery) GetAlias

func (q SQLServerSelectQuery) GetAlias() string

GetAlias returns the alias of the SQLServerSelectQuery.

func (SQLServerSelectQuery) GetDialect

func (q SQLServerSelectQuery) GetDialect() string

GetDialect implements the Query interface.

func (SQLServerSelectQuery) GetFetchableFields

func (q SQLServerSelectQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (SQLServerSelectQuery) GroupBy

func (q SQLServerSelectQuery) GroupBy(fields ...Field) SQLServerSelectQuery

GroupBy appends to the GroupByFields field in the SQLServerSelectQuery.

func (SQLServerSelectQuery) Having

func (q SQLServerSelectQuery) Having(predicates ...Predicate) SQLServerSelectQuery

Having appends to the HavingPredicate field in the SQLServerSelectQuery.

func (SQLServerSelectQuery) IsArray

func (q SQLServerSelectQuery) IsArray()

IsArray implements the Array interface.

func (SQLServerSelectQuery) IsBinary

func (q SQLServerSelectQuery) IsBinary()

IsBinary implements the Binary interface.

func (SQLServerSelectQuery) IsBoolean

func (q SQLServerSelectQuery) IsBoolean()

IsBoolean implements the Boolean interface.

func (SQLServerSelectQuery) IsEnum

func (q SQLServerSelectQuery) IsEnum()

IsEnum implements the Enum interface.

func (SQLServerSelectQuery) IsField

func (q SQLServerSelectQuery) IsField()

IsField implements the Field interface.

func (SQLServerSelectQuery) IsJSON

func (q SQLServerSelectQuery) IsJSON()

IsJSON implements the JSON interface.

func (SQLServerSelectQuery) IsNumber

func (q SQLServerSelectQuery) IsNumber()

IsNumber implements the Number interface.

func (SQLServerSelectQuery) IsString

func (q SQLServerSelectQuery) IsString()

IsString implements the String interface.

func (SQLServerSelectQuery) IsTable

func (q SQLServerSelectQuery) IsTable()

IsTable implements the Table interface.

func (SQLServerSelectQuery) IsTime

func (q SQLServerSelectQuery) IsTime()

IsTime implements the Time interface.

func (SQLServerSelectQuery) IsUUID

func (q SQLServerSelectQuery) IsUUID()

IsUUID implements the UUID interface.

func (SQLServerSelectQuery) Join

func (q SQLServerSelectQuery) Join(table Table, predicates ...Predicate) SQLServerSelectQuery

Join joins a new Table to the SQLServerSelectQuery.

func (SQLServerSelectQuery) LeftJoin

func (q SQLServerSelectQuery) LeftJoin(table Table, predicates ...Predicate) SQLServerSelectQuery

LeftJoin left joins a new Table to the SQLServerSelectQuery.

func (SQLServerSelectQuery) Offset

Offset sets the OffsetRows field in the SQLServerSelectQuery.

func (SQLServerSelectQuery) OrderBy

func (q SQLServerSelectQuery) OrderBy(fields ...Field) SQLServerSelectQuery

OrderBy appends to the OrderByFields field in the SQLServerSelectQuery.

func (SQLServerSelectQuery) Select

func (q SQLServerSelectQuery) Select(fields ...Field) SQLServerSelectQuery

Select appends to the SelectFields in the SQLServerSelectQuery.

func (SQLServerSelectQuery) SelectDistinct

func (q SQLServerSelectQuery) SelectDistinct(fields ...Field) SQLServerSelectQuery

SelectDistinct sets the SelectFields in the SQLServerSelectQuery.

func (SQLServerSelectQuery) SelectOne

func (q SQLServerSelectQuery) SelectOne(fields ...Field) SQLServerSelectQuery

SelectOne sets the SQLServerSelectQuery to SELECT 1.

func (SQLServerSelectQuery) SetDialect

func (q SQLServerSelectQuery) SetDialect(dialect string) SQLServerSelectQuery

SetDialect sets the dialect of the query.

func (SQLServerSelectQuery) SetFetchableFields

func (q SQLServerSelectQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (SQLServerSelectQuery) Top

Top sets the LimitTop field of the SQLServerSelectQuery.

func (SQLServerSelectQuery) TopPercent

func (q SQLServerSelectQuery) TopPercent(percentLimit any) SQLServerSelectQuery

Top sets the LimitTopPercent field of the SQLServerSelectQuery.

func (SQLServerSelectQuery) Where

func (q SQLServerSelectQuery) Where(predicates ...Predicate) SQLServerSelectQuery

Where appends to the WherePredicate field in the SQLServerSelectQuery.

func (SQLServerSelectQuery) WithTies

WithTies enables the FetchWithTies field in the SQLServerSelectQuery.

func (SQLServerSelectQuery) WriteSQL

func (q SQLServerSelectQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SQLServerUpdateQuery

type SQLServerUpdateQuery UpdateQuery

SQLServerUpdateQuery represents an SQL Server UPDATE query.

func (SQLServerUpdateQuery) CrossJoin

func (q SQLServerUpdateQuery) CrossJoin(table Table) SQLServerUpdateQuery

CrossJoin cross joins a new Table to the SQLServerUpdateQuery.

func (SQLServerUpdateQuery) CustomJoin

func (q SQLServerUpdateQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) SQLServerUpdateQuery

CustomJoin joins a new Table to the SQLServerUpdateQuery with a custom join operator.

func (SQLServerUpdateQuery) From

From sets the FromTable field of the SQLServerUpdateQuery.

func (SQLServerUpdateQuery) FullJoin

func (q SQLServerUpdateQuery) FullJoin(table Table, predicates ...Predicate) SQLServerUpdateQuery

FullJoin full joins a new Table to the SQLServerUpdateQuery.

func (SQLServerUpdateQuery) GetDialect

func (q SQLServerUpdateQuery) GetDialect() string

GetDialect implements the Query interface.

func (SQLServerUpdateQuery) GetFetchableFields

func (q SQLServerUpdateQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the SQLServerUpdateQuery.

func (SQLServerUpdateQuery) Join

func (q SQLServerUpdateQuery) Join(table Table, predicates ...Predicate) SQLServerUpdateQuery

Join joins a new Table to the SQLServerUpdateQuery.

func (SQLServerUpdateQuery) LeftJoin

func (q SQLServerUpdateQuery) LeftJoin(table Table, predicates ...Predicate) SQLServerUpdateQuery

LeftJoin left joins a new Table to the SQLServerUpdateQuery.

func (SQLServerUpdateQuery) Set

Set sets the Assignments field of the SQLServerUpdateQuery.

func (SQLServerUpdateQuery) SetDialect

func (q SQLServerUpdateQuery) SetDialect(dialect string) SQLServerUpdateQuery

SetDialect sets the dialect of the SQLServerUpdateQuery.

func (SQLServerUpdateQuery) SetFetchableFields

func (q SQLServerUpdateQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (SQLServerUpdateQuery) SetFunc

func (q SQLServerUpdateQuery) SetFunc(colmapper func(*Column)) SQLServerUpdateQuery

SetFunc sets the ColumnMapper of the SQLServerUpdateQuery.

func (SQLServerUpdateQuery) Where

func (q SQLServerUpdateQuery) Where(predicates ...Predicate) SQLServerUpdateQuery

Where appends to the WherePredicate field of the SQLServerUpdateQuery.

func (SQLServerUpdateQuery) WriteSQL

func (q SQLServerUpdateQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SQLWriter

type SQLWriter interface {
	// WriteSQL writes the SQL representation of the SQLWriter into the query
	// string (*bytes.Buffer) and args slice (*[]any).
	//
	// The params map is used to hold the mappings between named parameters in
	// the query to the corresponding index in the args slice and is used for
	// rebinding args by their parameter name. The params map may be nil, check
	// first before writing to it.
	WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error
}

SQLWriter is anything that can be converted to SQL.

type SQLiteDeleteQuery

type SQLiteDeleteQuery DeleteQuery

SQLiteDeleteQuery represents an SQLite DELETE query.

func (SQLiteDeleteQuery) GetDialect

func (q SQLiteDeleteQuery) GetDialect() string

GetDialect implements the Query interface.

func (SQLiteDeleteQuery) GetFetchableFields

func (q SQLiteDeleteQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (SQLiteDeleteQuery) Returning

func (q SQLiteDeleteQuery) Returning(fields ...Field) SQLiteDeleteQuery

Returning appends fields to the RETURNING clause of the SQLiteDeleteQuery.

func (SQLiteDeleteQuery) SetDialect

func (q SQLiteDeleteQuery) SetDialect(dialect string) SQLiteDeleteQuery

SetDialect sets the dialect of the query.

func (SQLiteDeleteQuery) SetFetchableFields

func (q SQLiteDeleteQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (SQLiteDeleteQuery) Where

func (q SQLiteDeleteQuery) Where(predicates ...Predicate) SQLiteDeleteQuery

Where appends to the WherePredicate field of the SQLiteDeleteQuery.

func (SQLiteDeleteQuery) WriteSQL

func (q SQLiteDeleteQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SQLiteInsertQuery

type SQLiteInsertQuery InsertQuery

SQLiteInsertQuery represents an SQLite INSERT query.

func (SQLiteInsertQuery) ColumnValues

func (q SQLiteInsertQuery) ColumnValues(colmapper func(*Column)) SQLiteInsertQuery

ColumnValues sets the ColumnMapper field of the SQLiteInsertQuery.

func (SQLiteInsertQuery) Columns

func (q SQLiteInsertQuery) Columns(fields ...Field) SQLiteInsertQuery

Columns sets the InsertColumns field of the SQLiteInsertQuery.

func (SQLiteInsertQuery) GetDialect

func (q SQLiteInsertQuery) GetDialect() string

GetDialect implements the Query interface.

func (SQLiteInsertQuery) GetFetchableFields

func (q SQLiteInsertQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (SQLiteInsertQuery) OnConflict

func (q SQLiteInsertQuery) OnConflict(fields ...Field) sqliteInsertConflict

OnConflict starts the ON CONFLICT clause of the SQLiteInsertQuery.

func (SQLiteInsertQuery) Returning

func (q SQLiteInsertQuery) Returning(fields ...Field) SQLiteInsertQuery

Returning adds fields to the RETURNING clause of the SQLiteInsertQuery.

func (SQLiteInsertQuery) Select

func (q SQLiteInsertQuery) Select(query Query) SQLiteInsertQuery

Select sets the SelectQuery field of the SQLiteInsertQuery.

func (SQLiteInsertQuery) SetDialect

func (q SQLiteInsertQuery) SetDialect(dialect string) SQLiteInsertQuery

SetDialect returns the dialect of the query.

func (SQLiteInsertQuery) SetFetchableFields

func (q SQLiteInsertQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (SQLiteInsertQuery) Values

func (q SQLiteInsertQuery) Values(values ...any) SQLiteInsertQuery

Values sets the RowValues field of the SQLiteInsertQuery.

func (SQLiteInsertQuery) Where

func (q SQLiteInsertQuery) Where(predicates ...Predicate) SQLiteInsertQuery

Where adds predicates to the DO UPDATE SET clause of the SQLiteInsertQuery.

func (SQLiteInsertQuery) WriteSQL

func (q SQLiteInsertQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SQLiteSelectQuery

type SQLiteSelectQuery SelectQuery

SQLiteSelectQuery represents an SQLite SELECT query.

func (SQLiteSelectQuery) As

func (q SQLiteSelectQuery) As(alias string, columns ...string) SQLiteSelectQuery

As returns a new SQLiteSelectQuery with the table alias (and optionally column aliases).

func (SQLiteSelectQuery) CrossJoin

func (q SQLiteSelectQuery) CrossJoin(table Table) SQLiteSelectQuery

CrossJoin cross joins a new Table to the SQLiteSelectQuery.

func (SQLiteSelectQuery) CustomJoin

func (q SQLiteSelectQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) SQLiteSelectQuery

CustomJoin joins a new Table to the SQLiteSelectQuery with a custom join operator.

func (SQLiteSelectQuery) Field

func (q SQLiteSelectQuery) Field(name string) AnyField

Field returns a new field qualified by the SQLiteSelectQuery's alias.

func (SQLiteSelectQuery) From

From sets the FromTable field in the SQLiteSelectQuery.

func (SQLiteSelectQuery) GetAlias

func (q SQLiteSelectQuery) GetAlias() string

GetAlias returns the alias of the SQLiteSelectQuery.

func (SQLiteSelectQuery) GetDialect

func (q SQLiteSelectQuery) GetDialect() string

GetDialect implements the Query interface.

func (SQLiteSelectQuery) GetFetchableFields

func (q SQLiteSelectQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (SQLiteSelectQuery) GroupBy

func (q SQLiteSelectQuery) GroupBy(fields ...Field) SQLiteSelectQuery

GroupBy appends to the GroupByFields field in the SQLiteSelectQuery.

func (SQLiteSelectQuery) Having

func (q SQLiteSelectQuery) Having(predicates ...Predicate) SQLiteSelectQuery

Having appends to the HavingPredicate field in the SQLiteSelectQuery.

func (SQLiteSelectQuery) IsArray

func (q SQLiteSelectQuery) IsArray()

IsArray implements the Array interface.

func (SQLiteSelectQuery) IsBinary

func (q SQLiteSelectQuery) IsBinary()

IsBinary implements the Binary interface.

func (SQLiteSelectQuery) IsBoolean

func (q SQLiteSelectQuery) IsBoolean()

IsBoolean implements the Boolean interface.

func (SQLiteSelectQuery) IsEnum

func (q SQLiteSelectQuery) IsEnum()

IsEnum implements the Enum interface.

func (SQLiteSelectQuery) IsField

func (q SQLiteSelectQuery) IsField()

IsField implements the Field interface.

func (SQLiteSelectQuery) IsJSON

func (q SQLiteSelectQuery) IsJSON()

IsJSON implements the JSON interface.

func (SQLiteSelectQuery) IsNumber

func (q SQLiteSelectQuery) IsNumber()

IsNumber implements the Number interface.

func (SQLiteSelectQuery) IsString

func (q SQLiteSelectQuery) IsString()

IsString implements the String interface.

func (SQLiteSelectQuery) IsTable

func (q SQLiteSelectQuery) IsTable()

IsTable implements the Table interface.

func (SQLiteSelectQuery) IsTime

func (q SQLiteSelectQuery) IsTime()

IsTime implements the Time interface.

func (SQLiteSelectQuery) IsUUID

func (q SQLiteSelectQuery) IsUUID()

IsUUID implements the UUID interface.

func (SQLiteSelectQuery) Join

func (q SQLiteSelectQuery) Join(table Table, predicates ...Predicate) SQLiteSelectQuery

Join joins a new Table to the SQLiteSelectQuery.

func (SQLiteSelectQuery) JoinUsing

func (q SQLiteSelectQuery) JoinUsing(table Table, fields ...Field) SQLiteSelectQuery

JoinUsing joins a new Table to the SQLiteSelectQuery with the USING operator.

func (SQLiteSelectQuery) LeftJoin

func (q SQLiteSelectQuery) LeftJoin(table Table, predicates ...Predicate) SQLiteSelectQuery

LeftJoin left joins a new Table to the SQLiteSelectQuery.

func (SQLiteSelectQuery) Limit

func (q SQLiteSelectQuery) Limit(limit any) SQLiteSelectQuery

Limit sets the LimitRows field in the SQLiteSelectQuery.

func (SQLiteSelectQuery) Offset

func (q SQLiteSelectQuery) Offset(offset any) SQLiteSelectQuery

Offset sets the OffsetRows field in the SQLiteSelectQuery.

func (SQLiteSelectQuery) OrderBy

func (q SQLiteSelectQuery) OrderBy(fields ...Field) SQLiteSelectQuery

OrderBy appends to the OrderByFields field in the SQLiteSelectQuery.

func (SQLiteSelectQuery) Select

func (q SQLiteSelectQuery) Select(fields ...Field) SQLiteSelectQuery

Select appends to the SelectFields in the SQLiteSelectQuery.

func (SQLiteSelectQuery) SelectDistinct

func (q SQLiteSelectQuery) SelectDistinct(fields ...Field) SQLiteSelectQuery

SelectDistinct sets the SelectFields in the SQLiteSelectQuery.

func (SQLiteSelectQuery) SelectOne

func (q SQLiteSelectQuery) SelectOne(fields ...Field) SQLiteSelectQuery

SelectOne sets the SQLiteSelectQuery to SELECT 1.

func (SQLiteSelectQuery) SetDialect

func (q SQLiteSelectQuery) SetDialect(dialect string) SQLiteSelectQuery

SetDialect sets the dialect of the query.

func (SQLiteSelectQuery) SetFetchableFields

func (q SQLiteSelectQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (SQLiteSelectQuery) Where

func (q SQLiteSelectQuery) Where(predicates ...Predicate) SQLiteSelectQuery

Where appends to the WherePredicate field in the SQLiteSelectQuery.

func (SQLiteSelectQuery) WriteSQL

func (q SQLiteSelectQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SQLiteUpdateQuery

type SQLiteUpdateQuery UpdateQuery

SQLiteUpdateQuery represents an SQLite UPDATE query.

func (SQLiteUpdateQuery) CrossJoin

func (q SQLiteUpdateQuery) CrossJoin(table Table) SQLiteUpdateQuery

CrossJoin cross joins a new Table to the SQLiteUpdateQuery.

func (SQLiteUpdateQuery) CustomJoin

func (q SQLiteUpdateQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) SQLiteUpdateQuery

CustomJoin joins a new Table to the SQLiteUpdateQuery with a custom join operator.

func (SQLiteUpdateQuery) From

From sets the FromTable field of the SQLiteUpdateQuery.

func (SQLiteUpdateQuery) GetDialect

func (q SQLiteUpdateQuery) GetDialect() string

GetDialect implements the Query interface.

func (SQLiteUpdateQuery) GetFetchableFields

func (q SQLiteUpdateQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the SQLiteUpdateQuery.

func (SQLiteUpdateQuery) Join

func (q SQLiteUpdateQuery) Join(table Table, predicates ...Predicate) SQLiteUpdateQuery

Join joins a new Table to the SQLiteUpdateQuery.

func (SQLiteUpdateQuery) JoinUsing

func (q SQLiteUpdateQuery) JoinUsing(table Table, fields ...Field) SQLiteUpdateQuery

JoinUsing joins a new Table to the SQLiteUpdateQuery with the USING operator.

func (SQLiteUpdateQuery) LeftJoin

func (q SQLiteUpdateQuery) LeftJoin(table Table, predicates ...Predicate) SQLiteUpdateQuery

LeftJoin left joins a new Table to the SQLiteUpdateQuery.

func (SQLiteUpdateQuery) Returning

func (q SQLiteUpdateQuery) Returning(fields ...Field) SQLiteUpdateQuery

Returning sets the ReturningFields field of the SQLiteUpdateQuery.

func (SQLiteUpdateQuery) Set

func (q SQLiteUpdateQuery) Set(assignments ...Assignment) SQLiteUpdateQuery

Set sets the Assignments field of the SQLiteUpdateQuery.

func (SQLiteUpdateQuery) SetDialect

func (q SQLiteUpdateQuery) SetDialect(dialect string) SQLiteUpdateQuery

SetDialect sets the dialect of the SQLiteUpdateQuery.

func (SQLiteUpdateQuery) SetFetchableFields

func (q SQLiteUpdateQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (SQLiteUpdateQuery) SetFunc

func (q SQLiteUpdateQuery) SetFunc(colmapper func(*Column)) SQLiteUpdateQuery

SetFunc sets the ColumnMapper of the SQLiteUpdateQuery.

func (SQLiteUpdateQuery) Where

func (q SQLiteUpdateQuery) Where(predicates ...Predicate) SQLiteUpdateQuery

Where appends to the WherePredicate field of the SQLiteUpdateQuery.

func (SQLiteUpdateQuery) WriteSQL

func (q SQLiteUpdateQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SelectQuery

type SelectQuery struct {
	Dialect string
	// WITH
	CTEs []CTE
	// SELECT
	Distinct         bool
	SelectFields     []Field
	DistinctOnFields []Field
	// TOP
	LimitTop        any
	LimitTopPercent any
	// FROM
	FromTable Table
	// JOIN
	JoinTables []JoinTable
	// WHERE
	WherePredicate Predicate
	// GROUP BY
	GroupByFields []Field
	// HAVING
	HavingPredicate Predicate
	// WINDOW
	NamedWindows []NamedWindow
	// ORDER BY
	OrderByFields []Field
	// LIMIT
	LimitRows any
	// OFFSET
	OffsetRows any
	// FETCH NEXT
	FetchNextRows any
	FetchWithTies bool
	// FOR UPDATE | FOR SHARE
	LockClause string
	LockValues []any
	// AS
	Alias   string
	Columns []string
}

SelectQuery represents an SQL SELECT query.

func From

func From(table Table) SelectQuery

From creates a new SelectQuery.

func Select

func Select(fields ...Field) SelectQuery

Select creates a new SelectQuery.

func SelectDistinct

func SelectDistinct(fields ...Field) SelectQuery

SelectDistinct creates a new SelectQuery.

func SelectOne

func SelectOne() SelectQuery

SelectOne creates a new SelectQuery.

func (SelectQuery) As

func (q SelectQuery) As(alias string, columns ...string) SelectQuery

As returns a new SelectQuery with the table alias (and optionally column aliases).

func (SelectQuery) CrossJoin

func (q SelectQuery) CrossJoin(table Table) SelectQuery

CrossJoin cross joins a new Table to the SelectQuery.

func (SelectQuery) CustomJoin

func (q SelectQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) SelectQuery

CustomJoin joins a new Table to the SelectQuery with a custom join operator.

func (SelectQuery) Field

func (q SelectQuery) Field(name string) AnyField

Field returns a new field qualified by the SelectQuery's alias.

func (SelectQuery) From

func (q SelectQuery) From(table Table) SelectQuery

From sets the FromTable field in the SelectQuery.

func (SelectQuery) GetAlias

func (q SelectQuery) GetAlias() string

GetAlias returns the alias of the SelectQuery.

func (SelectQuery) GetColumns

func (q SelectQuery) GetColumns() []string

GetColumns returns the column aliases of the SelectQuery.

func (SelectQuery) GetDialect

func (q SelectQuery) GetDialect() string

GetDialect implements the Query interface.

func (SelectQuery) GetFetchableFields

func (q SelectQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (SelectQuery) GroupBy

func (q SelectQuery) GroupBy(fields ...Field) SelectQuery

GroupBy appends to the GroupByFields field in the SelectQuery.

func (SelectQuery) Having

func (q SelectQuery) Having(predicates ...Predicate) SelectQuery

Having appends to the HavingPredicate field in the SelectQuery.

func (SelectQuery) IsArray

func (q SelectQuery) IsArray()

IsArray implements the Array interface.

func (SelectQuery) IsBinary

func (q SelectQuery) IsBinary()

IsBinary implements the Binary interface.

func (SelectQuery) IsBoolean

func (q SelectQuery) IsBoolean()

IsBoolean implements the Boolean interface.

func (SelectQuery) IsEnum

func (q SelectQuery) IsEnum()

IsEnum implements the Enum interface.

func (SelectQuery) IsField

func (q SelectQuery) IsField()

IsField implements the Field interface.

func (SelectQuery) IsJSON

func (q SelectQuery) IsJSON()

IsJSON implements the JSON interface.

func (SelectQuery) IsNumber

func (q SelectQuery) IsNumber()

IsNumber implements the Number interface.

func (SelectQuery) IsString

func (q SelectQuery) IsString()

IsString implements the String interface.

func (SelectQuery) IsTable

func (q SelectQuery) IsTable()

IsTable implements the Table interface.

func (SelectQuery) IsTime

func (q SelectQuery) IsTime()

IsTime implements the Time interface.

func (SelectQuery) IsUUID

func (q SelectQuery) IsUUID()

IsUUID implements the UUID interface.

func (SelectQuery) Join

func (q SelectQuery) Join(table Table, predicates ...Predicate) SelectQuery

Join joins a new Table to the SelectQuery.

func (SelectQuery) JoinUsing

func (q SelectQuery) JoinUsing(table Table, fields ...Field) SelectQuery

JoinUsing joins a new Table to the SelectQuery with the USING operator.

func (SelectQuery) LeftJoin

func (q SelectQuery) LeftJoin(table Table, predicates ...Predicate) SelectQuery

LeftJoin left joins a new Table to the SelectQuery.

func (SelectQuery) Limit

func (q SelectQuery) Limit(limit any) SelectQuery

Limit sets the LimitRows field in the SelectQuery.

func (SelectQuery) Offset

func (q SelectQuery) Offset(offset any) SelectQuery

Offset sets the OffsetRows field in the SelectQuery.

func (SelectQuery) OrderBy

func (q SelectQuery) OrderBy(fields ...Field) SelectQuery

OrderBy appends to the OrderByFields field in the SelectQuery.

func (SelectQuery) Select

func (q SelectQuery) Select(fields ...Field) SelectQuery

Select appends to the SelectFields in the SelectQuery.

func (SelectQuery) SelectDistinct

func (q SelectQuery) SelectDistinct(fields ...Field) SelectQuery

SelectDistinct sets the SelectFields in the SelectQuery.

func (SelectQuery) SelectOne

func (q SelectQuery) SelectOne(fields ...Field) SelectQuery

SelectOne sets the SelectQuery to SELECT 1.

func (SelectQuery) SetDialect

func (q SelectQuery) SetDialect(dialect string) SelectQuery

SetDialect sets the dialect of the query.

func (SelectQuery) SetFetchableFields

func (q SelectQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (SelectQuery) Where

func (q SelectQuery) Where(predicates ...Predicate) SelectQuery

Where appends to the WherePredicate field in the SelectQuery.

func (SelectQuery) WriteSQL

func (q SelectQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SelectValues

type SelectValues struct {
	Alias     string
	Columns   []string
	RowValues [][]any
}

SelectValues represents a table literal comprised of SELECT statements UNION-ed together e.g.

(SELECT 1 AS a, 2 AS b, 3 AS c
UNION ALL
SELECT 4, 5, 6
UNION ALL
SELECT 7, 8, 9) AS tbl

func (SelectValues) Field

func (vs SelectValues) Field(name string) AnyField

Field returns a new field qualified by the SelectValues' alias.

func (SelectValues) GetAlias

func (vs SelectValues) GetAlias() string

GetAlias returns the alias of the SelectValues.

func (SelectValues) GetDialect

func (vs SelectValues) GetDialect() string

GetDialect implements the Query interface. It always returns an empty string.

func (SelectValues) IsTable

func (vs SelectValues) IsTable()

IsTable implements the Table interface.

func (SelectValues) SetFetchableFields

func (vs SelectValues) SetFetchableFields([]Field) (query Query, ok bool)

SetFetchableFields implements the Query interface. It always returns false as the second result.

func (SelectValues) WriteSQL

func (vs SelectValues) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SimpleCase

type SimpleCase struct {
	Value  any
	Result any
}

SimpleCase holds the result to be used for a given value in a SimpleCaseExpression.

type SimpleCaseExpression

type SimpleCaseExpression struct {
	Expression any
	Cases      SimpleCases
	Default    any
	// contains filtered or unexported fields
}

SimpleCaseExpression represents an SQL simple CASE expression.

func Case

func Case(expression any) SimpleCaseExpression

Case returns a new SimpleCaseExpression.

func (SimpleCaseExpression) As

As returns a new SimpleCaseExpression with the given alias.

func (SimpleCaseExpression) Else

Else sets the fallback result of the SimpleCaseExpression.

func (SimpleCaseExpression) GetAlias

func (e SimpleCaseExpression) GetAlias() string

GetAlias returns the alias of the SimpleCaseExpression.

func (SimpleCaseExpression) IsArray

func (e SimpleCaseExpression) IsArray()

IsArray implements the Array interface.

func (SimpleCaseExpression) IsBinary

func (e SimpleCaseExpression) IsBinary()

IsBinary implements the Binary interface.

func (SimpleCaseExpression) IsBoolean

func (e SimpleCaseExpression) IsBoolean()

IsBoolean implements the Boolean interface.

func (SimpleCaseExpression) IsEnum

func (e SimpleCaseExpression) IsEnum()

IsEnum implements the Enum interface.

func (SimpleCaseExpression) IsField

func (e SimpleCaseExpression) IsField()

IsField implements the Field interface.

func (SimpleCaseExpression) IsJSON

func (e SimpleCaseExpression) IsJSON()

IsJSON implements the JSON interface.

func (SimpleCaseExpression) IsNumber

func (e SimpleCaseExpression) IsNumber()

IsNumber implements the Number interface.

func (SimpleCaseExpression) IsString

func (e SimpleCaseExpression) IsString()

IsString implements the String interface.

func (SimpleCaseExpression) IsTime

func (e SimpleCaseExpression) IsTime()

IsTime implements the Time interface.

func (SimpleCaseExpression) IsUUID

func (e SimpleCaseExpression) IsUUID()

IsUUID implements the UUID interface.

func (SimpleCaseExpression) When

func (e SimpleCaseExpression) When(value any, result any) SimpleCaseExpression

When adds a new value-result pair to the SimpleCaseExpression.

func (SimpleCaseExpression) WriteSQL

func (e SimpleCaseExpression) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type SimpleCases

type SimpleCases = []SimpleCase

SimpleCases is a slice of SimpleCases.

type SqLogger

type SqLogger interface {
	// SqLogSettings should populate a LogSettings struct, which influences
	// what is added into the QueryStats.
	SqLogSettings(context.Context, *LogSettings)

	// SqLogQuery logs a query when for the given QueryStats.
	SqLogQuery(context.Context, QueryStats)
}

SqLogger represents a logger for the sq package.

func NewLogger

func NewLogger(w io.Writer, prefix string, flag int, config LoggerConfig) SqLogger

NewLogger returns a new SqLogger.

type String

type String interface {
	Field
	IsString()
}

String is a Field of string type.

type StringField

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

StringField represents an SQL string field.

func NewStringField

func NewStringField(name string, tbl TableStruct) StringField

NewStringField returns a new StringField.

func (StringField) As

func (field StringField) As(alias string) StringField

As returns a new StringField with the given alias.

func (StringField) Asc

func (field StringField) Asc() StringField

Asc returns a new StringField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (StringField) Collate

func (field StringField) Collate(collation string) StringField

Collate returns a new StringField using the given collation.

func (StringField) Desc

func (field StringField) Desc() StringField

Desc returns a new StringField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.

func (StringField) Eq

func (field StringField) Eq(value String) Predicate

Eq returns a 'field = value' Predicate.

func (StringField) EqString

func (field StringField) EqString(str string) Predicate

EqString returns a 'field = str' Predicate.

func (StringField) Ge

func (field StringField) Ge(value String) Predicate

Ge returns a 'field >= value' Predicate.

func (StringField) GeString

func (field StringField) GeString(str string) Predicate

GeString returns a 'field >= str' Predicate.

func (StringField) GetAlias

func (field StringField) GetAlias() string

GetAlias returns the alias of the StringField.

func (StringField) Gt

func (field StringField) Gt(value String) Predicate

Gt returns a 'field > value' Predicate.

func (StringField) GtString

func (field StringField) GtString(str string) Predicate

GtString returns a 'field > str' Predicate.

func (StringField) ILikeString

func (field StringField) ILikeString(str string) Predicate

ILikeString returns a 'field ILIKE str' Predicate.

func (StringField) In

func (field StringField) In(value any) Predicate

In returns a 'field IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field IN (x, y, z)'.

func (StringField) IsField

func (field StringField) IsField()

IsField implements the Field interface.

func (StringField) IsNotNull

func (field StringField) IsNotNull() Predicate

IsNotNull returns a 'field IS NOT NULL' Predicate.

func (StringField) IsNull

func (field StringField) IsNull() Predicate

IsNull returns a 'field IS NULL' Predicate.

func (StringField) IsString

func (field StringField) IsString()

IsString implements the String interface.

func (StringField) Le

func (field StringField) Le(value String) Predicate

Le returns a 'field <= value' Predicate.

func (StringField) LeString

func (field StringField) LeString(str string) Predicate

LeString returns a 'field <= str' Predicate.

func (StringField) LikeString

func (field StringField) LikeString(str string) Predicate

LikeString returns a 'field LIKE str' Predicate.

func (StringField) Lt

func (field StringField) Lt(value String) Predicate

Lt returns a 'field < value' Predicate.

func (StringField) LtString

func (field StringField) LtString(str string) Predicate

LtString returns a 'field < str' Predicate.

func (StringField) Ne

func (field StringField) Ne(value String) Predicate

Ne returns a 'field <> value' Predicate.

func (StringField) NeString

func (field StringField) NeString(str string) Predicate

NeString returns a 'field <> str' Predicate.

func (StringField) NotILikeString added in v0.3.0

func (field StringField) NotILikeString(str string) Predicate

NotILikeString returns a 'field NOT ILIKE str' Predicate.

func (StringField) NotIn added in v0.3.0

func (field StringField) NotIn(value any) Predicate

In returns a 'field NOT IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field NOT IN (x, y, z)'.

func (StringField) NotLikeString added in v0.3.0

func (field StringField) NotLikeString(str string) Predicate

NotLikeString returns a 'field NOT LIKE str' Predicate.

func (StringField) NullsFirst

func (field StringField) NullsFirst() StringField

NullsFirst returns a new StringField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (StringField) NullsLast

func (field StringField) NullsLast() StringField

NullsLast returns a new StringField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

func (StringField) Set

func (field StringField) Set(value any) Assignment

Set returns an Assignment assigning the value to the field.

func (StringField) SetString

func (field StringField) SetString(str string) Assignment

SetString returns an Assignment assigning a string to the field.

func (StringField) Setf

func (field StringField) Setf(format string, values ...any) Assignment

Setf returns an Assignment assigning an expression to the field.

func (StringField) WithPrefix

func (field StringField) WithPrefix(prefix string) Field

WithPrefix returns a new Field that with the given prefix.

func (StringField) WriteSQL

func (field StringField) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type StringParameter

type StringParameter sql.NamedArg

StringParameter is identical to sql.NamedArg, but implements the String interface.

func StringParam

func StringParam(name string, s string) StringParameter

StringParam creates a new StringParameter from a string value.

func (StringParameter) IsField

func (p StringParameter) IsField()

IsField implements the Field interface.

func (StringParameter) IsString

func (p StringParameter) IsString()

IsString implements the String interface.

func (StringParameter) WriteSQL

func (p StringParameter) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Table

type Table interface {
	SQLWriter
	IsTable()
}

Table is anything you can Select from or Join.

type TableStruct

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

TableStruct is meant to be embedded in table structs to make them implement the Table interface.

func NewTableStruct

func NewTableStruct(schema, name, alias string) TableStruct

NewTableStruct creates a new TableStruct.

func (TableStruct) GetAlias

func (ts TableStruct) GetAlias() string

GetAlias returns the alias of the TableStruct.

func (TableStruct) IsTable

func (ts TableStruct) IsTable()

IsTable implements the Table interface.

func (TableStruct) WriteSQL

func (ts TableStruct) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type TableValues

type TableValues struct {
	Alias     string
	Columns   []string
	RowValues [][]any
}

TableValues represents a table literal created by the VALUES clause e.g.

(VALUES

(1, 2, 3),
(4, 5, 6),
(7, 8, 9)) AS tbl (a, b, c)

func (TableValues) Field

func (vs TableValues) Field(name string) AnyField

Field returns a new field qualified by the TableValues' alias.

func (TableValues) GetAlias

func (vs TableValues) GetAlias() string

GetAlias returns the alias of the TableValues.

func (TableValues) GetColumns

func (vs TableValues) GetColumns() []string

GetColumns returns the names of the columns in the TableValues.

func (TableValues) GetDialect

func (vs TableValues) GetDialect() string

GetDialect implements the Query interface. It always returns an empty string.

func (TableValues) IsTable

func (vs TableValues) IsTable()

IsTable implements the Table interface.

func (TableValues) SetFetchableFields

func (vs TableValues) SetFetchableFields([]Field) (query Query, ok bool)

SetFetchableFields implements the Query interface. It always returns false as the second result.

func (TableValues) WriteSQL

func (vs TableValues) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Time

type Time interface {
	Field
	IsTime()
}

Time is a Field of time type.

type TimeField

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

TimeField represents an SQL time field.

func NewTimeField

func NewTimeField(name string, tbl TableStruct) TimeField

NewTimeField returns a new TimeField.

func (TimeField) As

func (field TimeField) As(alias string) TimeField

As returns a new TimeField with the given alias.

func (TimeField) Asc

func (field TimeField) Asc() TimeField

Asc returns a new TimeField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (TimeField) Desc

func (field TimeField) Desc() TimeField

Desc returns a new TimeField indicating that it should be ordered in ascending order i.e. 'ORDER BY field DESC'.

func (TimeField) Eq

func (field TimeField) Eq(value Time) Predicate

Eq returns a 'field = value' Predicate.

func (TimeField) EqTime

func (field TimeField) EqTime(t time.Time) Predicate

EqTime returns a 'field = t' Predicate.

func (TimeField) Ge

func (field TimeField) Ge(value Time) Predicate

Ge returns a 'field >= value' Predicate.

func (TimeField) GeTime

func (field TimeField) GeTime(t time.Time) Predicate

GeTime returns a 'field >= t' Predicate.

func (TimeField) GetAlias

func (field TimeField) GetAlias() string

GetAlias returns the alias of the TimeField.

func (TimeField) Gt

func (field TimeField) Gt(value Time) Predicate

Gt returns a 'field > value' Predicate.

func (TimeField) GtTime

func (field TimeField) GtTime(t time.Time) Predicate

GtTime returns a 'field > t' Predicate.

func (TimeField) In

func (field TimeField) In(value any) Predicate

In returns a 'field IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field IN (x, y, z)'.

func (TimeField) IsField

func (field TimeField) IsField()

IsField implements the Field interface.

func (TimeField) IsNotNull

func (field TimeField) IsNotNull() Predicate

IsNotNull returns a 'field IS NOT NULL' Predicate.

func (TimeField) IsNull

func (field TimeField) IsNull() Predicate

IsNull returns a 'field IS NULL' Predicate.

func (TimeField) IsTime

func (field TimeField) IsTime()

IsTime implements the Time interface.

func (TimeField) Le

func (field TimeField) Le(value Time) Predicate

Le returns a 'field <= value' Predicate.

func (TimeField) LeTime

func (field TimeField) LeTime(t time.Time) Predicate

LeTime returns a 'field <= t' Predicate.

func (TimeField) Lt

func (field TimeField) Lt(value Time) Predicate

Lt returns a 'field < value' Predicate.

func (TimeField) LtTime

func (field TimeField) LtTime(t time.Time) Predicate

LtTime returns a 'field < t' Predicate.

func (TimeField) Ne

func (field TimeField) Ne(value Time) Predicate

Ne returns a 'field <> value' Predicate.

func (TimeField) NeTime

func (field TimeField) NeTime(t time.Time) Predicate

NeTime returns a 'field <> t' Predicate.

func (TimeField) NotIn added in v0.3.0

func (field TimeField) NotIn(value any) Predicate

NotIn returns a 'field NOT IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field NOT IN (x, y, z)'.

func (TimeField) NullsFirst

func (field TimeField) NullsFirst() TimeField

NullsFirst returns a new TimeField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (TimeField) NullsLast

func (field TimeField) NullsLast() TimeField

NullsLast returns a new TimeField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

func (TimeField) Set

func (field TimeField) Set(value any) Assignment

Set returns an Assignment assigning the value to the field.

func (TimeField) SetTime

func (field TimeField) SetTime(t time.Time) Assignment

SetTime returns an Assignment assigning a time.Time to the field.

func (TimeField) Setf

func (field TimeField) Setf(format string, values ...any) Assignment

Setf returns an Assignment assigning an expression to the field.

func (TimeField) WithPrefix

func (field TimeField) WithPrefix(prefix string) Field

WithPrefix returns a new Field that with the given prefix.

func (TimeField) WriteSQL

func (field TimeField) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type TimeParameter

type TimeParameter sql.NamedArg

TimeParameter is identical to sql.NamedArg, but implements the Time interface.

func TimeParam

func TimeParam(name string, t time.Time) TimeParameter

TimeParam creates a new TimeParameter from a time.Time value.

func (TimeParameter) IsField

func (p TimeParameter) IsField()

IsField implements the Field interface.

func (TimeParameter) IsTime

func (p TimeParameter) IsTime()

IsTime implements the Time interface.

func (TimeParameter) WriteSQL

func (p TimeParameter) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type Timestamp

type Timestamp struct {
	time.Time
	Valid bool
	// contains filtered or unexported fields
}

Timestamp is as a replacement for sql.NullTime but with the following enhancements:

1. Timestamp.Value() returns an int64 unix timestamp if the dialect is SQLite, otherwise it returns a time.Time (similar to sql.NullTime).

2. Timestamp.Scan() additionally supports scanning from int64 and text (string/[]byte) values on top of what sql.NullTime already supports. The following text timestamp formats are supported:

var timestampFormats = []string{
	"2006-01-02 15:04:05.999999999-07:00",
	"2006-01-02T15:04:05.999999999-07:00",
	"2006-01-02 15:04:05.999999999",
	"2006-01-02T15:04:05.999999999",
	"2006-01-02 15:04:05",
	"2006-01-02T15:04:05",
	"2006-01-02 15:04",
	"2006-01-02T15:04",
	"2006-01-02",
}

func NewTimestamp

func NewTimestamp(t time.Time) Timestamp

NewTimestamp creates a new Timestamp from a time.Time.

func (Timestamp) DialectValuer

func (ts Timestamp) DialectValuer(dialect string) (driver.Valuer, error)

DialectValuer implements the DialectValuer interface.

func (*Timestamp) Scan

func (ts *Timestamp) Scan(value any) error

Scan implements the sql.Scanner interface. It additionally supports scanning from int64 and text (string/[]byte) values on top of what sql.NullTime already supports. The following text timestamp formats are supported:

var timestampFormats = []string{
	"2006-01-02 15:04:05.999999999-07:00",
	"2006-01-02T15:04:05.999999999-07:00",
	"2006-01-02 15:04:05.999999999",
	"2006-01-02T15:04:05.999999999",
	"2006-01-02 15:04:05",
	"2006-01-02T15:04:05",
	"2006-01-02 15:04",
	"2006-01-02T15:04",
	"2006-01-02",
}

func (Timestamp) Value

func (ts Timestamp) Value() (driver.Value, error)

Value implements the driver.Valuer interface. It returns an int64 unix timestamp if the dialect is SQLite, otherwise it returns a time.Time (similar to sql.NullTime).

type UUID

type UUID interface {
	Field
	IsUUID()
}

UUID is a Field of uuid type.

type UUIDField

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

UUIDField represents an SQL UUID field.

func NewUUIDField

func NewUUIDField(name string, tbl TableStruct) UUIDField

NewUUIDField returns a new UUIDField.

func (UUIDField) As

func (field UUIDField) As(alias string) UUIDField

As returns a new UUIDField with the given alias.

func (UUIDField) Asc

func (field UUIDField) Asc() UUIDField

Asc returns a new UUIDField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (UUIDField) Desc

func (field UUIDField) Desc() UUIDField

Desc returns a new UUIDField indicating that it should be ordered in ascending order i.e. 'ORDER BY field DESC'.

func (UUIDField) Eq

func (field UUIDField) Eq(value any) Predicate

Eq returns a 'field = value' Predicate.

func (UUIDField) EqUUID added in v0.2.1

func (field UUIDField) EqUUID(value any) Predicate

EqUUID returns a 'field = value' Predicate. The value is wrapped in UUIDValue().

func (UUIDField) GetAlias

func (field UUIDField) GetAlias() string

GetAlias returns the alias of the UUIDField.

func (UUIDField) In

func (field UUIDField) In(value any) Predicate

In returns a 'field IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field IN (x, y, z)'.

func (UUIDField) IsField

func (field UUIDField) IsField()

IsField implements the Field interface.

func (UUIDField) IsNotNull

func (field UUIDField) IsNotNull() Predicate

IsNotNull returns a 'field IS NOT NULL' Predicate.

func (UUIDField) IsNull

func (field UUIDField) IsNull() Predicate

IsNull returns a 'field IS NULL' Predicate.

func (UUIDField) IsUUID

func (field UUIDField) IsUUID()

IsUUID implements the UUID interface.

func (UUIDField) Ne

func (field UUIDField) Ne(value any) Predicate

Ne returns a 'field <> value' Predicate.

func (UUIDField) NeUUID added in v0.2.1

func (field UUIDField) NeUUID(value any) Predicate

NeUUID returns a 'field <> value' Predicate. The value is wrapped in UUIDValue().

func (UUIDField) NotIn added in v0.3.0

func (field UUIDField) NotIn(value any) Predicate

NotIn returns a 'field NOT IN (value)' Predicate. The value can be a slice, which corresponds to the expression 'field NOT IN (x, y, z)'.

func (UUIDField) NullsFirst

func (field UUIDField) NullsFirst() UUIDField

NullsFirst returns a new UUIDField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (UUIDField) NullsLast

func (field UUIDField) NullsLast() UUIDField

NullsLast returns a new UUIDField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

func (UUIDField) Set

func (field UUIDField) Set(value any) Assignment

Set returns an Assignment assigning the value to the field.

func (UUIDField) SetUUID

func (field UUIDField) SetUUID(value any) Assignment

SetUUID returns an Assignment assigning the value to the field. It wraps the value in UUIDValue().

func (UUIDField) Setf

func (field UUIDField) Setf(format string, values ...any) Assignment

Set returns an Assignment assigning the value to the field.

func (UUIDField) WithPrefix

func (field UUIDField) WithPrefix(prefix string) Field

WithPrefix returns a new Field that with the given prefix.

func (UUIDField) WriteSQL

func (field UUIDField) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type UUIDParameter added in v0.3.5

type UUIDParameter sql.NamedArg

UUIDParameter is identical to sql.NamedArg, but implements the UUID interface.

func UUIDParam added in v0.3.5

func UUIDParam(name string, value any) UUIDParameter

UUIDParam creates a new UUIDParameter. It wraps the value with UUIDValue().

func (UUIDParameter) IsField added in v0.3.5

func (p UUIDParameter) IsField()

IsField implements the Field interface.

func (UUIDParameter) IsUUID added in v0.3.5

func (p UUIDParameter) IsUUID()

IsUUID implements the UUID interface.

func (UUIDParameter) WriteSQL added in v0.3.5

func (p UUIDParameter) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type UpdateQuery

type UpdateQuery struct {
	Dialect      string
	ColumnMapper func(*Column)
	// WITH
	CTEs []CTE
	// UPDATE
	UpdateTable Table
	// FROM
	FromTable  Table
	JoinTables []JoinTable
	// SET
	Assignments []Assignment
	// WHERE
	WherePredicate Predicate
	// ORDER BY
	OrderByFields []Field
	// LIMIT
	LimitRows any
	// RETURNING
	ReturningFields []Field
}

UpdateQuery represents an SQL UPDATE query.

func Update

func Update(table Table) UpdateQuery

Update returns a new UpdateQuery.

func (UpdateQuery) GetDialect

func (q UpdateQuery) GetDialect() string

GetDialect implements the Query interface.

func (UpdateQuery) GetFetchableFields

func (q UpdateQuery) GetFetchableFields() []Field

GetFetchableFields returns the fetchable fields of the query.

func (UpdateQuery) Set

func (q UpdateQuery) Set(assignments ...Assignment) UpdateQuery

Set sets the Assignments field of the UpdateQuery.

func (UpdateQuery) SetDialect

func (q UpdateQuery) SetDialect(dialect string) UpdateQuery

SetDialect sets the dialect of the query.

func (UpdateQuery) SetFetchableFields

func (q UpdateQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (UpdateQuery) SetFunc

func (q UpdateQuery) SetFunc(colmapper func(*Column)) UpdateQuery

SetFunc sets the ColumnMapper field of the UpdateQuery.

func (UpdateQuery) Where

func (q UpdateQuery) Where(predicates ...Predicate) UpdateQuery

Where appends to the WherePredicate field of the UpdateQuery.

func (UpdateQuery) WriteSQL

func (q UpdateQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) (err error)

WriteSQL implements the SQLWriter interface.

type ValueExpression

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

ValueExpression represents an SQL value that is passed in as an argument to a prepared query.

func Value

func Value(value any) ValueExpression

Value returns a new ValueExpression.

func (ValueExpression) As

As returns a new ValueExpression with the given alias.

func (ValueExpression) Eq

func (e ValueExpression) Eq(val any) Predicate

Eq returns a 'expr = val' Predicate.

func (ValueExpression) Ge

func (e ValueExpression) Ge(val any) Predicate

Ge returns a 'expr >= val' Predicate.

func (ValueExpression) GetAlias

func (e ValueExpression) GetAlias() string

GetAlias returns the alias of the ValueExpression.

func (ValueExpression) Gt

func (e ValueExpression) Gt(val any) Predicate

Gt returns a 'expr > val' Predicate.

func (ValueExpression) In

func (e ValueExpression) In(val any) Predicate

In returns a 'expr IN (val)' Predicate.

func (ValueExpression) IsArray

func (e ValueExpression) IsArray()

IsArray implements the Array interface.

func (ValueExpression) IsBinary

func (e ValueExpression) IsBinary()

IsBinary implements the Binary interface.

func (ValueExpression) IsBoolean

func (e ValueExpression) IsBoolean()

IsBoolean implements the Boolean interface.

func (ValueExpression) IsEnum

func (e ValueExpression) IsEnum()

IsEnum implements the Enum interface.

func (ValueExpression) IsField

func (e ValueExpression) IsField()

IsField implements the Field interface.

func (ValueExpression) IsJSON

func (e ValueExpression) IsJSON()

IsJSON implements the JSON interface.

func (ValueExpression) IsNumber

func (e ValueExpression) IsNumber()

IsNumber implements the Number interface.

func (ValueExpression) IsString

func (e ValueExpression) IsString()

IsString implements the String interface.

func (ValueExpression) IsTime

func (e ValueExpression) IsTime()

IsTime implements the Time interfaces.

func (ValueExpression) IsUUID

func (e ValueExpression) IsUUID()

IsUUID implements the UUID interface.

func (ValueExpression) Le

func (e ValueExpression) Le(val any) Predicate

Le returns a 'expr <= val' Predicate.

func (ValueExpression) Lt

func (e ValueExpression) Lt(val any) Predicate

Lt returns a 'expr < val' Predicate.

func (ValueExpression) Ne

func (e ValueExpression) Ne(val any) Predicate

Ne returns a 'expr <> val' Predicate.

func (ValueExpression) WriteSQL

func (e ValueExpression) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type VariadicPredicate

type VariadicPredicate struct {
	// Toplevel indicates if the VariadicPredicate can skip writing the
	// (surrounding brackets).
	Toplevel bool

	// If IsDisjunction is true, the Predicates are joined using OR. If false,
	// the Predicates are joined using AND. The default is AND.
	IsDisjunction bool
	// Predicates holds the predicates inside the VariadicPredicate
	Predicates []Predicate
	// contains filtered or unexported fields
}

VariadicPredicate represents the 'x AND y AND z...' or 'x OR Y OR z...' SQL construct.

func And

func And(predicates ...Predicate) VariadicPredicate

And joins the predicates together with the AND operator.

func Or

func Or(predicates ...Predicate) VariadicPredicate

Or joins the predicates together with the OR operator.

func (VariadicPredicate) As

As returns a new VariadicPredicate with the given alias.

func (VariadicPredicate) GetAlias

func (p VariadicPredicate) GetAlias() string

GetAlias returns the alias of the VariadicPredicate.

func (VariadicPredicate) IsBoolean

func (p VariadicPredicate) IsBoolean()

IsBooleanType implements the Predicate interface.

func (VariadicPredicate) IsField

func (p VariadicPredicate) IsField()

IsField implements the Field interface.

func (VariadicPredicate) WriteSQL

func (p VariadicPredicate) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type VariadicQuery

type VariadicQuery struct {
	Toplevel bool
	Operator VariadicQueryOperator
	Queries  []Query
}

VariadicQuery represents the 'x UNION y UNION z...' etc SQL constructs.

func Except

func Except(queries ...Query) VariadicQuery

Except joins the queries together with the EXCEPT operator.

func ExceptAll

func ExceptAll(queries ...Query) VariadicQuery

ExceptAll joins the queries together with the EXCEPT ALL operator.

func Intersect

func Intersect(queries ...Query) VariadicQuery

Intersect joins the queries together with the INTERSECT operator.

func IntersectAll

func IntersectAll(queries ...Query) VariadicQuery

IntersectAll joins the queries together with the INTERSECT ALL operator.

func Union

func Union(queries ...Query) VariadicQuery

Union joins the queries together with the UNION operator.

func UnionAll

func UnionAll(queries ...Query) VariadicQuery

UnionAll joins the queries together with the UNION ALL operator.

func (VariadicQuery) GetDialect

func (q VariadicQuery) GetDialect() string

GetDialect returns the SQL dialect of the VariadicQuery.

func (VariadicQuery) GetFetchableFields

func (q VariadicQuery) GetFetchableFields() []Field

GetFetchableFields implements the Query interface.

func (VariadicQuery) SetFetchableFields

func (q VariadicQuery) SetFetchableFields(fields []Field) (query Query, ok bool)

SetFetchableFields implements the Query interface.

func (VariadicQuery) WriteSQL

func (q VariadicQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

type VariadicQueryOperator

type VariadicQueryOperator string

VariadicQueryOperator represents a variadic query operator.

const (
	QueryUnion        VariadicQueryOperator = "UNION"
	QueryUnionAll     VariadicQueryOperator = "UNION ALL"
	QueryIntersect    VariadicQueryOperator = "INTERSECT"
	QueryIntersectAll VariadicQueryOperator = "INTERSECT ALL"
	QueryExcept       VariadicQueryOperator = "EXCEPT"
	QueryExceptAll    VariadicQueryOperator = "EXCEPT ALL"
)

VariadicQuery operators.

type ViewStruct

type ViewStruct = TableStruct

ViewStruct is just an alias for TableStruct.

type Window

type Window interface {
	SQLWriter
	IsWindow()
}

Window is a window used in SQL window functions.

type WindowDefinition

type WindowDefinition struct {
	BaseWindowName    string
	PartitionByFields []Field
	OrderByFields     []Field
	FrameSpec         string
	FrameValues       []any
}

WindowDefinition represents an SQL window definition.

func BaseWindow

func BaseWindow(w NamedWindow) WindowDefinition

BaseWindow creates a new WindowDefinition based off an existing NamedWindow.

func OrderBy

func OrderBy(fields ...Field) WindowDefinition

PartitionBy returns a new WindowDefinition with the ORDER BY clause.

func PartitionBy

func PartitionBy(fields ...Field) WindowDefinition

PartitionBy returns a new WindowDefinition with the PARTITION BY clause.

func (WindowDefinition) Frame

func (w WindowDefinition) Frame(frameSpec string, frameValues ...any) WindowDefinition

Frame returns a new WindowDefinition with the frame specification set.

func (WindowDefinition) IsWindow

func (w WindowDefinition) IsWindow()

IsWindow implements the Window interface.

func (WindowDefinition) OrderBy

func (w WindowDefinition) OrderBy(fields ...Field) WindowDefinition

OrderBy returns a new WindowDefinition with the ORDER BY clause.

func (WindowDefinition) PartitionBy

func (w WindowDefinition) PartitionBy(fields ...Field) WindowDefinition

PartitionBy returns a new WindowDefinition with the PARTITION BY clause.

func (WindowDefinition) WriteSQL

func (w WindowDefinition) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error

WriteSQL implements the SQLWriter interface.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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