Documentation
¶
Index ¶
- func Build(ctx context.Context, fn func(b *Builder)) context.Context
- func WithBuilder(ctx context.Context, b *Builder) context.Context
- type Builder
- func (b *Builder) And(column string, args ...any) BuilderInterface
- func (b *Builder) Build(query string, args ...any) (string, []any)
- func (b *Builder) In(column string, args ...any) BuilderInterface
- func (b *Builder) Limit(limit int) BuilderInterface
- func (b *Builder) Offset(offset int) BuilderInterface
- func (b *Builder) Or(column string, args ...any) BuilderInterface
- func (b *Builder) Order(cols string, args ...any) BuilderInterface
- func (b *Builder) Where(expression string, args ...any) BuilderInterface
- type BuilderInterface
- type DBTX
- type WrappedOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func (*Builder) And ¶
func (b *Builder) And(column string, args ...any) BuilderInterface
Like method Where() but will add "AND" logic to your expression
Then your query will look like "AND {{ your expression here }}"
Example:
And("name LIKE ?", "%me%")
func (*Builder) In ¶
func (b *Builder) In(column string, args ...any) BuilderInterface
Is equal with Where("id IN (?,?,?,...)", args...)
Example:
In("id", 1,2,3)
In("OR id", 1,2,3)
func (*Builder) Limit ¶
func (b *Builder) Limit(limit int) BuilderInterface
Limit for rows that returned on SELECT query.
Example:
Limit(10)
func (*Builder) Offset ¶
func (b *Builder) Offset(offset int) BuilderInterface
Offset for rows that returned on SELECT query.
Example:
Offset(10)
func (*Builder) Or ¶
func (b *Builder) Or(column string, args ...any) BuilderInterface
Like method Where() but will add "OR" logic to your expression
Then your query will look like "OR {{ your expression here }}"
Example:
Or("name LIKE ?", "%me%")
func (*Builder) Order ¶
func (b *Builder) Order(cols string, args ...any) BuilderInterface
Order columns on SELECT query. Your query will like "SELECT x FROM x WHERE x ORDER BY {{ cols }}"
Example:
Order("id DESC")
Order("id, age DESC")
func (*Builder) Where ¶
func (b *Builder) Where(expression string, args ...any) BuilderInterface
Determine condition on "SELECT x FROM x WHERE {{ this is your expression }}".
Where("id = ?", 1) - If no logic is set, then will use "AND" by default
Where("OR email = ?", "x@gmail.com") - If logic has set, then will use it instead of "AND" (default)
Where("is_deleted = $1", 0)
Where("AND id IN (SELECT user_id FROM user_roles WHERE role_id = $1)", 2)
type BuilderInterface ¶
type BuilderInterface interface {
Where(expression string, args ...any) BuilderInterface
In(column string, args ...any) BuilderInterface
Or(column string, args ...any) BuilderInterface
And(column string, args ...any) BuilderInterface
Order(cols string, args ...any) BuilderInterface
Limit(limit int) BuilderInterface
Offset(offset int) BuilderInterface
Build(query string, args ...any) (string, []any)
}
type DBTX ¶
type DBTX interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
func Wrap ¶
func Wrap(db DBTX, opts WrappedOpts) DBTX
type WrappedOpts ¶ added in v0.0.34
type WrappedOpts struct {
// contains filtered or unexported fields
}