query

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: AGPL-3.0 Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder handles SQL query building.

func NewBuilder

func NewBuilder(q *Query) *Builder

NewBuilder creates a new Builder instance.

func (*Builder) BuildDelete

func (b *Builder) BuildDelete() (string, []any)

BuildDelete builds a DELETE query from the query state.

func (*Builder) BuildInsert

func (b *Builder) BuildInsert(value any) (string, []any)

BuildInsert builds an INSERT query from the query state.

func (*Builder) BuildSelect

func (b *Builder) BuildSelect() (string, []any)

BuildSelect builds a SELECT query from the query state.

func (*Builder) BuildUpdate

func (b *Builder) BuildUpdate(column any, values ...any) (string, []any)

BuildUpdate builds an UPDATE query from the query state.

type Clause

type Clause interface {
	Type() ClauseType
	ToSQL() (string, []any)
}

Clause represents a query clause.

type ClauseType

type ClauseType int

ClauseType represents the type of a query clause.

const (
	WhereClause ClauseType = iota
	SelectClause
	JoinClause
	GroupClause
	HavingClause
	OrderClause
	LimitClause
	OffsetClause
)

type JoinClauseBuilder

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

JoinClauseBuilder builds JOIN clauses.

func (*JoinClauseBuilder) ToSQL

func (j *JoinClauseBuilder) ToSQL() (string, []any)

func (*JoinClauseBuilder) Type

func (j *JoinClauseBuilder) Type() ClauseType

type LimitClauseBuilder

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

LimitClauseBuilder builds LIMIT clauses.

func (*LimitClauseBuilder) ToSQL

func (l *LimitClauseBuilder) ToSQL() (string, []any)

func (*LimitClauseBuilder) Type

func (l *LimitClauseBuilder) Type() ClauseType

type OffsetClauseBuilder

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

OffsetClauseBuilder builds OFFSET clauses.

func (*OffsetClauseBuilder) ToSQL

func (o *OffsetClauseBuilder) ToSQL() (string, []any)

func (*OffsetClauseBuilder) Type

func (o *OffsetClauseBuilder) Type() ClauseType

type OrderClauseBuilder

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

OrderClauseBuilder builds ORDER BY clauses.

func (*OrderClauseBuilder) ToSQL

func (o *OrderClauseBuilder) ToSQL() (string, []any)

func (*OrderClauseBuilder) Type

func (o *OrderClauseBuilder) Type() ClauseType

type Query

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

Query implements the Query interface using native database/sql.

func NewQuery

func NewQuery(ctx context.Context, db *sql.DB, drv driver.Driver, connection string, dbConfig *db.DBConfig, log log.Log) *Query

NewQuery creates a new Query instance.

func (*Query) AfterCommit

func (q *Query) AfterCommit(callback func() error)

func (*Query) AfterRollback

func (q *Query) AfterRollback(callback func() error)

func (*Query) Association

func (q *Query) Association(assocName string) contractsorm.Association

func (*Query) Avg

func (q *Query) Avg(column string, dest any) error

func (*Query) BeforeCommit

func (q *Query) BeforeCommit(callback func() error)

Transaction callback methods (stubs for now)

func (*Query) BeforeRollback

func (q *Query) BeforeRollback(callback func() error)

func (*Query) Begin

func (q *Query) Begin(opts ...*sql.TxOptions) (contractsorm.Query, error)

func (*Query) Chunk

func (q *Query) Chunk(size int, callback any) error

func (*Query) Commit

func (q *Query) Commit() error

func (*Query) Connection

func (q *Query) Connection(name string) contractsorm.Query

Connection returns a new Query instance with the specified connection.

func (*Query) Count

func (q *Query) Count(count *int64) error

func (*Query) Create

func (q *Query) Create(value any) error

Create inserts a new record into the database.

func (*Query) CrossJoin

func (q *Query) CrossJoin(query string, args ...any) contractsorm.Query

func (*Query) Cursor

func (q *Query) Cursor() (chan contractsorm.Cursor, error)

func (*Query) DB

func (q *Query) DB() (*sql.DB, error)

DB returns the underlying database connection.

func (*Query) Decrement

func (q *Query) Decrement(column string, amount ...any) (*contractsorm.Result, error)

func (*Query) Delete

func (q *Query) Delete(value ...any) (*contractsorm.Result, error)

Delete deletes records from the database.

func (*Query) DisableQueryLog

func (q *Query) DisableQueryLog()

DisableQueryLog disables query logging.

func (*Query) Distinct

func (q *Query) Distinct(args ...any) contractsorm.Query

Distinct adds distinct to the query.

func (*Query) Driver

func (q *Query) Driver() database.Driver

Driver returns the database driver.

func (*Query) EnableQueryLog

func (q *Query) EnableQueryLog()

EnableQueryLog enables query logging.

func (*Query) Exec

func (q *Query) Exec(sql string, values ...any) (*contractsorm.Result, error)

func (*Query) Exists

func (q *Query) Exists(exists *bool) error

func (*Query) Find

func (q *Query) Find(dest any, conds ...any) error

Find retrieves records matching the given conditions.

func (*Query) FindOrFail

func (q *Query) FindOrFail(dest any, conds ...any) error

FindOrFail retrieves records matching the given conditions or returns an error if not found.

func (*Query) First

func (q *Query) First(dest any) error

First retrieves the first record matching the query.

func (*Query) FirstOr

func (q *Query) FirstOr(dest any, callback func() error) error

func (*Query) FirstOrCreate

func (q *Query) FirstOrCreate(dest any, conds ...any) error

func (*Query) FirstOrFail

func (q *Query) FirstOrFail(dest any) error

FirstOrFail retrieves the first record or returns an error if not found.

func (*Query) FirstOrNew

func (q *Query) FirstOrNew(dest any, attributes any, values ...any) error

func (*Query) FlushQueryLog

func (q *Query) FlushQueryLog()

FlushQueryLog clears the query log.

func (*Query) ForceDelete

func (q *Query) ForceDelete(value ...any) (*contractsorm.Result, error)

func (*Query) Get

func (q *Query) Get(dest any) error

Get retrieves all records matching the query.

func (*Query) GetQueryLog

func (q *Query) GetQueryLog() []contractsorm.QueryLog

GetQueryLog returns the query log.

func (*Query) Group

func (q *Query) Group(name string) contractsorm.Query

func (*Query) Having

func (q *Query) Having(query any, args ...any) contractsorm.Query

func (*Query) InRandomOrder

func (q *Query) InRandomOrder() contractsorm.Query

func (*Query) InTransaction

func (q *Query) InTransaction() bool

InTransaction returns true if the query is in a transaction.

func (*Query) Increment

func (q *Query) Increment(column string, amount ...any) (*contractsorm.Result, error)

func (*Query) InsertGetId

func (q *Query) InsertGetId(values any) (uint, error)

InsertGetId inserts a record and returns the ID.

func (*Query) Join

func (q *Query) Join(query string, args ...any) contractsorm.Query

func (*Query) LeftJoin

func (q *Query) LeftJoin(query string, args ...any) contractsorm.Query

func (*Query) Limit

func (q *Query) Limit(limit int) contractsorm.Query

Limit adds a limit clause to the query.

func (*Query) Load

func (q *Query) Load(dest any, relation string, args ...any) error

func (*Query) LoadMissing

func (q *Query) LoadMissing(dest any, relation string, args ...any) error

func (*Query) LockForUpdate

func (q *Query) LockForUpdate() contractsorm.Query

func (*Query) Max

func (q *Query) Max(column string, dest any) error

func (*Query) Min

func (q *Query) Min(column string, dest any) error

func (*Query) Model

func (q *Query) Model(value any) contractsorm.Query

Model sets the model for the query.

func (*Query) Observe

func (q *Query) Observe(model any, observer contractsorm.Observer)

Observe registers an observer for the given model.

func (*Query) Offset

func (q *Query) Offset(offset int) contractsorm.Query

Offset adds an offset clause to the query.

func (*Query) Omit

func (q *Query) Omit(columns ...string) contractsorm.Query

func (*Query) OnlyTrashed

func (q *Query) OnlyTrashed() contractsorm.Query

func (*Query) OrWhere

func (q *Query) OrWhere(query any, args ...any) contractsorm.Query

OrWhere adds an or where clause to the query.

func (*Query) OrWhereBetween

func (q *Query) OrWhereBetween(column string, x, y any) contractsorm.Query

func (*Query) OrWhereColumn

func (q *Query) OrWhereColumn(first, operator, second string) contractsorm.Query

func (*Query) OrWhereIn

func (q *Query) OrWhereIn(column string, values []any) contractsorm.Query

func (*Query) OrWhereJsonContains

func (q *Query) OrWhereJsonContains(column string, value any) contractsorm.Query

func (*Query) OrWhereJsonContainsKey

func (q *Query) OrWhereJsonContainsKey(column string) contractsorm.Query

func (*Query) OrWhereJsonDoesntContain

func (q *Query) OrWhereJsonDoesntContain(column string, value any) contractsorm.Query

func (*Query) OrWhereJsonDoesntContainKey

func (q *Query) OrWhereJsonDoesntContainKey(column string) contractsorm.Query

func (*Query) OrWhereNot

func (q *Query) OrWhereNot(query any, args ...any) contractsorm.Query

func (*Query) OrWhereNotBetween

func (q *Query) OrWhereNotBetween(column string, x, y any) contractsorm.Query

func (*Query) OrWhereNotIn

func (q *Query) OrWhereNotIn(column string, values []any) contractsorm.Query

func (*Query) OrWhereNull

func (q *Query) OrWhereNull(column string) contractsorm.Query

func (*Query) Order

func (q *Query) Order(value any) contractsorm.Query

Order adds an order by clause to the query.

func (*Query) OrderBy

func (q *Query) OrderBy(column string, direction ...string) contractsorm.Query

OrderBy adds an order by clause with direction.

func (*Query) OrderByDesc

func (q *Query) OrderByDesc(column string) contractsorm.Query

OrderByDesc adds an order by clause with desc direction.

func (*Query) Paginate

func (q *Query) Paginate(page, limit int, dest any, total *int64) error

func (*Query) Pluck

func (q *Query) Pluck(column string, dest any) error

func (*Query) Raw

func (q *Query) Raw(sql string, values ...any) contractsorm.Query

func (*Query) Restore

func (q *Query) Restore(model ...any) (*contractsorm.Result, error)

func (*Query) RightJoin

func (q *Query) RightJoin(query string, args ...any) contractsorm.Query

func (*Query) Rollback

func (q *Query) Rollback() error

func (*Query) RollbackTo

func (q *Query) RollbackTo(level string) error

func (*Query) Save

func (q *Query) Save(value any) error

Save saves the model to the database.

func (*Query) SavePoint

func (q *Query) SavePoint(name string) error

func (*Query) SaveQuietly

func (q *Query) SaveQuietly(value any) error

SaveQuietly saves the model without firing events.

func (*Query) Scan

func (q *Query) Scan(dest any) error

func (*Query) Scopes

func (q *Query) Scopes(scopes ...func(contractsorm.Query) contractsorm.Query) contractsorm.Query

func (*Query) Select

func (q *Query) Select(query any, args ...any) contractsorm.Query

Select adds columns to the select clause.

func (*Query) SharedLock

func (q *Query) SharedLock() contractsorm.Query

func (*Query) Sum

func (q *Query) Sum(column string, dest any) error

func (*Query) Table

func (q *Query) Table(name string, args ...any) contractsorm.Query

Table sets the table for the query.

func (*Query) ToRawSql

func (q *Query) ToRawSql() contractsorm.ToSql

ToRawSql returns the raw SQL with placeholders.

func (*Query) ToSql

func (q *Query) ToSql() contractsorm.ToSql

ToSql returns a ToSql instance for generating SQL without execution.

func (*Query) Transaction

func (q *Query) Transaction(txFunc func(tx contractsorm.Query) error, opts ...*sql.TxOptions) error

Transaction runs a callback wrapped in a database transaction.

func (*Query) Update

func (q *Query) Update(column any, value ...any) (*contractsorm.Result, error)

Update updates records in the database.

func (*Query) UpdateOrCreate

func (q *Query) UpdateOrCreate(dest any, attributes any, values any) error

func (*Query) UpdateOrInsert

func (q *Query) UpdateOrInsert(attributes any, values any) error

func (*Query) Value

func (q *Query) Value(column string, dest any) error

func (*Query) Where

func (q *Query) Where(query any, args ...any) contractsorm.Query

Where adds a where clause to the query.

func (*Query) WhereAll

func (q *Query) WhereAll(columns []string, operator string, value any) contractsorm.Query

func (*Query) WhereAny

func (q *Query) WhereAny(columns []string, operator string, value any) contractsorm.Query

func (*Query) WhereBetween

func (q *Query) WhereBetween(column string, x, y any) contractsorm.Query

func (*Query) WhereColumn

func (q *Query) WhereColumn(first, operator, second string) contractsorm.Query

func (*Query) WhereExists

func (q *Query) WhereExists(callback func(contractsorm.Query) contractsorm.Query) contractsorm.Query

func (*Query) WhereIn

func (q *Query) WhereIn(column string, values []any) contractsorm.Query

func (*Query) WhereJsonContains

func (q *Query) WhereJsonContains(column string, value any) contractsorm.Query

func (*Query) WhereJsonContainsKey

func (q *Query) WhereJsonContainsKey(column string) contractsorm.Query

func (*Query) WhereJsonDoesntContain

func (q *Query) WhereJsonDoesntContain(column string, value any) contractsorm.Query

func (*Query) WhereJsonDoesntContainKey

func (q *Query) WhereJsonDoesntContainKey(column string) contractsorm.Query

func (*Query) WhereJsonLength

func (q *Query) WhereJsonLength(column string, operator string, value any) contractsorm.Query

func (*Query) WhereNone

func (q *Query) WhereNone(columns []string, operator string, value any) contractsorm.Query

func (*Query) WhereNot

func (q *Query) WhereNot(query any, args ...any) contractsorm.Query

func (*Query) WhereNotBetween

func (q *Query) WhereNotBetween(column string, x, y any) contractsorm.Query

func (*Query) WhereNotIn

func (q *Query) WhereNotIn(column string, values []any) contractsorm.Query

func (*Query) WhereNotNull

func (q *Query) WhereNotNull(column string) contractsorm.Query

func (*Query) WhereNull

func (q *Query) WhereNull(column string) contractsorm.Query

func (*Query) With

func (q *Query) With(query string, args ...any) contractsorm.Query

func (*Query) WithContext

func (q *Query) WithContext(ctx context.Context) contractsorm.Query

WithContext returns a new Query instance with the specified context.

func (*Query) WithCount

func (q *Query) WithCount(query string, args ...any) contractsorm.Query

func (*Query) WithExists

func (q *Query) WithExists(query string, args ...any) contractsorm.Query

func (*Query) WithTrashed

func (q *Query) WithTrashed() contractsorm.Query

func (*Query) Without

func (q *Query) Without(relations ...string) contractsorm.Query

func (*Query) WithoutEvents

func (q *Query) WithoutEvents() contractsorm.Query

WithoutEvents disables event firing for the query.

func (*Query) WithoutTrashed

func (q *Query) WithoutTrashed() contractsorm.Query

type SelectClauseBuilder

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

SelectClauseBuilder builds SELECT clauses.

func (*SelectClauseBuilder) ToSQL

func (s *SelectClauseBuilder) ToSQL() (string, []any)

func (*SelectClauseBuilder) Type

func (s *SelectClauseBuilder) Type() ClauseType

type ToSql

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

ToSql implements the ToSql interface for generating SQL without execution.

func NewToSql

func NewToSql(q *Query) *ToSql

NewToSql creates a new ToSql instance.

func (*ToSql) Avg

func (t *ToSql) Avg(column string, dest any) string

Avg generates the SQL for an AVG aggregation query.

func (*ToSql) Count

func (t *ToSql) Count() string

Count generates the SQL for a COUNT query.

func (*ToSql) Create

func (t *ToSql) Create(value any) string

Create generates the SQL for an INSERT query.

func (*ToSql) Decrement

func (t *ToSql) Decrement(column string, amount ...any) string

Decrement generates the SQL for a DECREMENT query.

func (*ToSql) Delete

func (t *ToSql) Delete(value ...any) string

Delete generates the SQL for a DELETE query.

func (*ToSql) Find

func (t *ToSql) Find(dest any, conds ...any) string

Find generates the SQL for a SELECT query.

func (*ToSql) First

func (t *ToSql) First(dest any) string

First generates the SQL for a SELECT query with LIMIT 1.

func (*ToSql) ForceDelete

func (t *ToSql) ForceDelete(value ...any) string

ForceDelete generates the SQL for a DELETE query (same as Delete for now).

func (*ToSql) Get

func (t *ToSql) Get(dest any) string

Get generates the SQL for a SELECT query.

func (*ToSql) Increment

func (t *ToSql) Increment(column string, amount ...any) string

Increment generates the SQL for an INCREMENT query.

func (*ToSql) InsertGetId

func (t *ToSql) InsertGetId(values any) string

InsertGetId generates the SQL for an INSERT query with ID retrieval.

func (*ToSql) Max

func (t *ToSql) Max(column string, dest any) string

Max generates the SQL for a MAX aggregation query.

func (*ToSql) Min

func (t *ToSql) Min(column string, dest any) string

Min generates the SQL for a MIN aggregation query.

func (*ToSql) Pluck

func (t *ToSql) Pluck(column string, dest any) string

Pluck generates the SQL for a SELECT query with a single column.

func (*ToSql) Save

func (t *ToSql) Save(value any) string

Save generates the SQL for an UPDATE query (simplified).

func (*ToSql) Sum

func (t *ToSql) Sum(column string, dest any) string

Sum generates the SQL for a SUM aggregation query.

func (*ToSql) Update

func (t *ToSql) Update(column any, value ...any) string

Update generates the SQL for an UPDATE query.

func (*ToSql) Value

func (t *ToSql) Value(column string, dest any) string

Value generates the SQL for a SELECT query with a single column and LIMIT 1.

type WhereClauseBuilder

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

WhereClauseBuilder builds WHERE clauses.

func (*WhereClauseBuilder) ToSQL

func (w *WhereClauseBuilder) ToSQL() (string, []any)

func (*WhereClauseBuilder) Type

func (w *WhereClauseBuilder) Type() ClauseType

Jump to

Keyboard shortcuts

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