Documentation ¶
Index ¶
- Constants
- Variables
- func DescField(idx *index.Index, field string) bool
- func NewIter(m driver.Model, d driver.Driver, r *sql.Rows, err error) driver.Iter
- type Backend
- type Constraint
- type ConstraintType
- type DB
- func (d *DB) Backend() Backend
- func (d *DB) Begin() (*DB, error)
- func (d *DB) Close() error
- func (d *DB) Commit() error
- func (d *DB) DB() *sql.DB
- func (d *DB) Driver() *Driver
- func (d *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (d *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (d *DB) QueryRow(query string, args ...interface{}) *sql.Row
- func (d *DB) QuoteIdentifier(s string) string
- func (d *DB) QuoteString(s string) string
- func (d *DB) Rollback() error
- type Driver
- func (d *Driver) Begin() (driver.Tx, error)
- func (d *Driver) Capabilities() driver.Capability
- func (d *Driver) Check() error
- func (d *Driver) Close() error
- func (d *Driver) Commit() error
- func (d *Driver) Connection() interface{}
- func (d *Driver) Count(m driver.Model, q query.Q, limit int, offset int) (uint64, error)
- func (d *Driver) DB() *DB
- func (d *Driver) Delete(m driver.Model, q query.Q) (driver.Result, error)
- func (d *Driver) Exists(m driver.Model, q query.Q) (bool, error)
- func (d *Driver) HasFunc(fname string, retType reflect.Type) bool
- func (d *Driver) Initialize(ms []driver.Model) error
- func (d *Driver) Insert(m driver.Model, data interface{}) (driver.Result, error)
- func (d *Driver) Operate(m driver.Model, q query.Q, ops []*operation.Operation) (driver.Result, error)
- func (d *Driver) Query(m driver.Model, q query.Q, sort []driver.Sort, limit int, offset int) driver.Iter
- func (d *Driver) Rollback() error
- func (d *Driver) Select(fields []string, quote bool, m driver.Model, q query.Q, sort []driver.Sort, ...) (*bytes.Buffer, []interface{}, error)
- func (d *Driver) SelectStmt(buf *bytes.Buffer, params *[]interface{}, fields []string, quote bool, ...) error
- func (d *Driver) SetLogger(logger *log.Logger)
- func (d *Driver) Tags() []string
- func (d *Driver) Transaction(f func(driver.Driver) error) error
- func (d *Driver) Update(m driver.Model, q query.Q, data interface{}) (driver.Result, error)
- func (d *Driver) Upsert(m driver.Model, q query.Q, data interface{}) (driver.Result, error)
- func (d *Driver) Upserts() bool
- type Executor
- type Field
- func (f *Field) AddConstraint(ct ConstraintType)
- func (f *Field) AddOption(opt FieldOption)
- func (f *Field) Constraint(ct ConstraintType) *Constraint
- func (f *Field) Copy() *Field
- func (f *Field) HasOption(opt FieldOption) bool
- func (f *Field) SQL(db *DB, m driver.Model, table *Table) (string, []string, error)
- type FieldOption
- type Iter
- type Kind
- type Queryier
- type Reference
- type SqlBackend
- func (b *SqlBackend) AddFields(db *DB, m driver.Model, prevTable *Table, newTable *Table, fields []*Field) error
- func (b *SqlBackend) AlterField(db *DB, m driver.Model, table *Table, oldField *Field, newField *Field) error
- func (b *SqlBackend) Capabilities() driver.Capability
- func (b *SqlBackend) Check(_ *DB) error
- func (b *SqlBackend) DefaultValues() string
- func (b *SqlBackend) DefineField(db *DB, m driver.Model, table *Table, f *Field) (string, []string, error)
- func (b *SqlBackend) Func(fname string, retType reflect.Type) (string, error)
- func (b *SqlBackend) IdentifierQuote() byte
- func (b *SqlBackend) Insert(db *DB, m driver.Model, query string, args ...interface{}) (driver.Result, error)
- func (b *SqlBackend) Inspect(db *DB, m driver.Model, schema string) (*Table, error)
- func (b *SqlBackend) Placeholder(n int) string
- func (b *SqlBackend) Placeholders(n int) string
- func (b *SqlBackend) ScanBool(val bool, goVal *reflect.Value, t *structs.Tag) error
- func (b *SqlBackend) ScanByteSlice(val []byte, goVal *reflect.Value, t *structs.Tag) error
- func (b *SqlBackend) ScanFloat(val float64, goVal *reflect.Value, t *structs.Tag) error
- func (b *SqlBackend) ScanInt(val int64, goVal *reflect.Value, t *structs.Tag) error
- func (b *SqlBackend) ScanString(val string, goVal *reflect.Value, t *structs.Tag) error
- func (b *SqlBackend) ScanTime(val *time.Time, goVal *reflect.Value, t *structs.Tag) error
- func (b *SqlBackend) StringQuote() byte
- func (b *SqlBackend) TransformOutValue(val reflect.Value) (interface{}, error)
- func (b *SqlBackend) Transforms() []reflect.Type
- type Table
Constants ¶
View Source
const ( ConstraintNotNull = 1 + iota ConstraintUnique ConstraintPrimaryKey ConstraintForeignKey )
View Source
const ( KindInvalid = iota KindInteger KindFloat KindDecimal KindChar KindVarchar KindText KindBlob KindTime )
View Source
const (
OptionAutoIncrement = 1 + iota
)
Variables ¶
View Source
var ( ErrNoRows = sql.ErrNoRows ErrFuncNotSupported = errors.New("function not supported") )
Functions ¶
Types ¶
type Backend ¶
type Backend interface { // Check performs any required sanity checks on the connection. Check(*DB) error // Name passsed to database/sql.Open Name() string // Tag returns the struct tag read by this backend Tag() string // Capabilities returns the backend capabilities not provided // by the SQL driver itself. Capabilities() driver.Capability // Placeholder returns the placeholder for the n'th position Placeholder(int) string // Placeholders returns a placeholders string for the given number if parameters Placeholders(int) string // StringQuote returns the character used for quoting strings. StringQuote() byte // IdentifierQuote returns the character used for quoting identifiers. IdentifierQuote() byte // Func returns the function which corresponds to the given name and // return type at the database level. Func(string, reflect.Type) (string, error) // DefaultValues returns the string used to signal that a INSERT has no provided // values and the default ones should be used. DefaultValues() string // Inspect returns the table as it exists in the database for the current model. If // the table does not exist, the Backend is expected to return (nil, nil). Inspect(*DB, driver.Model) (*Table, error) // HasIndex returns wheter an index exists using the provided model, index and name. HasIndex(*DB, driver.Model, *index.Index, string) (bool, error) // DefineField returns the complete field definition as a string, including name, type, options... // Field constraints are returned in the secon argument, each constraint should be an item in the // returned slice. DefineField(*DB, driver.Model, *Table, *Field) (string, []string, error) // AddFields adds the given field to the table for the given model. prevTable is the result // of Inspect() on the previous table, while newTable is generated from the model definition. AddFields(db *DB, m driver.Model, prevTable *Table, newTable *Table, fields []*Field) error // Alter field changes oldField to newField, potentially including the name. AlterField(db *DB, m driver.Model, table *Table, oldField *Field, newField *Field) error // Insert performs an insert on the given database for the given model fields. // Most drivers should just return db.Exec(query, args...). Insert(*DB, driver.Model, string, ...interface{}) (driver.Result, error) // Returns the db type of the given field (e.g. INTEGER) FieldType(reflect.Type, *structs.Tag) (string, error) // Types that need to be transformed (e.g. sqlite transforms time.Time and bool to integer) Transforms() []reflect.Type // Scan an int64 from the db to Go ScanInt(val int64, goVal *reflect.Value, t *structs.Tag) error // Scan a float64 from the db to Go ScanFloat(val float64, goVal *reflect.Value, t *structs.Tag) error // Scan a bool from the db to Go ScanBool(val bool, goVal *reflect.Value, t *structs.Tag) error // Scan a []byte from the db to Go ScanByteSlice(val []byte, goVal *reflect.Value, t *structs.Tag) error // Scan a string from the db to Go ScanString(val string, goVal *reflect.Value, t *structs.Tag) error // Scan a *time.Time from the db to Go ScanTime(val *time.Time, goVal *reflect.Value, t *structs.Tag) error // Transform a value from Go to the database TransformOutValue(reflect.Value) (interface{}, error) }
Backend is the interface implemented by drivers for database/sql orm backends
type Constraint ¶
type Constraint struct { Type ConstraintType References Reference }
func (*Constraint) String ¶
func (c *Constraint) String() string
type ConstraintType ¶
type ConstraintType int
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) QuoteIdentifier ¶
func (*DB) QuoteString ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
func (*Driver) Capabilities ¶
func (d *Driver) Capabilities() driver.Capability
func (*Driver) Connection ¶
func (d *Driver) Connection() interface{}
func (*Driver) SelectStmt ¶
type Field ¶
type Field struct { Name string Type string Default string Options []FieldOption Constraints []*Constraint }
func (*Field) AddConstraint ¶
func (f *Field) AddConstraint(ct ConstraintType)
func (*Field) AddOption ¶
func (f *Field) AddOption(opt FieldOption)
func (*Field) Constraint ¶
func (f *Field) Constraint(ct ConstraintType) *Constraint
func (*Field) HasOption ¶
func (f *Field) HasOption(opt FieldOption) bool
type FieldOption ¶
type FieldOption int
type SqlBackend ¶
type SqlBackend struct { }
func (*SqlBackend) AlterField ¶
func (*SqlBackend) Capabilities ¶
func (b *SqlBackend) Capabilities() driver.Capability
func (*SqlBackend) Check ¶
func (b *SqlBackend) Check(_ *DB) error
func (*SqlBackend) DefaultValues ¶
func (b *SqlBackend) DefaultValues() string
func (*SqlBackend) DefineField ¶
func (*SqlBackend) IdentifierQuote ¶
func (b *SqlBackend) IdentifierQuote() byte
func (*SqlBackend) Placeholder ¶
func (b *SqlBackend) Placeholder(n int) string
func (*SqlBackend) Placeholders ¶
func (b *SqlBackend) Placeholders(n int) string
func (*SqlBackend) ScanByteSlice ¶
func (*SqlBackend) ScanString ¶
func (*SqlBackend) StringQuote ¶
func (b *SqlBackend) StringQuote() byte
func (*SqlBackend) TransformOutValue ¶
func (b *SqlBackend) TransformOutValue(val reflect.Value) (interface{}, error)
func (*SqlBackend) Transforms ¶
func (b *SqlBackend) Transforms() []reflect.Type
Click to show internal directories.
Click to hide internal directories.