Documentation
¶
Index ¶
- Variables
- func ApplyComplexPtr[Existing constraints.Float | constraints.Integer, ...](existing *Existing, newVal *New, updatedColumns *mysql.ColumnList, ...) *Existing
- func ApplyInterfacePtr[T ApplyInterface[T]](existing *T, newVal *T, updatedColumns *mysql.ColumnList, ...) *T
- func ApplyPtr[T constraints.Float | constraints.Integer | string | bool](existing *T, newVal *T, updatedColumns *mysql.ColumnList, ...) *T
- func ApplyVal[T constraints.Float | constraints.Integer | string | bool](existing T, newVal *T, updatedColumns *mysql.ColumnList, ...) T
- func DestName(destTypeStruct any, path ...string) string
- func ExprStringers(values []fmt.Stringer) []mysql.Expression
- func ExprValues[T any](values []T, f func(T) mysql.Expression) []mysql.Expression
- func Fetch[T any](sqlo Queryable, stmt Statement) ([]*T, error)
- func FetchOne[T any](sqlo Queryable, stmt Statement) (*T, error)
- func Insert(sqlo Executable, stmt Statement) (uint64, error)
- func InsertReturning[T any](sqlo Queryable, stmt Statement) (*T, error)
- func IsZero[T any](ptr *T) error
- func ModuleDB(dialect Dialect, config *DBConfig, forceDebugLog bool) *app.Module
- func MustFetch[T any](sqlo Queryable, stmt Statement, notFoundErr error) ([]*T, error)
- func MustFetchOne[T any](sqlo Queryable, stmt Statement, notFoundErr error) (*T, error)
- func NormalCols[CL ColumnList](cols ...Column) CL
- func NowPtr() *time.Time
- func Ptr[T any](val T) *T
- func SQLO() *sql.DB
- func StringToFilter(str string) string
- func TrimPtr(s *string) *string
- func TrimPtrToNil(s *string) *string
- func Update(sqlo Executable, stmt Statement) error
- func UpdateAffected(sqlo Executable, stmt Statement) (int64, error)
- func UpdateReturning[T any](sqlo Queryable, stmt Statement) (*T, error)
- func Val[T any](ptr *T) T
- type ApplyInterface
- type BoolExpression
- type Column
- type ColumnList
- type DBConfig
- type Dialect
- type Executable
- type ExecutableTx
- type JSONB
- type QueryExec
- type QueryExecTx
- type Queryable
- type SQLOFunc
- type Statement
- type UUID
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoRows is returned when a query returns no rows. ErrNoRows = qrm.ErrNoRows // ErrValueIsZero is returned when an expected value is missing. ErrValueIsZero = errors.New("value is zero-value for type") )
Functions ¶
func ApplyComplexPtr ¶
func ApplyComplexPtr[ Existing constraints.Float | constraints.Integer, New constraints.Float | constraints.Integer, ]( existing *Existing, newVal *New, updatedColumns *mysql.ColumnList, targetColumn mysql.Column, ) *Existing
ApplyComplexPtr compares the existing value with a new value and returns the updated value if they differ. The new value may be of a different type (e.g. existing is uint16 and new is uint64), but it will be converted to match the current type resulting in potential loss of data. If the new value is nil, the existing value is retained. If the new value is a zero-value, the existing value is NOT retained, it will be set to nil. If the value is changed, targetColumn is pushed to updatedColumns.
func ApplyInterfacePtr ¶
func ApplyInterfacePtr[T ApplyInterface[T]]( existing *T, newVal *T, updatedColumns *mysql.ColumnList, targetColumn mysql.Column, ) *T
ApplyInterfacePtr compares the existing value with a new value and returns the updated value if they differ. Comparable types must have IsZero and Equal methods. If the new value is nil, the existing value is retained. If the new value is a zero-value, the existing value is NOT retained, it will be set to nil. If the value is changed, targetColumn is pushed to updatedColumns.
func ApplyPtr ¶
func ApplyPtr[T constraints.Float | constraints.Integer | string | bool]( existing *T, newVal *T, updatedColumns *mysql.ColumnList, targetColumn mysql.Column, ) *T
ApplyPtr compares the existing value with a new value and returns the updated value if they differ. If the new value is nil, the existing value is retained. If the new value is a zero-value, the existing value is NOT retained, it will be set to nil. If the value is changed, targetColumn is pushed to updatedColumns.
func ApplyVal ¶
func ApplyVal[T constraints.Float | constraints.Integer | string | bool]( existing T, newVal *T, updatedColumns *mysql.ColumnList, targetColumn mysql.Column, ) T
ApplyVal compares the existing value with a pointer to a new value and returns the updated value if they differ. If the new value is nil, the existing value is retained. If the value is changed, targetColumn is pushed to updatedColumns
func DestName ¶
DestName returns the name of the type passed as `destTypeStruct` as a string, normalized for compatibility with the Jet QRM.
func ExprStringers ¶
func ExprStringers(values []fmt.Stringer) []mysql.Expression
ExprStringers converts a list of fmt.Stringers to a list of mysql.Expression values.
func ExprValues ¶
func ExprValues[T any](values []T, f func(T) mysql.Expression) []mysql.Expression
ExprValues converts a list of values to a list of mysql.Expression values using function f to transform the values (mysql.String for strings, mysql.Uint64, etc).
func Fetch ¶
Fetch queries the database and returns the result as a slice. If the query returns no rows, it returns an empty slice and no error.
func FetchOne ¶
FetchOne queries the database and returns a single result. If the query returns no rows, it returns nil and no error.
func Insert ¶
func Insert(sqlo Executable, stmt Statement) (uint64, error)
Insert executes an insert statement, returning the last inserted ID or an error if the insert fails.
func InsertReturning ¶
InsertReturning executes an insert statement that returns the inserted row. The statement MUST be a Jet InsertStatement with a RETURNING clause. Returns the inserted row object T or an error if the insert fails or no rows are returned.
func IsZero ¶
IsZero checks if a pointer references the zero value of a given type and returns an error if this condition is met, otherwise returns nil if the pointer is nil or the value is not zero.
func ModuleDB ¶
ModuleDB returns the database module with the provided configuration. dialect specifies the SQL dialect to use (e.g., DialectPostgres, DialectMySQL). config specifies the database connection configuration. forceDebugLog forces debug logging to be enabled regardless of the config setting.
func MustFetch ¶
MustFetch queries the database and returns the result as a slice. If the query returns no rows, it returns an empty slice and the desired error.
func MustFetchOne ¶
MustFetchOne queries the database and returns a single result. If the query returns no rows, it returns nil and the desired error.
func NormalCols ¶
func NormalCols[CL ColumnList](cols ...Column) CL
NormalCols processes a list of columns and strips out any that implement any of ColumnTimestamp, ColumnTime, or ColumnDate.
func Ptr ¶
func Ptr[T any](val T) *T
Ptr returns a pointer to the given value of any scalar type. Returns nil if the value is a zero value.
func StringToFilter ¶
StringToFilter processes a string to be used as a filter in an SQL LIKE statement. It replaces all spaces with % and adds % to the beginning and end of the string.
func TrimPtr ¶
TrimPtr trims the whitespace from a pointer to a string and returns nil only if the pointer is nil.
func TrimPtrToNil ¶
TrimPtrToNil trims the whitespace from a pointer to a string and returns nil if the resulting string is empty or if the pointer is nil.
func Update ¶
func Update(sqlo Executable, stmt Statement) error
Update executes an update statement, returning an error if the update fails.
func UpdateAffected ¶
func UpdateAffected(sqlo Executable, stmt Statement) (int64, error)
UpdateAffected executes an update statement and returns the number of rows affected and an error if any.
func UpdateReturning ¶
UpdateReturning executes an update statement that returns the updated row. The statement MUST be a Jet UpdateStatement with a RETURNING clause. Returns the updated row object T or an error if the update fails or no rows are returned.
Types ¶
type ApplyInterface ¶
type BoolExpression ¶
type BoolExpression interface {
mysql.BoolExpression
postgres.BoolExpression
}
BoolExpression is a union type for mysql.BoolExpression and postgres.BoolExpression
type ColumnList ¶
type ColumnList interface {
mysql.ColumnList
postgres.ColumnList
}
ColumnList is a union type for mysql.ColumnList and postgres.ColumnList
type DBConfig ¶
type DBConfig struct {
User string `validate:"required"`
Password string `validate:"required"`
URI string `validate:"hostname_port,required"`
Name string `validate:"required"`
MaxConn int `validate:"min=1,max=1000"`
AutoMigrate bool
DebugLog bool
}
DBConfig provides a template for database connection configuration compatible with go-toolkit/config. If used as a field in a struct, remember to include the `validate:"dive"` tag to ensure that the validator checks sub-fields.
func (*DBConfig) ConnectionString ¶
ConnectionString returns a connection string compatible with the given SQL dialect.
type Executable ¶
Executable interface is an SQL driver object that can execute SQL statements for Jet.
type ExecutableTx ¶
type ExecutableTx interface {
Executable
Begin() (*sql.Tx, error)
}
ExecutableTx interface is an SQL driver object that implements the Executable interface and can also begin a transaction.
type JSONB ¶
JSONB is a type that represents a JSON object stored in the database. It is a map[string]any and implements sql.Scanner, driver.Valuer, and Stringer.
func (*JSONB) Scan ¶
Scan implements the sql.Scanner interface. It supports converting from string, []byte, or nil into a JSONB value. Attempting to convert from any other type will return an error.
type QueryExec ¶
type QueryExec interface {
Queryable
Executable
}
QueryExec interface is an SQL driver object that can execute SQL statements for Jet and query results.
type QueryExecTx ¶
type QueryExecTx interface {
Queryable
ExecutableTx
}
QueryExecTx interface is an SQL driver object that can execute SQL statements for Jet, query results, and begin a transaction.
type Queryable ¶
Queryable interface is an SQL driver object that can execute SQL statements for Jet.
type Statement ¶
type Statement interface {
Query(db qrm.Queryable, destination any) error
QueryContext(ctx context.Context, db qrm.Queryable, destination any) error
Exec(db qrm.Executable) (sql.Result, error)
ExecContext(ctx context.Context, db qrm.Executable) (sql.Result, error)
}
Statement is a common Jet statement for all SQL operations.
type UUID ¶
UUID is a wrapper around ksuid.KSUID that implements the graphql.Unmarshaler and graphql.Marshaler interfaces for use in GraphQL APIs. It also provides additional convenience functions such as ParseUUID and NewUUID.
func NewUUID ¶
func NewUUID() UUID
Generates a new, wrapped KSUID. In the strange case that random bytes can't be read, it will panic.
func ParseUUID ¶
ParseUUID parses a UUID from a string. If the string is not a valid UUID, it will return an error.
func (UUID) MarshalGQL ¶
MarshalGQL implements the graphql.Marshaler interface
func (*UUID) UnmarshalGQL ¶
UnmarshalGQL implements the graphql.Unmarshaler interface