Documentation ¶
Overview ¶
Example (Bind_receivers) ¶
type B struct { F3 string `orm:"f3"` F4 *string `orm:"?f4"` } type A struct { F1 int `orm:"f1"` F2 string `orm:"f2"` B B `orm:"?"` F5 string `orm:"?f5"` F6 float32 `orm:"?f6"` F7 string `orm:"f7|f8"` } t := Table{ Name: "t", columns: nameset{ "f1": {}, "f2": {}, "f3": {}, "f5": {}, "f8": {}, }, } v := &A{} bb, err := t.bind_receivers(v) if err == nil { fmt.Printf("ss: %v\n", bb.selectors) }
Output: ss: [f1 f2 f3 f5 f8]
Index ¶
- Variables
- func GetTables(src Querier, table_names ...string) (tt map[string]*Table, err error)
- func Select[T any](src Querier, table *Table, opts Options, on_row func(t *T) error) error
- func SelectToSlice[S ~[]*T, T any](src Querier, table *Table, opts Options, dst *S) error
- func Selector[T any](src Querier, table *Table) (func(opts Options, callback func(t *T) error) error, error)
- type Condition
- type ErrMissingColumns
- type ErrMissingTables
- type Options
- type Querier
- type Table
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrEmptyTableSchema = errors.New("empty table schema")
View Source
var ErrNoBindingsProduced = errors.New("failed to produce any field bindings")
View Source
var ErrTableDoesNotExist = errors.New("table does not exist")
Functions ¶
func GetTables ¶ added in v0.2.0
GetTables queries the set of tables from src.
Prefix table name with ? to make it optional.
func Select ¶ added in v0.2.0
Select enumerates table rows mapping its columns to fields in struct T.
T needs to have its fields tagged with orm attributes:
- use `orm:"fieldname"` for mandatory fields
- use `orm:"?fieldname"` for optional fields
- use `orm:"fieldname|alternative"` to match a field to any of the specified columns
- use `orm:"!"` for structural child filds to link to their fields
- use `orm:"?"` for structural child filds to optionally link to their fields
Special cases:
- use `orm:"$fieldname"` or `orm:"$?fieldname"` to bind nullable string fields to non-pointer string receivers, this generates conditional sql binding in the form: `(case when fieldname notnull then fieldname else "" end)`
func SelectToSlice ¶ added in v0.2.0
SelectToSlice appends results of Select enumeration to dst
Types ¶
type ErrMissingColumns ¶ added in v0.2.0
type ErrMissingColumns []string
ErrMissingColumns is a list of column names that can be used as the 'missing columns' error.
func (ErrMissingColumns) Error ¶ added in v0.2.0
func (e ErrMissingColumns) Error() string
type ErrMissingTables ¶ added in v0.2.0
type ErrMissingTables []string
ErrMissingTables is a list of table names that can be used as the 'missing tables' error.
func (ErrMissingTables) Error ¶ added in v0.2.0
func (e ErrMissingTables) Error() string
type Querier ¶
Querier is a generic db query runner, typically should be hooked to sql.Tx or sql.DB.
Click to show internal directories.
Click to hide internal directories.