Documentation
¶
Index ¶
- Constants
- type BasicField
- type DB
- func (jdb *DB) Delete(table string, id any) error
- func (jdb *DB) From(table string) QueryDB
- func (jdb *DB) Get(table string, id any, v any) error
- func (jdb *DB) GetRow(sql string, v any, values ...any) error
- func (jdb *DB) Insert(table string, v any) error
- func (jdb *DB) InsertWithOptions(table string, options Options, v any) error
- func (jdb *DB) Select(table string, v any) error
- func (jdb *DB) SelectAll(sql string, v any, values ...any) error
- func (jdb *DB) Update(table string, id any, v any) error
- func (jdb *DB) UpdateWithOptions(table string, id any, options Options, v any) error
- type DBLike
- type Delete
- type Expr
- type Field
- type Insert
- type LiteralField
- type NestedExpr
- type Options
- type OrderBy
- type PageOptions
- type QueryDB
- func (q QueryDB) All(v any) error
- func (q QueryDB) Count() (uint, error)
- func (q QueryDB) Get(id any, v any) error
- func (q QueryDB) One(v any) error
- func (q QueryDB) OrWhere(expr string, values ...any) QueryDB
- func (q QueryDB) OrWhereExpr(expr Expr, values ...any) QueryDB
- func (q QueryDB) Order(expression string, direction string) QueryDB
- func (q QueryDB) Page(options PageOptions, v any) error
- func (q QueryDB) Where(expr string, values ...any) QueryDB
- func (q QueryDB) WhereExpr(expr Expr, values ...any) QueryDB
- type Select
- type SimpleExpr
- type Update
- type WhereClause
Constants ¶
const ( AND_TYPE = "AND" OR_TYPE = "OR" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BasicField ¶ added in v0.0.6
This is a standard k = v field
func (BasicField) GetName ¶ added in v0.0.6
func (f BasicField) GetName() string
func (BasicField) GetPlaceholder ¶ added in v0.0.6
func (f BasicField) GetPlaceholder(idx int) string
func (BasicField) GetValue ¶ added in v0.0.6
func (f BasicField) GetValue() any
func (BasicField) IsLiteral ¶ added in v0.0.7
func (f BasicField) IsLiteral() bool
type DB ¶
type DB struct { DB DBLike IDColumn string SkipOnInsert []string // Allows you specify db field names to skip on insert }
func (*DB) Get ¶
Gets a single row from the given table with the given id. v must be a pointer to a struct.
func (*DB) GetRow ¶
Gets a single row using the supplied SQL and values. The result will be marshalled into the v struct. v must be a pointer to a struct.
func (*DB) Insert ¶
Inserts a row into the specified `table` with the given struct. The new row is returned and marshalled into v. v must be a pointer to a struct.
func (*DB) InsertWithOptions ¶ added in v0.0.6
Inserts a row into the specified `table` with the given struct. The new row is returned and marshalled into v. An Options type with a slice of Fields can be included to override any values in v. v must be a pointer to a struct.
func (*DB) Select ¶
Selects all rows from a given table. The results will be marshalled into the v slice of structs. v must be a pointer to a slice of structs.
func (*DB) SelectAll ¶
Selects all rows using the supplied SQL and values. The results will be marshalled into the v slice of structs. v must be a pointer to a slice of structs.
func (*DB) Update ¶ added in v0.0.4
Updates a row in the specified `table` using the given struct. The updated row is returned and marshalled into v. v must be a pointer to a struct.
func (*DB) UpdateWithOptions ¶ added in v0.0.7
Updates a row in the specified `table` using the given struct. The updated row is returned and marshalled into v. An Options type with a slice of Fields can be included to override any values in v. v must be a pointer to a struct.
type DBLike ¶ added in v0.0.5
type DBLike interface { Exec(query string, args ...any) (sql.Result, error) Query(query string, args ...any) (*sql.Rows, error) QueryRow(query string, args ...any) *sql.Row }
Represents a DB-like interface. This only specifies the methods used by sqlj. Both DB and Tx in the database/sql standard library fulfill this contract.
type Delete ¶ added in v0.0.7
type Delete struct { From string Where []WhereClause }
type LiteralField ¶ added in v0.0.6
This is useful if you want to call a function. An example would be LiteralField{Name: "created_at", Value: "now()"}.
func (LiteralField) GetName ¶ added in v0.0.6
func (f LiteralField) GetName() string
func (LiteralField) GetPlaceholder ¶ added in v0.0.6
func (f LiteralField) GetPlaceholder(idx int) string
func (LiteralField) GetValue ¶ added in v0.0.6
func (f LiteralField) GetValue() any
func (LiteralField) IsLiteral ¶ added in v0.0.7
func (f LiteralField) IsLiteral() bool
type NestedExpr ¶ added in v0.0.7
type NestedExpr struct {
// contains filtered or unexported fields
}
func (NestedExpr) String ¶ added in v0.0.7
func (e NestedExpr) String() string
type PageOptions ¶ added in v0.0.7
type QueryDB ¶ added in v0.0.7
type QueryDB struct { DB *DB From string OrderClauses []OrderBy WhereClauses []WhereClause WhereValues []any }
func (QueryDB) Count ¶ added in v0.2.0
Counts the number of records in the table. This is intended to be used in conjunction with .Page.
func (QueryDB) Get ¶ added in v0.0.7
Get a record by ID. This will ignore any previous calls to .Where and .OrWhere
func (QueryDB) OrWhereExpr ¶ added in v0.0.7
func (QueryDB) Page ¶ added in v0.2.0
func (q QueryDB) Page(options PageOptions, v any) error
Selects a page of data from the given table. The options parameter allows you to specify the page, page size and order by clauses. The results will be marshalled into the v slice of structs. v must be a pointer to a slice of structs.
type SimpleExpr ¶ added in v0.0.7
type SimpleExpr struct {
// contains filtered or unexported fields
}
func (SimpleExpr) String ¶ added in v0.0.7
func (e SimpleExpr) String() string