Documentation
¶
Overview ¶
Package sqlrud provides a small CRUD helper for database/sql-style applications.
Index ¶
- Variables
- type Client
- func (client *Client) Create(ctx context.Context, model any) error
- func (client *Client) CreateOrUpdate(ctx context.Context, model any) error
- func (client *Client) Delete(ctx context.Context, model any, options ...QueryOption) error
- func (client *Client) Find(ctx context.Context, destination any, options ...QueryOption) error
- func (client *Client) First(ctx context.Context, destination any) error
- func (client *Client) Transaction(ctx context.Context, fn func(*Client) error) error
- func (client *Client) TransactionOptions(ctx context.Context, options *sql.TxOptions, fn func(*Client) error) (err error)
- func (client *Client) Update(ctx context.Context, model any, options ...QueryOption) error
- type Direction
- type Predicate
- func Eq(value any) Predicate
- func Gt(value any) Predicate
- func Gte(value any) Predicate
- func In(values ...any) Predicate
- func IsNotNull() Predicate
- func IsNull() Predicate
- func Like(value any) Predicate
- func Lt(value any) Predicate
- func Lte(value any) Predicate
- func NotEq(value any) Predicate
- func NotIn(values ...any) Predicate
- type QueryOption
- type TableNamer
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidModel = errors.New("sqlrud: model must be a struct or a pointer to struct") ErrInvalidDestination = errors.New("sqlrud: destination must be a pointer to struct or slice") ErrInvalidIdentifier = errors.New("sqlrud: invalid identifier") ErrDuplicateColumn = errors.New("sqlrud: duplicate column") ErrAmbiguousField = errors.New("sqlrud: ambiguous field") ErrMissingPrimaryKey = errors.New("sqlrud: model has no primary key") ErrMissingPrimaryValue = errors.New("sqlrud: primary key value is empty") ErrMissingWhere = errors.New("sqlrud: update or delete requires conditions or a primary key value") ErrNoColumns = errors.New("sqlrud: no writable columns") ErrUnknownField = errors.New("sqlrud: unknown field") ErrEmptyIn = errors.New("sqlrud: IN predicate requires at least one value") ErrUnsupportedOption = errors.New("sqlrud: unsupported option") ErrUnsupportedDialect = errors.New("sqlrud: unsupported dialect") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client runs CRUD operations through sqlx.
func (*Client) CreateOrUpdate ¶
CreateOrUpdate inserts model or atomically updates it on primary key conflict.
func (*Client) Transaction ¶
Transaction runs fn in a transaction. Returning an error from fn rolls back the transaction.
type Predicate ¶
type Predicate struct {
// contains filtered or unexported fields
}
Predicate represents a safe field comparison used by Where.
type QueryOption ¶
type QueryOption interface {
// contains filtered or unexported methods
}
QueryOption configures CRUD queries.
func Offset ¶
func Offset(offset int) QueryOption
Offset adds an OFFSET clause. MySQL requires Limit to be specified as well.
func OrderBy ¶
func OrderBy(field string, direction Direction) QueryOption
OrderBy adds an ORDER BY clause.
func Where ¶
func Where(field string, predicate Predicate) QueryOption
Where adds an AND condition. field can be either a struct field name or db column name.
type TableNamer ¶
type TableNamer interface {
TableName() string
}
TableNamer overrides the table name for a model.
Click to show internal directories.
Click to hide internal directories.