Documentation
¶
Index ¶
- Variables
- func InsertedValues[Entity any](t *Entity) ([]string, []any)
- func ScanRow[Entity any](t *Entity, row database.Row) error
- type AdvisoryLockQuery
- type ColumnDefinition
- type ColumnSelector
- type ConnFn
- type CountOptions
- type CustomRepository
- type DefaultCustomRepo
- type DefaultMutatorRepo
- func (r *DefaultMutatorRepo[Entity]) Delete(ctx context.Context, preparer database.Preparer, deleter Entity, ...) (int64, error)
- func (r *DefaultMutatorRepo[Entity]) Insert(ctx context.Context, preparer database.Preparer, mutator Entity) (Entity, error)
- func (r *DefaultMutatorRepo[Entity]) Update(ctx context.Context, preparer database.Preparer, updater Entity, ...) (int64, error)
- type DefaultRawQueryer
- func (rq *DefaultRawQueryer) Exec(ctx context.Context, preparer database.Preparer, query string, ...) (database.Result, error)
- func (rq *DefaultRawQueryer) ExecRaw(ctx context.Context, db database.DB, query string, parameters []any) (database.Result, error)
- func (rq *DefaultRawQueryer) Query(ctx context.Context, preparer database.Preparer, query string, ...) (database.Rows, error)
- func (rq *DefaultRawQueryer) QueryRaw(ctx context.Context, db database.DB, query string, parameters []any) (database.Rows, error)
- type DefaultReaderRepo
- func (r *DefaultReaderRepo[Entity]) Count(ctx context.Context, preparer database.Preparer, selectors Selectors, ...) (int, error)
- func (r *DefaultReaderRepo[Entity]) GetMany(ctx context.Context, preparer database.Preparer, ...) ([]Entity, error)
- func (r *DefaultReaderRepo[Entity]) GetOne(ctx context.Context, preparer database.Preparer, ...) (Entity, error)
- func (r *DefaultReaderRepo[Entity]) Query(ctx context.Context, preparer database.Preparer, query string, ...) ([]Entity, error)
- type DefaultTxManager
- type DeleteOptions
- type Direction
- type EntityOption
- type EntityQueryOptions
- func (q *EntityQueryOptions[Entity]) AddOption(field string, value any) *EntityQueryOptions[Entity]
- func (q *EntityQueryOptions[Entity]) AddSelector(field string, predicate Predicate, value any) *EntityQueryOptions[Entity]
- func (q *EntityQueryOptions[Entity]) AddUpdate(field string, value any) *EntityQueryOptions[Entity]
- func (q *EntityQueryOptions[Entity]) Entity() Entity
- func (q *EntityQueryOptions[Entity]) Selectors() Selectors
- func (q *EntityQueryOptions[Entity]) Updates() Updates
- type GetOptions
- type GetterFactoryFn
- type InsertedValuesFn
- type Join
- type JoinType
- type Joins
- type ManyMutatorQuery
- type MutatorQuery
- type MutatorRepository
- type OptionEntityFactoryFn
- type Order
- type Orders
- type Page
- type Predicate
- type Projection
- type Projections
- type Query
- type RawQueryer
- type ReaderQuery
- type ReaderRepository
- type SchemaQuery
- type Selector
- type Selectors
- type TableOptions
- type TxManager
- type Update
- type Updates
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDuplicateEntry is returned when a unique constraint is violated. ErrDuplicateEntry = apierror.NewAPIError("DUPLICATE_ENTRY") // ErrForeignConstraint is returned when a foreign key constraint is // violated. ErrForeignConstraint = apierror.NewAPIError("FOREIGN_CONSTRAINT_ERROR") // ErrNoRows is returned when no rows are found. ErrNoRows = apierror.NewAPIError("NO_ROWS") )
Functions ¶
func InsertedValues ¶
InsertedValues uses reflection to generate slices of column names and values.
Parameters:
- t: A pointer to the object to be scanned.
Returns:
- []string: A slice of column names.
- []any: A slice of values.
Types ¶
type AdvisoryLockQuery ¶
type AdvisoryLockQuery interface {
// AdvisoryLock builds an advisory lock statement.
AdvisoryLock(lockName string, timeout int) (string, []any, error)
// AdvisoryUnlock builds an advisory unlock statement.
AdvisoryUnlock(lockName string) (string, []any, error)
}
AdvisoryLockQuery provides methods for advisory locking.
type ColumnDefinition ¶
type ColumnDefinition struct {
Name string // Column name
Type string // Data type (with length/precision, e.g. "CHAR(36)")
NotNull bool // Whether to add NOT NULL (if false, NULL is allowed)
Default *string // Optional default value (pass nil if not needed)
AutoIncrement bool // Whether to add AUTO_INCREMENT
Extra string // Extra column options (e.g. "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin")
PrimaryKey bool // Marks this column as primary key (inline)
Unique bool // Marks this column as UNIQUE (unless already primary key)
}
ColumnDefinition defines the properties for a table column in a table. creation query.
type ColumnSelector ¶
ColumnSelector represents a column selector.
type CountOptions ¶
CountOptions is used for count queries.
type CustomRepository ¶
type CustomRepository[Entity any] interface { // QueryCustom executes a custom SQL It returns a slice of T or an // error if the query or scan fails. QueryCustom( ctx context.Context, preparer database.Preparer, query string, parameters []any, factoryFn func() Entity, ) ([]Entity, error) }
CustomRepository defines methods for executing custom SQL queries and mapping the results into custom entities.
func NewCustomRepo ¶
func NewCustomRepo[T any]( errorChecker database.ErrorChecker, ) CustomRepository[T]
NewCustomRepo creates a new customRepo.
type DefaultCustomRepo ¶
type DefaultCustomRepo[T any] struct { ErrorChecker database.ErrorChecker }
DefaultCustomRepo implements the CustomRepo interface. It can be used to execute custom SQL queries and map the results into custom entities. It supports both object and scalar values.
func (*DefaultCustomRepo[T]) QueryCustom ¶
func (r *DefaultCustomRepo[T]) QueryCustom( ctx context.Context, preparer database.Preparer, query string, parameters []any, factoryFn func() T, ) ([]T, error)
QueryCustom executes a custom SQL query and maps the results into a slice of custom entities. It detects is the custom entity is a database.Getter and uses the getter to populate the entity.
Parameters:
- ctx: Context to use.
- preparer: The preparer to use for the query.
- query: The SQL query to execute.
- parameters: The query parameters.
- factoryFn: A function that creates a custom entity from a database row.
Returns:
- []T: A slice of custom entities scanned from the query.
- error: An error if the query fails.
type DefaultMutatorRepo ¶
type DefaultMutatorRepo[Entity database.Mutator] struct { MutatorQuery MutatorQuery ErrorChecker database.ErrorChecker }
DefaultMutatorRepo implements mutation operations.
func NewMutatorRepo ¶
func NewMutatorRepo[Entity database.Mutator]( mutatorQuery MutatorQuery, errorChecker database.ErrorChecker, ) *DefaultMutatorRepo[Entity]
NewMutatorRepo creates a new mutatorRepo.
Parameters:
- ctx: Context to use.
- mutatorQuery: The query builder to use for the repository.
- errorChecker: The error checker to use for the repository.
Returns:
- *mutatorRepo: A new mutatorRepo.
func (*DefaultMutatorRepo[Entity]) Delete ¶
func (r *DefaultMutatorRepo[Entity]) Delete( ctx context.Context, preparer database.Preparer, deleter Entity, selectors Selectors, deleteOpts *DeleteOptions, ) (int64, error)
Delete builds a delete query and executes it.
Parameters:
- ctx: Context to use.
- preparer: The preparer to use for the
- deleter: The entity to delete.
- selectors: The selectors to use for the delete.
- deleteOpts: The delete options.
Returns:
- int64: The number of rows affected by the delete.
- error: An error if the query fails.
func (*DefaultMutatorRepo[Entity]) Insert ¶
func (r *DefaultMutatorRepo[Entity]) Insert( ctx context.Context, preparer database.Preparer, mutator Entity, ) (Entity, error)
Insert builds an insert query and executes it.
Parameters:
- ctx: Context to use.
- preparer: The preparer to use for the
- mutator: The entity to insert.
Returns:
- T: The inserted entity.
- error: An error if the query fails.
func (*DefaultMutatorRepo[Entity]) Update ¶
func (r *DefaultMutatorRepo[Entity]) Update( ctx context.Context, preparer database.Preparer, updater Entity, selectors Selectors, updates Updates, ) (int64, error)
Update builds an update query and executes it.
Parameters:
- ctx: Context to use.
- preparer: The preparer to use for the
- updater: The entity to update.
- selectors: The selectors to use for the update.
- updates: The updates to apply to the entity.
Returns:
- int64: The number of rows affected by the update.
- error: An error if the query fails.
type DefaultRawQueryer ¶
type DefaultRawQueryer struct{}
DefaultRawQueryer provides direct query execution.
func NewRawQueryer ¶
func NewRawQueryer() *DefaultRawQueryer
NewRawQueryer creates a new rawQueryer.
Returns:
- *rawQueryer: A new rawQueryer.
func (*DefaultRawQueryer) Exec ¶
func (rq *DefaultRawQueryer) Exec( ctx context.Context, preparer database.Preparer, query string, parameters []any, ) (database.Result, error)
Exec executes a query using a prepared statement.
Parameters:
- ctx: Context to use.
- preparer: The preparer to use for the
- query: The SQL query to execute.
- parameters: The query parameters.
Returns:
- Result: The Result of the
- error: An error if the query fails.
func (*DefaultRawQueryer) ExecRaw ¶
func (rq *DefaultRawQueryer) ExecRaw( ctx context.Context, db database.DB, query string, parameters []any, ) (database.Result, error)
ExecRaw executes a query directly on the DB.
Parameters:
- ctx: Context to use.
- db: The DB to execute the query on.
- query: The SQL query to execute.
- parameters: The query parameters.
Returns:
- Result: The Result of the
- error: An error if the query fails.
func (*DefaultRawQueryer) Query ¶
func (rq *DefaultRawQueryer) Query( ctx context.Context, preparer database.Preparer, query string, parameters []any, ) (database.Rows, error)
Query executes a query that returns rows. The caller is responsible for closing the rows.
Parameters:
- ctx: Context to use.
- preparer: The preparer to use for the
- query: The SQL query to execute.
- parameters: The query parameters.
Returns:
- Rows: The rows of the
- error: An error if the query fails.
func (*DefaultRawQueryer) QueryRaw ¶
func (rq *DefaultRawQueryer) QueryRaw( ctx context.Context, db database.DB, query string, parameters []any, ) (database.Rows, error)
QueryRaw executes a query directly on the DB without preparation.
Parameters:
- ctx: Context to use.
- db: The DB to execute the query on.
- query: The SQL query to execute.
- parameters: The query parameters.
Returns:
- Rows: The rows of the
- error: An error if the query fails.
type DefaultReaderRepo ¶
type DefaultReaderRepo[Entity database.Getter] struct { ReaderQuery ReaderQuery ErrorChecker database.ErrorChecker }
DefaultReaderRepo implements read operations.
func NewReaderRepo ¶
func NewReaderRepo[Entity database.Getter]( readerQuery ReaderQuery, errorChecker database.ErrorChecker, ) *DefaultReaderRepo[Entity]
NewReaderRepo creates a new readerRepo.
Parameters:
- ctx: Context to use.
- readerQuery: The query builder to use for building queries.
- errorChecker: The ErrorChecker to use for checking errors.
Returns:
- *readerRepo: A new readerRepo.
func (*DefaultReaderRepo[Entity]) Count ¶
func (r *DefaultReaderRepo[Entity]) Count( ctx context.Context, preparer database.Preparer, selectors Selectors, page *Page, factoryFn GetterFactoryFn[Entity], ) (int, error)
Count returns the count of matching records.
Parameters:
- ctx: Context to use.
- preparer: The preparer to use for the
- selectors: The Selectors to use for the
- page: The Page to use for the
- factoryFn: A function that returns a new instance of T.
Returns:
- int: The count of matching records.
- error: An error if the query fails.
func (*DefaultReaderRepo[Entity]) GetMany ¶
func (r *DefaultReaderRepo[Entity]) GetMany( ctx context.Context, preparer database.Preparer, factoryFn GetterFactoryFn[Entity], getOpts *GetOptions, ) ([]Entity, error)
GetMany retrieves multiple records from the DB.
Parameters:
- ctx: Context to use.
- preparer: The preparer to use for the
- factoryFn: A function that returns a new instance of T.
- getOpts: The GetOptions to use for the
Returns:
- []T: A slice of entities scanned from the
- error: An error if the query fails.
func (*DefaultReaderRepo[Entity]) GetOne ¶
func (r *DefaultReaderRepo[Entity]) GetOne( ctx context.Context, preparer database.Preparer, factoryFn GetterFactoryFn[Entity], getOpts *GetOptions, ) (Entity, error)
GetOne retrieves a single record from the DB by delegating to dbOps.
Parameters:
- ctx: Context to use.
- preparer: The preparer to use for the
- factoryFn: A function that returns a new instance of T.
- getOpts: The GetOptions to use for the
Returns:
- T: The entity scanned from the
- error: An error if the query fails.
func (*DefaultReaderRepo[Entity]) Query ¶
func (r *DefaultReaderRepo[Entity]) Query( ctx context.Context, preparer database.Preparer, query string, parameters []any, factoryFn GetterFactoryFn[Entity], ) ([]Entity, error)
Query executes a custom SQL query that is already built.
Parameters:
- ctx: Context to use.
- preparer: The preparer to use for the
- query: The SQL query to execute.
- parameters: The query parameters.
- factoryFn: A function that returns a new instance of T.
Returns:
- []T: A slice of entities scanned from the
- error: An error if the query fails.
type DefaultTxManager ¶
type DefaultTxManager[Entity any] struct{}
DefaultTxManager is the default transaction manager.
func NewTxManager ¶
func NewTxManager[Entity any]() *DefaultTxManager[Entity]
NewTxManager returns a new txManager.
Returns:
- *txManager[Entity]: The new txManager.
func (*DefaultTxManager[Entity]) WithTransaction ¶
func (t *DefaultTxManager[Entity]) WithTransaction( ctx context.Context, connFn ConnFn, callback database.TxFn[Entity], ) (Entity, error)
WithTransaction wraps a function call in a DB transaction.
Parameters:
- ctx: Context to use.
- ctx: The context to use for the transaction.
- connFn: The function to get a DB connection.
- callback: The function to call in the transaction.
Returns:
- Entity: The result of the callback.
- error: An error if the transaction fails.
type DeleteOptions ¶
DeleteOptions is used for delete queries.
type EntityOption ¶
type EntityOption[T any] func(T)
EntityOption defines a functional option for configuring an entity.
func WithOption ¶
func WithOption[T any]( field string, value any, ) EntityOption[T]
WithOption is a generic functional option that sets a field on an object. The field parameter should match the object's struct `db` tag. It attempts to automatically handle differences between pointer and non-pointer values. Only single level pointer differences are handled and passing a multi-level pointer field will panic.
Example:
type SomeEntity struct {
ID custom.UUID `db:"id"`
Data string `db:"data"`
}
field = "data"
value = "example data"
Output:
someEntity.Data = "example data"
Limitations:
- Only single-level pointer differences are handled. Multi-level pointers (e.g. **SomeEntity) are not supported.
- If the field is not found in the object, or if the provided value's type is not assignable (even after pointer adjustments), the function will panic.
Parameters:
- field: The field to set.
- value: The value to set.
Returns:
- EntityOption[Entity]: The entity-specific option.
type EntityQueryOptions ¶
type EntityQueryOptions[Entity database.CRUDEntity] struct { TableName string EntityFn func() Entity OptionEntityFn OptionEntityFactoryFn[Entity] SelectorList Selectors UpdateList Updates Options []EntityOption[Entity] }
EntityQueryOptions represents a query for an entity.
func NewEntityQueryOptions ¶
func NewEntityQueryOptions[Entity database.CRUDEntity]( tableName string, entityFn func() Entity, optionEntityFn OptionEntityFactoryFn[Entity], ) *EntityQueryOptions[Entity]
NewEntityQueryOptions creates a new NewEntityQuery for an entity.
Parameters:
- tableName: The name of the table to
- entityFn: A function that returns the entity to
- optionEntityFn: A function that returns the entity with the given options.
Returns:
- *EntityQuery: The new Entity
func (*EntityQueryOptions[Entity]) AddOption ¶
func (q *EntityQueryOptions[Entity]) AddOption( field string, value any, ) *EntityQueryOptions[Entity]
Option creates an entity-specific option.
Parameters:
- field: The field to set.
- value: The value to set.
Returns:
- crud.EntityOption[Entity]: The entity-specific option.
func (*EntityQueryOptions[Entity]) AddSelector ¶
func (q *EntityQueryOptions[Entity]) AddSelector( field string, predicate Predicate, value any, ) *EntityQueryOptions[Entity]
AddSelector appends a selector to the
Parameters:
- field: The field to select.
- predicate: The predicate to apply.
- value: The value to compare.
Returns:
- *EntityQuery: The updated Entity
func (*EntityQueryOptions[Entity]) AddUpdate ¶
func (q *EntityQueryOptions[Entity]) AddUpdate( field string, value any, ) *EntityQueryOptions[Entity]
AddUpdate appends an update clause to the
Parameters:
- field: The field to update.
- value: The value to set.
Returns:
- *EntityQuery: The updated Entity
func (*EntityQueryOptions[Entity]) Entity ¶
func (q *EntityQueryOptions[Entity]) Entity() Entity
Entity returns the entity that is being queried with the set options.
Returns:
- Entity: The entity that is being queried.
func (*EntityQueryOptions[Entity]) Selectors ¶
func (q *EntityQueryOptions[Entity]) Selectors() Selectors
Selectors returns the current selectors.
Returns:
- types.Selectors: The current selectors.
func (*EntityQueryOptions[Entity]) Updates ¶
func (q *EntityQueryOptions[Entity]) Updates() Updates
Updates returns the current updates.
Returns:
- types.Updates: The current updates.
type GetOptions ¶
type GetOptions struct {
Selectors Selectors
Orders Orders
Page *Page
Joins Joins
Projections Projections
Lock bool
}
GetOptions is used for get queries.
type GetterFactoryFn ¶
GetterFactoryFn returns a Getter factory function.
type InsertedValuesFn ¶
InsertedValuesFn defines a function that returns column names and values for an insert. This allows deferred evaluation of values and consistent ordering of parameters.
type Join ¶
type Join struct {
JoinType JoinType
Table string
OnLeft ColumnSelector
OnRight ColumnSelector
}
Join represents a database join clause.
func NewJoin ¶
func NewJoin( joinType JoinType, table string, onLeft, onRight ColumnSelector, ) Join
NewJoin creates a new join clause.
Parameters:
- joinType: The type of join.
- table: The table name.
- onLeft: The left column selector.
- onRight: The right column selector.
Returns:
- Join: The new join clause.
func (Join) WithJoinType ¶
WithJoinType returns a new join with the provided join type.
Parameters:
- joinType: The join type.
Returns:
- Join: The new join.
func (Join) WithOnLeft ¶
func (j Join) WithOnLeft(onLeft ColumnSelector) Join
WithOnLeft returns a new join with the provided left column selector.
Parameters:
- onLeft: The left column selector.
Returns:
- Join: The new join.
func (Join) WithOnRight ¶
func (j Join) WithOnRight(onRight ColumnSelector) Join
WithOnRight returns a new join with the provided right column selector.
Parameters:
- onRight: The right column selector.
Returns:
- Join: The new join.
type ManyMutatorQuery ¶
type ManyMutatorQuery interface {
// InsertMany builds a batch INSERT for multiple rows.
InsertMany(
table string, valuesFuncs []InsertedValuesFn,
) (query string, params []any)
// UpsertMany builds an UPSERT (insert or update) statement.
UpsertMany(
table string, valuesFuncs []InsertedValuesFn,
updateProjections []Projection,
) (query string, params []any)
}
ManyMutatorQuery provides methods for modifying multiple rows in a query.
type MutatorQuery ¶
type MutatorQuery interface {
// Insert builds an INSERT statement for a single row.
Insert(
table string, insertedValuesFunc InsertedValuesFn,
) (query string, params []any)
// UpdateQuery builds an UPDATE statement for given selectors.
UpdateQuery(
table string, updates []Update, selectors []Selector,
) (query string, params []any)
// Delete builds a DELETE statement for given selectors.
Delete(
table string, selectors []Selector, opts *DeleteOptions,
) (query string, params []any)
}
MutatorQuery provides methods for modifying data in a query.
type MutatorRepository ¶
type MutatorRepository[Entity database.Mutator] interface { // Insert builds an insert query and executes it. Insert( ctx context.Context, preparer database.Preparer, entity Entity, ) (Entity, error) // Update builds an update query and executes it. Update( ctx context.Context, preparer database.Preparer, entity Entity, selectors Selectors, updates Updates, ) (int64, error) // Delete builds a delete query and executes it. Delete( ctx context.Context, preparer database.Preparer, entity Entity, selectors Selectors, deleteOpts *DeleteOptions, ) (int64, error) }
MutatorRepository defines mutation-related operations.
type OptionEntityFactoryFn ¶
type OptionEntityFactoryFn[Entity database.CRUDEntity] func( opts ...EntityOption[Entity], ) Entity
OptionEntityFactoryFn is a function that returns an entity with the given options.
type Projection ¶
Projection represents a projected column in a query.
type Query ¶
type Query interface {
MutatorQuery
ManyMutatorQuery
ReaderQuery
SchemaQuery
AdvisoryLockQuery
}
Query combines all query-building interfaces.
type RawQueryer ¶
type RawQueryer interface {
// Exec executes a query using a prepared statement that does not return
// rows.
Exec(
ctx context.Context,
preparer database.Preparer,
query string,
parameters []any,
) (database.Result, error)
// ExecRaw executes a query directly on the DB without explicit preparation.
ExecRaw(
ctx context.Context,
db database.DB,
query string,
parameters []any,
) (database.Result, error)
// Query prepares and executes a query that returns rows. Returns rows.
// The caller is responsible for closing the returned rows.
Query(
ctx context.Context,
preparer database.Preparer,
query string,
parameters []any,
) (database.Rows, error)
// QueryRaw executes a query directly on the DB without preparation and
// returns rows. The caller is responsible for closing the returned rows.
QueryRaw(ctx context.Context, db database.DB, query string, parameters []any,
) (database.Rows, error)
}
RawQueryer defines generic methods for executing raw queries and commands.
type ReaderQuery ¶
type ReaderQuery interface {
// Get builds a SELECT statement with optional filters.
Get(table string, opts *GetOptions) (query string, params []any)
// Count builds a SELECT COUNT(*) statement with optional filters.
Count(table string, opts *CountOptions) (query string, params []any)
}
ReaderQuery provides methods for querying data.
type ReaderRepository ¶
type ReaderRepository[Entity database.Getter] interface { // GetOne retrieves a single record from the DB. GetOne( ctx context.Context, preparer database.Preparer, factoryFn GetterFactoryFn[Entity], getOptions *GetOptions, ) (Entity, error) // GetMany retrieves multiple records from the DB. GetMany( ctx context.Context, preparer database.Preparer, factoryFn GetterFactoryFn[Entity], getOptions *GetOptions, ) ([]Entity, error) // Count returns a record count. Count( ctx context.Context, preparer database.Preparer, selectors Selectors, page *Page, factoryFn GetterFactoryFn[Entity], ) (int, error) }
ReaderRepository defines retrieval-related operations.
type SchemaQuery ¶
type SchemaQuery interface {
// CreateDatabaseQuery builds a CREATE DATABASE statement.
CreateDatabaseQuery(
dbName string, ifNotExists bool, charset string, collate string,
) (string, []any, error)
// CreateTableQuery builds a CREATE TABLE statement.
CreateTableQuery(
tableName string, ifNotExists bool, columns []ColumnDefinition,
constraints []string, opts TableOptions,
) (string, []any, error)
// UseDatabaseQuery builds a USE DATABASE statement.
UseDatabaseQuery(dbName string) (string, []any, error)
// SetVariableQuery builds a SET statement for a variable.
SetVariableQuery(
variable string, value string,
) (string, []any, error)
// CurrentTimestamp returns the current timestamp expression.
CurrentTimestamp() *string
// CurrentTimestamp returns the text type expression.
TypeText() *string
// CurrentTimestamp returns the datetime type expression.
TypeDatetime() *string
}
SchemaQuery provides methods for managing the database schema.
type Selector ¶
Selector represents a database selector.
func MustGetSelector ¶
func MustGetSelector( tableName string, entity any, column string, predicate Predicate, value any, ) *Selector
MustGetSelector creates a new Selector with the given parameters. It panics if the provided value's type is not assignable to the expected type.
Parameters:
- tableName: The name of the table to select from.
- entity: The entity to select from.
- column: The column to select.
- predicate: The predicate to apply.
- value: The value to compare.
Returns:
- *types.Selector: The new Selector.
func NewSelector ¶
NewSelector creates a new selector with the given parameters.
Parameters:
- column: the column name.
- predicate: the predicate.
- value: the value.
Returns:
- *Selector: The new selector.
func (*Selector) WithColumn ¶
WithColumn returns a new selector with the provided column name.
Parameters:
- column: the column name.
Returns:
- *Selector: The new selector.
func (*Selector) WithPredicate ¶
WithPredicate returns a new selector with the provided predicate.
Parameters:
- predicate: the predicate.
Returns:
- *Selector: The new selector.
type Selectors ¶
type Selectors []Selector
Selectors represents a list of database selectors.
func NewSelectors ¶
NewSelectors returns a new list of selectors.
Parameters:
- selectors: The selectors.
Returns:
- Selectors: The new list of selectors.
func (Selectors) Add ¶
Add adds a new selector to the list.
Parameters:
- column: The column name.
- predicate: The predicate.
- value: The value.
Returns:
- Selectors: The new list of selectors.
func (Selectors) GetByField ¶
GetByField returns selector with the given field.
Parameters:
- field: the field to search for.
Returns:
- *Selector: The selector.
func (Selectors) GetByFields ¶
GetByFields returns selectors with the given fields.
Parameters:
- fields: the fields to search for.
Returns:
- []Selector: A list of selectors.
type TableOptions ¶
type TableOptions struct {
Engine string // e.g. "InnoDB"
Charset string // e.g. "utf8mb4"
Collate string // e.g. "utf8mb4_bin"
}
TableOptions holds additional options for a table creation query.
type TxManager ¶
type TxManager[T any] interface { // WithTransaction wraps a function call in a DB transaction. WithTransaction( ctx context.Context, connFn ConnFn, callback database.TxFn[T], ) (T, error) }
TxManager is an interface for transaction management.
type Update ¶
Update is the options struct used for update queries.
func MustGetUpdate ¶
MustGetUpdate creates a new Update with the given parameters. It panics if the provided value's type is not assignable to the expected type.
Parameters:
- entity: The entity to update.
- fieldName: The field to update.
- value: The value to set.
Returns:
- *types.Update: The new Update.
func NewUpdate ¶
NewUpdate creates a new update field.
Parameters:
- field: The field.
- value: The value
Returns:
- Update: The new update field.
type Updates ¶
type Updates []Update
Updates is a list of update fields
func NewUpdates ¶
NewUpdates creates a new list of updates.
Parameters:
- updates: The updates.
Returns:
- Updates: The new list of updates.