Documentation
¶
Index ¶
- Constants
- func CloseAllDataSources() error
- func CloseDataSource(name string) error
- func Query[T entity.Entity](schema Schema) func(where Where) Executor
- func QueryJoin(schema Schema) func(joinstmt string, where Where) Executor
- func SetSQLLogger(l *log.Logger)
- func Update[T entity.Entity](values ValueObject) func(where Where) Executor
- func UpdateJoin[T entity.Entity](values ValueObject) func(joinstmt string, where Where) Executor
- type DB
- type Executor
- type Schema
- type ValueObject
- type Where
- func And(wheres ...Where) Where
- func Eq(field dvo.Field, value any) Where
- func Gt(field dvo.Field, value any) Where
- func Gte(field dvo.Field, value any) Where
- func In(field dvo.Field, values ...any) Where
- func Like(field dvo.Field, value string) Where
- func Lt(field dvo.Field, value any) Where
- func Lte(field dvo.Field, value any) Where
- func Ne(field dvo.Field, value any) Where
- func Or(wheres ...Where) Where
Constants ¶
const ( UserKey = "${user}" PasswordKey = "${password}" HostKey = "${host}" )
Variables ¶
This section is empty.
Functions ¶
func CloseAllDataSources ¶
func CloseAllDataSources() error
CloseAllDataSources closes and removes all registered datasources from the registry. It returns the first error encountered while closing any datasource, or nil on success.
func CloseDataSource ¶
CloseDataSource closes and removes the named datasource from the registry.
func Query ¶
Query builds a single-table SELECT query.
Usage example:
// build executor exec := Query[Account](schema)(Eq(field, value)) // run resEither, err := exec.Execute(ctx, db) // check left/right and handle accordingly
func QueryJoin ¶
QueryJoin builds a select executor that injects `joinstmt` into the FROM clause. The returned Executor follows the existing `Executor` contract.
func SetSQLLogger ¶
SetSQLLogger enables SQL logging for all datasources registered after this call. Call this early (e.g., in main) before any DefaultDS/GetDS calls.
func Update ¶
func Update[T entity.Entity](values ValueObject) func(where Where) Executor
Update builds a single-table UPDATE query.
New design: public Update accepts the update payload as a meta.ValueObject; the ValueObject may include a special "__schema" entry or provide its own Fields() listing. This avoids a global runtime schema registry.
func UpdateJoin ¶
UpdateJoin builds an update executor that applies an EXISTS-correlated join filter. The update payload values are supplied as a meta.ValueObject when creating the executor via UpdateJoin[T](values)(joinstmt, where).
Types ¶
type DB ¶
type DB interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
PingContext(ctx context.Context) error
Close() error
}
DB is the minimal database contract used by this package. It mirrors the methods we use from *sql.DB and can be backed by *sql.DB or a thin wrapper.
This indirection lets us add cross-cutting features (SQL logging, tracing, metrics) without changing the higher-level query builder APIs.
type Executor ¶
type Executor interface {
Execute(ctx context.Context, ds *sql.DB) (mo.Either[[]ValueObject, sql.Result], error)
// contains filtered or unexported methods
}
Executor represents the delayed execution step constructed by the top-level factory helpers (`Query`, `Delete`, `Update`).
Execution contract:
- Callers obtain an Executor via one of the factory functions and then call `Execute(ctx, db)` to run the statement. Parameter values for the prepared statement are set during `Where.Build()` (the Where returns the SQL fragment and its argument list). For INSERT/UPDATE builders which consume a `meta.ValueObject` for column values, those helpers read the ValueObject inside their builder functions.
- `Execute` will call the appropriate lower-level builder helper to obtain both the SQL string and the argument list (e.g. `selectSQL`).
- For SELECT statements the left side of `mo.Either` holds the `[]meta.ValueObject` results; for non-SELECT statements the right side holds the `sql.Result`.
Note: `sql()` is kept pure and only returns the generated SQL string and an error. It is primarily useful for testing and inspection.
type ValueObject ¶
type ValueObject interface {
internal.ValueObject
// contains filtered or unexported methods
}
ValueObject is a thin alias over internal.ValueObject to expose it
func NewValueObject ¶
func NewValueObject(m map[string]any) ValueObject
type Where ¶
Where is the only contract used to express predicates for CRUD.
The DSL helpers in this package (And/Or/Eq/In/Like/...) produce values that implement `Where`. `Where.Build()` returns a SQL fragment and the parameter list suitable for use in a prepared statement.
func And ¶
And combines multiple Where conditions with the AND operator. Nil or empty clauses are ignored.