Documentation ¶
Overview ¶
Package orm provide ORM for MySQL/PostgreSQL/sqlite Simple Usage
package main import ( "fmt" "github.com/lei006/beego/client/orm" _ "github.com/go-sql-driver/mysql" // import your used driver ) // Model Struct type User struct { Id int `orm:"auto"` Name string `orm:"size(100)"` } func init() { orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30) } func main() { o := orm.NewOrm() user := User{Name: "slene"} // insert id, err := o.Insert(&user) // update user.Name = "astaxie" num, err := o.Update(&user) // read one u := User{Id: user.Id} err = o.Read(&u) // delete num, err = o.Delete(&u) }
Index ¶
- Constants
- Variables
- func AddAliasWthDB(aliasName, driverName string, db *sql.DB, params ...DBOption) error
- func AddGlobalFilterChain(filterChain ...FilterChain)
- func BootStrap()
- func ColValue(opt operator, value interface{}) interface{}
- func GetDB(aliasNames ...string) (*sql.DB, error)
- func NewLog(out io.Writer) *logs.Log
- func RegisterDataBase(aliasName, driverName, dataSource string, params ...DBOption) error
- func RegisterDriver(driverName string, typ DriverType) error
- func RegisterModel(models ...interface{})
- func RegisterModelWithPrefix(prefix string, models ...interface{})
- func RegisterModelWithSuffix(suffix string, models ...interface{})
- func ResetModelCache()
- func RunCommand()
- func RunSyncdb(name string, force bool, verbose bool) error
- func SetDataBaseTZ(aliasName string, tz *time.Location) error
- func SetMaxIdleConns(aliasName string, maxIdleConns int)
- func SetMaxOpenConns(aliasName string, maxOpenConns int)
- func SetNameStrategy(s string)
- type BigIntegerField
- type BooleanField
- type CharField
- type Condition
- func (c Condition) And(expr string, args ...interface{}) *Condition
- func (c *Condition) AndCond(cond *Condition) *Condition
- func (c Condition) AndNot(expr string, args ...interface{}) *Condition
- func (c *Condition) AndNotCond(cond *Condition) *Condition
- func (c *Condition) IsEmpty() bool
- func (c Condition) Or(expr string, args ...interface{}) *Condition
- func (c *Condition) OrCond(cond *Condition) *Condition
- func (c Condition) OrNot(expr string, args ...interface{}) *Condition
- func (c *Condition) OrNotCond(cond *Condition) *Condition
- func (c Condition) Raw(expr string, sql string) *Condition
- type DB
- func (d *DB) Begin() (*sql.Tx, error)
- func (d *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
- func (d *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (d *DB) Prepare(query string) (*sql.Stmt, error)
- func (d *DB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (d *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (d *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (d *DB) QueryRow(query string, args ...interface{}) *sql.Row
- func (d *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- type DBOption
- type DML
- type DQL
- type DateField
- type DateTimeField
- type DoNothingOrm
- func (d *DoNothingOrm) Begin() (TxOrmer, error)
- func (d *DoNothingOrm) BeginWithCtx(ctx context.Context) (TxOrmer, error)
- func (d *DoNothingOrm) BeginWithCtxAndOpts(ctx context.Context, opts *sql.TxOptions) (TxOrmer, error)
- func (d *DoNothingOrm) BeginWithOpts(opts *sql.TxOptions) (TxOrmer, error)
- func (d *DoNothingOrm) DBStats() *sql.DBStats
- func (d *DoNothingOrm) Delete(md interface{}, cols ...string) (int64, error)
- func (d *DoNothingOrm) DeleteWithCtx(ctx context.Context, md interface{}, cols ...string) (int64, error)
- func (d *DoNothingOrm) DoTx(task func(ctx context.Context, txOrm TxOrmer) error) error
- func (d *DoNothingOrm) DoTxWithCtx(ctx context.Context, task func(ctx context.Context, txOrm TxOrmer) error) error
- func (d *DoNothingOrm) DoTxWithCtxAndOpts(ctx context.Context, opts *sql.TxOptions, ...) error
- func (d *DoNothingOrm) DoTxWithOpts(opts *sql.TxOptions, task func(ctx context.Context, txOrm TxOrmer) error) error
- func (d *DoNothingOrm) Driver() Driver
- func (d *DoNothingOrm) Insert(md interface{}) (int64, error)
- func (d *DoNothingOrm) InsertMulti(bulk int, mds interface{}) (int64, error)
- func (d *DoNothingOrm) InsertMultiWithCtx(ctx context.Context, bulk int, mds interface{}) (int64, error)
- func (d *DoNothingOrm) InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64, error)
- func (d *DoNothingOrm) InsertOrUpdateWithCtx(ctx context.Context, md interface{}, colConflitAndArgs ...string) (int64, error)
- func (d *DoNothingOrm) InsertWithCtx(ctx context.Context, md interface{}) (int64, error)
- func (d *DoNothingOrm) LoadRelated(md interface{}, name string, args ...utils.KV) (int64, error)
- func (d *DoNothingOrm) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...utils.KV) (int64, error)
- func (d *DoNothingOrm) QueryM2M(md interface{}, name string) QueryM2Mer
- func (d *DoNothingOrm) QueryM2MWithCtx(ctx context.Context, md interface{}, name string) QueryM2Mer
- func (d *DoNothingOrm) QueryTable(ptrStructOrTableName interface{}) QuerySeter
- func (d *DoNothingOrm) QueryTableWithCtx(ctx context.Context, ptrStructOrTableName interface{}) QuerySeter
- func (d *DoNothingOrm) Raw(query string, args ...interface{}) RawSeter
- func (d *DoNothingOrm) RawWithCtx(ctx context.Context, query string, args ...interface{}) RawSeter
- func (d *DoNothingOrm) Read(md interface{}, cols ...string) error
- func (d *DoNothingOrm) ReadForUpdate(md interface{}, cols ...string) error
- func (d *DoNothingOrm) ReadForUpdateWithCtx(ctx context.Context, md interface{}, cols ...string) error
- func (d *DoNothingOrm) ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, int64, error)
- func (d *DoNothingOrm) ReadOrCreateWithCtx(ctx context.Context, md interface{}, col1 string, cols ...string) (bool, int64, error)
- func (d *DoNothingOrm) ReadWithCtx(ctx context.Context, md interface{}, cols ...string) error
- func (d *DoNothingOrm) Update(md interface{}, cols ...string) (int64, error)
- func (d *DoNothingOrm) UpdateWithCtx(ctx context.Context, md interface{}, cols ...string) (int64, error)
- type DoNothingTxOrm
- type Driver
- type DriverGetter
- type DriverType
- type Fielder
- type Filter
- type FilterChain
- type FloatField
- type Inserter
- type IntegerField
- type Invocation
- type IsApplicableTableForDB
- type JSONField
- type JsonbField
- type Log
- type MySQLQueryBuilder
- func (qb *MySQLQueryBuilder) And(cond string) QueryBuilder
- func (qb *MySQLQueryBuilder) Asc() QueryBuilder
- func (qb *MySQLQueryBuilder) Delete(tables ...string) QueryBuilder
- func (qb *MySQLQueryBuilder) Desc() QueryBuilder
- func (qb *MySQLQueryBuilder) ForUpdate() QueryBuilder
- func (qb *MySQLQueryBuilder) From(tables ...string) QueryBuilder
- func (qb *MySQLQueryBuilder) GroupBy(fields ...string) QueryBuilder
- func (qb *MySQLQueryBuilder) Having(cond string) QueryBuilder
- func (qb *MySQLQueryBuilder) In(vals ...string) QueryBuilder
- func (qb *MySQLQueryBuilder) InnerJoin(table string) QueryBuilder
- func (qb *MySQLQueryBuilder) InsertInto(table string, fields ...string) QueryBuilder
- func (qb *MySQLQueryBuilder) LeftJoin(table string) QueryBuilder
- func (qb *MySQLQueryBuilder) Limit(limit int) QueryBuilder
- func (qb *MySQLQueryBuilder) Offset(offset int) QueryBuilder
- func (qb *MySQLQueryBuilder) On(cond string) QueryBuilder
- func (qb *MySQLQueryBuilder) Or(cond string) QueryBuilder
- func (qb *MySQLQueryBuilder) OrderBy(fields ...string) QueryBuilder
- func (qb *MySQLQueryBuilder) RightJoin(table string) QueryBuilder
- func (qb *MySQLQueryBuilder) Select(fields ...string) QueryBuilder
- func (qb *MySQLQueryBuilder) Set(kv ...string) QueryBuilder
- func (qb *MySQLQueryBuilder) String() string
- func (qb *MySQLQueryBuilder) Subquery(sub string, alias string) string
- func (qb *MySQLQueryBuilder) Update(tables ...string) QueryBuilder
- func (qb *MySQLQueryBuilder) Values(vals ...string) QueryBuilder
- func (qb *MySQLQueryBuilder) Where(cond string) QueryBuilder
- type Ormer
- type Params
- type ParamsList
- type PositiveBigIntegerField
- type PositiveIntegerField
- type PositiveSmallIntegerField
- type PostgresQueryBuilder
- func (qb *PostgresQueryBuilder) And(cond string) QueryBuilder
- func (qb *PostgresQueryBuilder) Asc() QueryBuilder
- func (qb *PostgresQueryBuilder) Delete(tables ...string) QueryBuilder
- func (qb *PostgresQueryBuilder) Desc() QueryBuilder
- func (qb *PostgresQueryBuilder) ForUpdate() QueryBuilder
- func (qb *PostgresQueryBuilder) From(tables ...string) QueryBuilder
- func (qb *PostgresQueryBuilder) GroupBy(fields ...string) QueryBuilder
- func (qb *PostgresQueryBuilder) Having(cond string) QueryBuilder
- func (qb *PostgresQueryBuilder) In(vals ...string) QueryBuilder
- func (qb *PostgresQueryBuilder) InnerJoin(table string) QueryBuilder
- func (qb *PostgresQueryBuilder) InsertInto(table string, fields ...string) QueryBuilder
- func (qb *PostgresQueryBuilder) LeftJoin(table string) QueryBuilder
- func (qb *PostgresQueryBuilder) Limit(limit int) QueryBuilder
- func (qb *PostgresQueryBuilder) Offset(offset int) QueryBuilder
- func (qb *PostgresQueryBuilder) On(cond string) QueryBuilder
- func (qb *PostgresQueryBuilder) Or(cond string) QueryBuilder
- func (qb *PostgresQueryBuilder) OrderBy(fields ...string) QueryBuilder
- func (qb *PostgresQueryBuilder) RightJoin(table string) QueryBuilder
- func (qb *PostgresQueryBuilder) Select(fields ...string) QueryBuilder
- func (qb *PostgresQueryBuilder) Set(kv ...string) QueryBuilder
- func (qb *PostgresQueryBuilder) String() string
- func (qb *PostgresQueryBuilder) Subquery(sub string, alias string) string
- func (qb *PostgresQueryBuilder) Update(tables ...string) QueryBuilder
- func (qb *PostgresQueryBuilder) Values(vals ...string) QueryBuilder
- func (qb *PostgresQueryBuilder) Where(cond string) QueryBuilder
- type QueryBuilder
- type QueryExecutor
- type QueryM2Mer
- type QuerySeter
- type RawPreparer
- type RawSeter
- type SmallIntegerField
- type StrTo
- type TableEngineI
- type TableIndexI
- type TableNameI
- type TableUniqueI
- type TextField
- type TiDBQueryBuilder
- type TimeField
- type TxBeginner
- type TxCommitter
- type TxDB
- func (t *TxDB) Commit() error
- func (t *TxDB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (t *TxDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (t *TxDB) Prepare(query string) (*sql.Stmt, error)
- func (t *TxDB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (t *TxDB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (t *TxDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (t *TxDB) QueryRow(query string, args ...interface{}) *sql.Row
- func (t *TxDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (t *TxDB) Rollback() error
- func (t *TxDB) RollbackUnlessCommit() error
- type TxOrmer
Constants ¶
const ( TypeBooleanField = models.TypeBooleanField TypeVarCharField = models.TypeVarCharField TypeCharField = models.TypeCharField TypeTextField = models.TypeTextField TypeTimeField = models.TypeTimeField TypeDateField = models.TypeDateField TypeDateTimeField = models.TypeDateTimeField TypeBitField = models.TypeBitField TypeSmallIntegerField = models.TypeSmallIntegerField TypeIntegerField = models.TypeIntegerField TypeBigIntegerField = models.TypeBigIntegerField TypePositiveBitField = models.TypePositiveBitField TypePositiveSmallIntegerField = models.TypePositiveSmallIntegerField TypePositiveIntegerField = models.TypePositiveIntegerField TypePositiveBigIntegerField = models.TypePositiveBigIntegerField TypeFloatField = models.TypeFloatField TypeDecimalField = models.TypeDecimalField TypeJSONField = models.TypeJSONField TypeJsonbField = models.TypeJsonbField RelForeignKey = models.RelForeignKey RelOneToOne = models.RelOneToOne RelManyToMany = models.RelManyToMany RelReverseOne = models.RelReverseOne RelReverseMany = models.RelReverseMany )
Define the Type enum
const ( IsIntegerField = models.IsIntegerField IsPositiveIntegerField = models.IsPositiveIntegerField IsRelField = models.IsRelField IsFieldType = models.IsFieldType )
Define some logic enum
const ( ColAdd operator = iota ColMinus ColMultiply ColExcept ColBitAnd ColBitRShift ColBitLShift ColBitXOR ColBitOr )
define Col operations
const CommaSpace = ", "
CommaSpace is the separation
const (
DebugQueries = iota
)
DebugQueries define the debug
const (
ExprSep = clauses.ExprSep
)
ExprSep define the expression separation
const (
TxNameKey = "TxName"
)
Variables ¶
var ( Debug = false DebugLog = NewLog(os.Stdout) DefaultRowsLimit = -1 DefaultRelsDepth = 2 DefaultTimeLoc = iutils.DefaultTimeLoc ErrTxDone = errors.New("<TxOrmer.Commit/Rollback> transaction already done") ErrMultiRows = errors.New("<QuerySeter> return multi rows") ErrNoRows = errors.New("<QuerySeter> no row found") ErrStmtClosed = errors.New("<QuerySeter> stmt already closed") ErrArgs = errors.New("<Ormer> args error may be empty") ErrNotImplement = errors.New("have not implement") )
Define common vars
var ErrMissPK = errors.New("missed pk value")
ErrMissPK missing pk error
var LogFunc func(query map[string]interface{})
LogFunc costomer log func
Functions ¶
func AddAliasWthDB ¶
AddAliasWthDB add a aliasName for the drivename
func AddGlobalFilterChain ¶
func AddGlobalFilterChain(filterChain ...FilterChain)
AddGlobalFilterChain adds a new FilterChain All orm instances built after this invocation will use this filterChain, but instances built before this invocation will not be affected
func BootStrap ¶
func BootStrap()
BootStrap Bootstrap models. make All model parsed and can not add more models
func ColValue ¶
func ColValue(opt operator, value interface{}) interface{}
ColValue do the field raw changes. e.g Nums = Nums + 10. usage:
Params{ "Nums": ColValue(Col_Add, 10), }
func GetDB ¶
GetDB Get *sql.DB from registered database by db alias name. Use "default" as alias name if you not Set.
func RegisterDataBase ¶
RegisterDataBase Setting the database connect params. Use the database driver self dataSource args.
func RegisterDriver ¶
func RegisterDriver(driverName string, typ DriverType) error
RegisterDriver Register a database driver use specify driver name, this can be definition the driver is which database type.
func RegisterModelWithPrefix ¶
func RegisterModelWithPrefix(prefix string, models ...interface{})
RegisterModelWithPrefix Register models with a prefix
func RegisterModelWithSuffix ¶
func RegisterModelWithSuffix(suffix string, models ...interface{})
RegisterModelWithSuffix Register models with a suffix
func ResetModelCache ¶
func ResetModelCache()
ResetModelCache Clean model cache. Then you can re-RegisterModel. Common use this api for test case.
func RunCommand ¶
func RunCommand()
RunCommand listens for orm command and runs if command arguments have been passed.
func RunSyncdb ¶
RunSyncdb run syncdb command line. name: Table's alias name (default is "default") force: Run the next sql command even if the current gave an error verbose: Print All information, useful for debugging
func SetDataBaseTZ ¶
SetDataBaseTZ Change the database default used timezone
func SetMaxIdleConns ¶
SetMaxIdleConns Change the max idle conns for *sql.DB, use specify database alias name Deprecated you should not use this, we will remove it in the future
func SetMaxOpenConns ¶
SetMaxOpenConns Change the max open conns for *sql.DB, use specify database alias name Deprecated you should not use this, we will remove it in the future
func SetNameStrategy ¶
func SetNameStrategy(s string)
Types ¶
type BigIntegerField ¶
type BigIntegerField = models.BigIntegerField
BigIntegerField -9223372036854775808 to 9223372036854775807.
type CharField ¶
CharField A string field required values tag: size The size is enforced at the database level and in models’s validation. eg: `orm:"size(120)"`
type Condition ¶
type Condition struct {
// contains filtered or unexported fields
}
Condition struct. work for WHERE conditions.
func (*Condition) AndNotCond ¶
AndNotCond combine an AND NOT condition to current condition
type DB ¶
func (*DB) ExecContext ¶
func (*DB) PrepareContext ¶
func (*DB) QueryContext ¶
type DBOption ¶
type DBOption func(al *alias)
func ConnMaxIdletime ¶
ConnMaxIdletime return a hint about ConnMaxIdletime
func ConnMaxLifetime ¶
ConnMaxLifetime return a hint about ConnMaxLifetime
func MaxIdleConnections ¶
MaxIdleConnections return a hint about MaxIdleConnections
func MaxOpenConnections ¶
MaxOpenConnections return a hint about MaxOpenConnections
func MaxStmtCacheSize ¶
MaxStmtCacheSize return a hint about MaxStmtCacheSize
type DML ¶
type DML interface { // Insert insert model data to database // for example: // user := new(User) // id, err = Ormer.Insert(user) // user must be a pointer and Insert will Set user's pk field Insert(md interface{}) (int64, error) InsertWithCtx(ctx context.Context, md interface{}) (int64, error) // InsertOrUpdate mysql:InsertOrUpdate(model) or InsertOrUpdate(model,"colu=colu+value") // if colu type is integer : can use(+-*/), string : convert(colu,"value") // postgres: InsertOrUpdate(model,"conflictColumnName") or InsertOrUpdate(model,"conflictColumnName","colu=colu+value") // if colu type is integer : can use(+-*/), string : colu || "value" InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64, error) InsertOrUpdateWithCtx(ctx context.Context, md interface{}, colConflitAndArgs ...string) (int64, error) // InsertMulti inserts some models to database InsertMulti(bulk int, mds interface{}) (int64, error) InsertMultiWithCtx(ctx context.Context, bulk int, mds interface{}) (int64, error) // Update updates model to database. // cols Set the Columns those want to update. // find model by Id(pk) field and update Columns specified by Fields, if cols is null then update All Columns // for example: // user := User{Id: 2} // user.Langs = append(user.Langs, "zh-CN", "en-US") // user.Extra.Name = "beego" // user.Extra.Data = "orm" // num, err = Ormer.Update(&user, "Langs", "Extra") Update(md interface{}, cols ...string) (int64, error) UpdateWithCtx(ctx context.Context, md interface{}, cols ...string) (int64, error) // Delete deletes model in database Delete(md interface{}, cols ...string) (int64, error) DeleteWithCtx(ctx context.Context, md interface{}, cols ...string) (int64, error) // Raw return a raw query seter for raw sql string. // for example: // ormer.Raw("UPDATE `user` SET `user_name` = ? WHERE `user_name` = ?", "slene", "testing").Exec() // // update user testing's name to slene Raw(query string, args ...interface{}) RawSeter RawWithCtx(ctx context.Context, query string, args ...interface{}) RawSeter }
DML Data Manipulation Language
type DQL ¶
type DQL interface { // Read reads data to model // for example: // this will find User by Id field // u = &User{Id: user.Id} // err = Ormer.Read(u) // this will find User by UserName field // u = &User{UserName: "astaxie", Password: "pass"} // err = Ormer.Read(u, "UserName") Read(md interface{}, cols ...string) error ReadWithCtx(ctx context.Context, md interface{}, cols ...string) error // ReadForUpdate Like Read(), but with "FOR UPDATE" clause, useful in transaction. // Some databases are not support this feature. ReadForUpdate(md interface{}, cols ...string) error ReadForUpdateWithCtx(ctx context.Context, md interface{}, cols ...string) error // ReadOrCreate Try to read a row from the database, or insert one if it doesn't exist ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, int64, error) ReadOrCreateWithCtx(ctx context.Context, md interface{}, col1 string, cols ...string) (bool, int64, error) // LoadRelated load related models to md model. // args are limit, offset int and order string. // // example: // Ormer.LoadRelated(post,"Tags") // for _,tag := range post.Tags{...} // hints.DefaultRelDepth useDefaultRelsDepth ; or depth 0 // hints.RelDepth loadRelationDepth // hints.Limit limit default limit 1000 // hints.Offset int offset default offset 0 // hints.OrderBy string order for example : "-Id" // make sure the relation is defined in model struct tags. LoadRelated(md interface{}, name string, args ...utils.KV) (int64, error) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...utils.KV) (int64, error) // QueryM2M create a models to models queryer // for example: // post := Post{Id: 4} // m2m := Ormer.QueryM2M(&post, "Tags") QueryM2M(md interface{}, name string) QueryM2Mer // QueryM2MWithCtx NOTE: this method is deprecated, context parameter will not take effect. // Use context.Context directly on methods with `WithCtx` suffix such as InsertWithCtx/UpdateWithCtx QueryM2MWithCtx(ctx context.Context, md interface{}, name string) QueryM2Mer // QueryTable return a QuerySeter for table operations. // table name can be string or struct. // e.g. QueryTable("user"), QueryTable(&user{}) or QueryTable((*User)(nil)), QueryTable(ptrStructOrTableName interface{}) QuerySeter // QueryTableWithCtx NOTE: this method is deprecated, context parameter will not take effect. // Use context.Context directly on methods with `WithCtx` suffix such as InsertWithCtx/UpdateWithCtx QueryTableWithCtx(ctx context.Context, ptrStructOrTableName interface{}) QuerySeter DBStats() *sql.DBStats }
DQL Data Query Language
type DateField ¶
DateField A date, represented in go by a time.Time instance. only date values like 2006-01-02 Has a few extra, optional attr tag:
auto_now: Automatically Set the field to now every time the object is saved. Useful for “last-modified” timestamps. Note that the current date is always used; it’s not just a default value that you can override.
auto_now_add: Automatically Set the field to now when the object is first created. Useful for creation of timestamps. Note that the current date is always used; it’s not just a default value that you can override.
eg: `orm:"auto_now"` or `orm:"auto_now_add"`
type DateTimeField ¶
type DateTimeField = models.DateTimeField
DateTimeField A date, represented in go by a time.Time instance. datetime values like 2006-01-02 15:04:05 Takes the same extra arguments as DateField.
type DoNothingOrm ¶
type DoNothingOrm struct{}
func (*DoNothingOrm) Begin ¶
func (d *DoNothingOrm) Begin() (TxOrmer, error)
func (*DoNothingOrm) BeginWithCtx ¶
func (d *DoNothingOrm) BeginWithCtx(ctx context.Context) (TxOrmer, error)
func (*DoNothingOrm) BeginWithCtxAndOpts ¶
func (*DoNothingOrm) BeginWithOpts ¶
func (d *DoNothingOrm) BeginWithOpts(opts *sql.TxOptions) (TxOrmer, error)
func (*DoNothingOrm) DBStats ¶
func (d *DoNothingOrm) DBStats() *sql.DBStats
func (*DoNothingOrm) Delete ¶
func (d *DoNothingOrm) Delete(md interface{}, cols ...string) (int64, error)
func (*DoNothingOrm) DeleteWithCtx ¶
func (*DoNothingOrm) DoTxWithCtx ¶
func (*DoNothingOrm) DoTxWithCtxAndOpts ¶
func (*DoNothingOrm) DoTxWithOpts ¶
func (*DoNothingOrm) Driver ¶
func (d *DoNothingOrm) Driver() Driver
func (*DoNothingOrm) Insert ¶
func (d *DoNothingOrm) Insert(md interface{}) (int64, error)
func (*DoNothingOrm) InsertMulti ¶
func (d *DoNothingOrm) InsertMulti(bulk int, mds interface{}) (int64, error)
func (*DoNothingOrm) InsertMultiWithCtx ¶
func (*DoNothingOrm) InsertOrUpdate ¶
func (d *DoNothingOrm) InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64, error)
func (*DoNothingOrm) InsertOrUpdateWithCtx ¶
func (*DoNothingOrm) InsertWithCtx ¶
func (d *DoNothingOrm) InsertWithCtx(ctx context.Context, md interface{}) (int64, error)
func (*DoNothingOrm) LoadRelated ¶
func (*DoNothingOrm) LoadRelatedWithCtx ¶
func (*DoNothingOrm) QueryM2M ¶
func (d *DoNothingOrm) QueryM2M(md interface{}, name string) QueryM2Mer
func (*DoNothingOrm) QueryM2MWithCtx ¶
func (d *DoNothingOrm) QueryM2MWithCtx(ctx context.Context, md interface{}, name string) QueryM2Mer
NOTE: this method is deprecated, context parameter will not take effect.
func (*DoNothingOrm) QueryTable ¶
func (d *DoNothingOrm) QueryTable(ptrStructOrTableName interface{}) QuerySeter
func (*DoNothingOrm) QueryTableWithCtx ¶
func (d *DoNothingOrm) QueryTableWithCtx(ctx context.Context, ptrStructOrTableName interface{}) QuerySeter
NOTE: this method is deprecated, context parameter will not take effect.
func (*DoNothingOrm) Raw ¶
func (d *DoNothingOrm) Raw(query string, args ...interface{}) RawSeter
func (*DoNothingOrm) RawWithCtx ¶
func (d *DoNothingOrm) RawWithCtx(ctx context.Context, query string, args ...interface{}) RawSeter
func (*DoNothingOrm) Read ¶
func (d *DoNothingOrm) Read(md interface{}, cols ...string) error
func (*DoNothingOrm) ReadForUpdate ¶
func (d *DoNothingOrm) ReadForUpdate(md interface{}, cols ...string) error
func (*DoNothingOrm) ReadForUpdateWithCtx ¶
func (d *DoNothingOrm) ReadForUpdateWithCtx(ctx context.Context, md interface{}, cols ...string) error
func (*DoNothingOrm) ReadOrCreate ¶
func (*DoNothingOrm) ReadOrCreateWithCtx ¶
func (*DoNothingOrm) ReadWithCtx ¶
func (d *DoNothingOrm) ReadWithCtx(ctx context.Context, md interface{}, cols ...string) error
func (*DoNothingOrm) Update ¶
func (d *DoNothingOrm) Update(md interface{}, cols ...string) (int64, error)
func (*DoNothingOrm) UpdateWithCtx ¶
type DoNothingTxOrm ¶
type DoNothingTxOrm struct {
DoNothingOrm
}
DoNothingTxOrm is similar with DoNothingOrm, usually you use it to test
func (*DoNothingTxOrm) Commit ¶
func (d *DoNothingTxOrm) Commit() error
func (*DoNothingTxOrm) Rollback ¶
func (d *DoNothingTxOrm) Rollback() error
type Driver ¶
type Driver interface { Name() string Type() DriverType }
Driver define database driver
type DriverGetter ¶
type DriverGetter interface {
Driver() Driver
}
type DriverType ¶
type DriverType int
DriverType database driver constant int.
const ( DRMySQL DriverType // mysql DRSqlite // sqlite DROracle // oracle DRPostgres // pgsql DRTiDB // TiDB )
Enum the Database driver
type Filter ¶
type Filter func(ctx context.Context, inv *Invocation) []interface{}
Filter behavior is a little big strange. it's only be called when users call methods of Ormer return value is an array. it's a little bit hard to understand, for example, the Ormer's Read method only return error so the filter processing this method should return an array whose first element is error and, Ormer's ReadOrCreateWithCtx return three values, so the Filter's result should contain three values
type FilterChain ¶
FilterChain is used to build a Filter don't forget to call next(...) inside your Filter
type FloatField ¶
type FloatField = models.FloatField
FloatField A floating-point number represented in go by a float32 value.
type Inserter ¶
type Inserter interface { Insert(interface{}) (int64, error) InsertWithCtx(context.Context, interface{}) (int64, error) Close() error }
Inserter insert prepared statement
type Invocation ¶
type Invocation struct { Method string // Md may be nil in some cases. It depends on method Md interface{} // the args are All arguments except context.Context Args []interface{} // insideTx indicates whether this is inside a transaction InsideTx bool TxStartTime time.Time TxName string // contains filtered or unexported fields }
Invocation represents an "Orm" invocation
func (*Invocation) GetPkFieldName ¶
func (inv *Invocation) GetPkFieldName() string
GetPkFieldName return the primary key of this table if not found, "" is returned
func (*Invocation) GetTableName ¶
func (inv *Invocation) GetTableName() string
type IsApplicableTableForDB ¶
IsApplicableTableForDB if return false, we won't create table to this db
type MySQLQueryBuilder ¶
type MySQLQueryBuilder struct {
// contains filtered or unexported fields
}
MySQLQueryBuilder is the SQL build
func (*MySQLQueryBuilder) And ¶
func (qb *MySQLQueryBuilder) And(cond string) QueryBuilder
And join the and cond
func (*MySQLQueryBuilder) Delete ¶
func (qb *MySQLQueryBuilder) Delete(tables ...string) QueryBuilder
Delete join the Delete tables
func (*MySQLQueryBuilder) Desc ¶
func (qb *MySQLQueryBuilder) Desc() QueryBuilder
Desc join the desc
func (*MySQLQueryBuilder) ForUpdate ¶
func (qb *MySQLQueryBuilder) ForUpdate() QueryBuilder
ForUpdate add the FOR UPDATE clause
func (*MySQLQueryBuilder) From ¶
func (qb *MySQLQueryBuilder) From(tables ...string) QueryBuilder
From join the tables
func (*MySQLQueryBuilder) GroupBy ¶
func (qb *MySQLQueryBuilder) GroupBy(fields ...string) QueryBuilder
GroupBy join the Group by Fields
func (*MySQLQueryBuilder) Having ¶
func (qb *MySQLQueryBuilder) Having(cond string) QueryBuilder
Having join the Having cond
func (*MySQLQueryBuilder) In ¶
func (qb *MySQLQueryBuilder) In(vals ...string) QueryBuilder
In join the IN (vals)
func (*MySQLQueryBuilder) InnerJoin ¶
func (qb *MySQLQueryBuilder) InnerJoin(table string) QueryBuilder
InnerJoin INNER JOIN the table
func (*MySQLQueryBuilder) InsertInto ¶
func (qb *MySQLQueryBuilder) InsertInto(table string, fields ...string) QueryBuilder
InsertInto join the insert SQL
func (*MySQLQueryBuilder) LeftJoin ¶
func (qb *MySQLQueryBuilder) LeftJoin(table string) QueryBuilder
LeftJoin LEFT JOIN the table
func (*MySQLQueryBuilder) Limit ¶
func (qb *MySQLQueryBuilder) Limit(limit int) QueryBuilder
Limit join the limit num
func (*MySQLQueryBuilder) Offset ¶
func (qb *MySQLQueryBuilder) Offset(offset int) QueryBuilder
Offset join the offset num
func (*MySQLQueryBuilder) On ¶
func (qb *MySQLQueryBuilder) On(cond string) QueryBuilder
On join with on cond
func (*MySQLQueryBuilder) Or ¶
func (qb *MySQLQueryBuilder) Or(cond string) QueryBuilder
Or join the or cond
func (*MySQLQueryBuilder) OrderBy ¶
func (qb *MySQLQueryBuilder) OrderBy(fields ...string) QueryBuilder
OrderBy join the Order by Fields
func (*MySQLQueryBuilder) RightJoin ¶
func (qb *MySQLQueryBuilder) RightJoin(table string) QueryBuilder
RightJoin RIGHT JOIN the table
func (*MySQLQueryBuilder) Select ¶
func (qb *MySQLQueryBuilder) Select(fields ...string) QueryBuilder
Select will join the Fields
func (*MySQLQueryBuilder) Set ¶
func (qb *MySQLQueryBuilder) Set(kv ...string) QueryBuilder
Set join the Set kv
func (*MySQLQueryBuilder) String ¶
func (qb *MySQLQueryBuilder) String() string
String join All tokens
func (*MySQLQueryBuilder) Subquery ¶
func (qb *MySQLQueryBuilder) Subquery(sub string, alias string) string
Subquery join the sub as alias
func (*MySQLQueryBuilder) Update ¶
func (qb *MySQLQueryBuilder) Update(tables ...string) QueryBuilder
Update join the update table
func (*MySQLQueryBuilder) Values ¶
func (qb *MySQLQueryBuilder) Values(vals ...string) QueryBuilder
Values join the Values(vals)
func (*MySQLQueryBuilder) Where ¶
func (qb *MySQLQueryBuilder) Where(cond string) QueryBuilder
Where join the Where cond
type Ormer ¶
type Ormer interface { QueryExecutor TxBeginner }
func NewFilterOrmDecorator ¶
func NewFilterOrmDecorator(delegate Ormer, filterChains ...FilterChain) Ormer
func NewOrmUsingDB ¶
NewOrmUsingDB create new orm with the name
type PositiveBigIntegerField ¶
type PositiveBigIntegerField = models.PositiveBigIntegerField
PositiveBigIntegerField 0 to 18446744073709551615
type PositiveIntegerField ¶
type PositiveIntegerField = models.PositiveIntegerField
PositiveIntegerField 0 to 4294967295
type PositiveSmallIntegerField ¶
type PositiveSmallIntegerField = models.PositiveSmallIntegerField
PositiveSmallIntegerField 0 to 65535
type PostgresQueryBuilder ¶
type PostgresQueryBuilder struct {
// contains filtered or unexported fields
}
PostgresQueryBuilder is the SQL build
func (*PostgresQueryBuilder) And ¶
func (qb *PostgresQueryBuilder) And(cond string) QueryBuilder
And join the and cond
func (*PostgresQueryBuilder) Asc ¶
func (qb *PostgresQueryBuilder) Asc() QueryBuilder
Asc join the asc
func (*PostgresQueryBuilder) Delete ¶
func (qb *PostgresQueryBuilder) Delete(tables ...string) QueryBuilder
Delete join the Delete tables
func (*PostgresQueryBuilder) Desc ¶
func (qb *PostgresQueryBuilder) Desc() QueryBuilder
Desc join the desc
func (*PostgresQueryBuilder) ForUpdate ¶
func (qb *PostgresQueryBuilder) ForUpdate() QueryBuilder
ForUpdate add the FOR UPDATE clause
func (*PostgresQueryBuilder) From ¶
func (qb *PostgresQueryBuilder) From(tables ...string) QueryBuilder
From join the tables
func (*PostgresQueryBuilder) GroupBy ¶
func (qb *PostgresQueryBuilder) GroupBy(fields ...string) QueryBuilder
GroupBy join the Group by Fields
func (*PostgresQueryBuilder) Having ¶
func (qb *PostgresQueryBuilder) Having(cond string) QueryBuilder
Having join the Having cond
func (*PostgresQueryBuilder) In ¶
func (qb *PostgresQueryBuilder) In(vals ...string) QueryBuilder
In join the IN (vals)
func (*PostgresQueryBuilder) InnerJoin ¶
func (qb *PostgresQueryBuilder) InnerJoin(table string) QueryBuilder
InnerJoin INNER JOIN the table
func (*PostgresQueryBuilder) InsertInto ¶
func (qb *PostgresQueryBuilder) InsertInto(table string, fields ...string) QueryBuilder
InsertInto join the insert SQL
func (*PostgresQueryBuilder) LeftJoin ¶
func (qb *PostgresQueryBuilder) LeftJoin(table string) QueryBuilder
LeftJoin LEFT JOIN the table
func (*PostgresQueryBuilder) Limit ¶
func (qb *PostgresQueryBuilder) Limit(limit int) QueryBuilder
Limit join the limit num
func (*PostgresQueryBuilder) Offset ¶
func (qb *PostgresQueryBuilder) Offset(offset int) QueryBuilder
Offset join the offset num
func (*PostgresQueryBuilder) On ¶
func (qb *PostgresQueryBuilder) On(cond string) QueryBuilder
On join with on cond
func (*PostgresQueryBuilder) Or ¶
func (qb *PostgresQueryBuilder) Or(cond string) QueryBuilder
Or join the or cond
func (*PostgresQueryBuilder) OrderBy ¶
func (qb *PostgresQueryBuilder) OrderBy(fields ...string) QueryBuilder
OrderBy join the Order by Fields
func (*PostgresQueryBuilder) RightJoin ¶
func (qb *PostgresQueryBuilder) RightJoin(table string) QueryBuilder
RightJoin RIGHT JOIN the table
func (*PostgresQueryBuilder) Select ¶
func (qb *PostgresQueryBuilder) Select(fields ...string) QueryBuilder
Select will join the Fields
func (*PostgresQueryBuilder) Set ¶
func (qb *PostgresQueryBuilder) Set(kv ...string) QueryBuilder
Set join the Set kv
func (*PostgresQueryBuilder) String ¶
func (qb *PostgresQueryBuilder) String() string
String join All tokens
func (*PostgresQueryBuilder) Subquery ¶
func (qb *PostgresQueryBuilder) Subquery(sub string, alias string) string
Subquery join the sub as alias
func (*PostgresQueryBuilder) Update ¶
func (qb *PostgresQueryBuilder) Update(tables ...string) QueryBuilder
Update join the update table
func (*PostgresQueryBuilder) Values ¶
func (qb *PostgresQueryBuilder) Values(vals ...string) QueryBuilder
Values join the Values(vals)
func (*PostgresQueryBuilder) Where ¶
func (qb *PostgresQueryBuilder) Where(cond string) QueryBuilder
Where join the Where cond
type QueryBuilder ¶
type QueryBuilder interface { Select(fields ...string) QueryBuilder ForUpdate() QueryBuilder From(tables ...string) QueryBuilder InnerJoin(table string) QueryBuilder LeftJoin(table string) QueryBuilder RightJoin(table string) QueryBuilder On(cond string) QueryBuilder Where(cond string) QueryBuilder And(cond string) QueryBuilder Or(cond string) QueryBuilder In(vals ...string) QueryBuilder OrderBy(fields ...string) QueryBuilder Asc() QueryBuilder Desc() QueryBuilder Limit(limit int) QueryBuilder Offset(offset int) QueryBuilder GroupBy(fields ...string) QueryBuilder Having(cond string) QueryBuilder Update(tables ...string) QueryBuilder Set(kv ...string) QueryBuilder Delete(tables ...string) QueryBuilder InsertInto(table string, fields ...string) QueryBuilder Values(vals ...string) QueryBuilder Subquery(sub string, alias string) string String() string }
QueryBuilder is the Query builder interface
func NewQueryBuilder ¶
func NewQueryBuilder(driver string) (qb QueryBuilder, err error)
NewQueryBuilder return the QueryBuilder
type QueryExecutor ¶
type QueryExecutor interface {
// contains filtered or unexported methods
}
QueryExecutor wrapping for ormer
type QueryM2Mer ¶
type QueryM2Mer interface { // Add adds models to origin models when creating queryM2M. // example: // m2m := orm.QueryM2M(post,"Tag") // m2m.Add(&Tag1{},&Tag2{}) // for _,tag := range post.Tags{}{ ... } // param could also be any of the follow // []*Tag{{Id:3,Name: "TestTag1"}, {Id:4,Name: "TestTag2"}} // &Tag{Id:5,Name: "TestTag3"} // []interface{}{&Tag{Id:6,Name: "TestTag4"}} // insert one or more rows to m2m table // make sure the relation is defined in post model struct tag. Add(...interface{}) (int64, error) AddWithCtx(context.Context, ...interface{}) (int64, error) // Remove removes models following the origin model relationship // only delete rows from m2m table // for example: // tag3 := &Tag{Id:5,Name: "TestTag3"} // num, err = m2m.Remove(tag3) Remove(...interface{}) (int64, error) RemoveWithCtx(context.Context, ...interface{}) (int64, error) // Exist checks model is existed in relationship of origin model Exist(interface{}) bool ExistWithCtx(context.Context, interface{}) bool // Clear cleans All models in related of origin model Clear() (int64, error) ClearWithCtx(context.Context) (int64, error) // Count counts All related models of origin model Count() (int64, error) CountWithCtx(context.Context) (int64, error) }
QueryM2Mer model to model query struct All operations are on the m2m table only, will not affect the origin model table
type QuerySeter ¶
type QuerySeter interface { // Filter add condition expression to QuerySeter. // for example: // filter by UserName == 'slene' // qs.Filter("UserName", "slene") // sql : left outer join profile on t0.id1==t1.id2 where t1.age == 28 // Filter("profile__Age", 28) // // time compare // qs.Filter("created", time.Now()) Filter(string, ...interface{}) QuerySeter // FilterRaw add raw sql to querySeter. // for example: // qs.FilterRaw("user_id IN (SELECT id FROM profile WHERE age>=18)") // //sql-> WHERE user_id IN (SELECT id FROM profile WHERE age>=18) FilterRaw(string, string) QuerySeter // Exclude add NOT condition to querySeter. // have the same usage as Filter Exclude(string, ...interface{}) QuerySeter // SetCond Set condition to QuerySeter. // sql's where condition // cond := orm.NewCondition() // cond1 := cond.And("profile__isnull", false).AndNot("status__in", 1).Or("profile__age__gt", 2000) // //sql-> WHERE T0.`profile_id` IS NOT NULL AND NOT T0.`Status` IN (?) OR T1.`age` > 2000 // num, err := qs.SetCond(cond1).Count() SetCond(*Condition) QuerySeter // GetCond Get condition from QuerySeter. // sql's where condition // cond := orm.NewCondition() // cond = cond.And("profile__isnull", false).AndNot("status__in", 1) // qs = qs.SetCond(cond) // cond = qs.GetCond() // cond := cond.Or("profile__age__gt", 2000) // //sql-> WHERE T0.`profile_id` IS NOT NULL AND NOT T0.`Status` IN (?) OR T1.`age` > 2000 // num, err := qs.SetCond(cond).Count() GetCond() *Condition // Limit add LIMIT value. // args[0] means offset, e.g. LIMIT num,offset. // if Limit <= 0 then Limit will be Set to default limit ,eg 1000 // if QuerySeter doesn't call Limit, the sql's Limit will be Set to default limit, eg 1000 // for example: // qs.Limit(10, 2) // // sql-> limit 10 offset 2 Limit(limit interface{}, args ...interface{}) QuerySeter // Offset add OFFSET value // same as Limit function's args[0] Offset(offset interface{}) QuerySeter // GroupBy add GROUP BY expression // for example: // qs.GroupBy("id") GroupBy(exprs ...string) QuerySeter // OrderBy add ORDER expression. // "column" means ASC, "-column" means DESC. // for example: // qs.OrderBy("-status") OrderBy(exprs ...string) QuerySeter // OrderClauses add ORDER expression by order clauses // for example: // OrderClauses( // order_clause.Clause( // order.Column("Id"), // order.SortAscending(), // ), // order_clause.Clause( // order.Column("status"), // order.SortDescending(), // ), // ) // OrderClauses(order_clause.Clause( // order_clause.Column(`user__status`), // order_clause.SortDescending(),//default None // )) // OrderClauses(order_clause.Clause( // order_clause.Column(`random()`), // order_clause.SortNone(),//default None // order_clause.Raw(),//default false.if true, do not check field is valid or not // )) OrderClauses(orders ...*order_clause.Order) QuerySeter // ForceIndex add FORCE INDEX expression. // for example: // qs.ForceIndex(`idx_name1`,`idx_name2`) // ForceIndex, UseIndex , IgnoreIndex are mutually exclusive ForceIndex(indexes ...string) QuerySeter // UseIndex add USE INDEX expression. // for example: // qs.UseIndex(`idx_name1`,`idx_name2`) // ForceIndex, UseIndex , IgnoreIndex are mutually exclusive UseIndex(indexes ...string) QuerySeter // IgnoreIndex add IGNORE INDEX expression. // for example: // qs.IgnoreIndex(`idx_name1`,`idx_name2`) // ForceIndex, UseIndex , IgnoreIndex are mutually exclusive IgnoreIndex(indexes ...string) QuerySeter // RelatedSel Set relation model to query together. // it will query relation models and assign to parent model. // for example: // // will load All related Fields use left join . // qs.RelatedSel().One(&user) // // will load related field only profile // qs.RelatedSel("profile").One(&user) // user.Profile.Age = 32 RelatedSel(params ...interface{}) QuerySeter // Distinct Set Distinct // for example: // o.QueryTable("policy").Filter("Groups__Group__Users__User", user). // Distinct(). // All(&permissions) Distinct() QuerySeter // ForUpdate Set FOR UPDATE to query. // for example: // o.QueryTable("user").Filter("uid", uid).ForUpdate().All(&users) ForUpdate() QuerySeter // Count returns QuerySeter execution result number // for example: // num, err = qs.Filter("profile__age__gt", 28).Count() Count() (int64, error) CountWithCtx(context.Context) (int64, error) // Exist check result empty or not after QuerySeter executed // the same as QuerySeter.Count > 0 Exist() bool ExistWithCtx(context.Context) bool // Update execute update with parameters // for example: // num, err = qs.Filter("user_name", "slene").Update(Params{ // "Nums": ColValue(Col_Minus, 50), // }) // user slene's Nums will minus 50 // num, err = qs.Filter("UserName", "slene").Update(Params{ // "user_name": "slene2" // }) // user slene's name will change to slene2 Update(values Params) (int64, error) UpdateWithCtx(ctx context.Context, values Params) (int64, error) // Delete delete from table // for example: // num ,err = qs.Filter("user_name__in", "testing1", "testing2").Delete() // //delete two user who's name is testing1 or testing2 Delete() (int64, error) DeleteWithCtx(context.Context) (int64, error) // PrepareInsert return an insert queryer. // it can be used in times. // example: // i,err := sq.PrepareInsert() // num, err = i.Insert(&user1) // user table will add one record user1 at once // num, err = i.Insert(&user2) // user table will add one record user2 at once // err = i.Close() //don't forget call Close PrepareInsert() (Inserter, error) PrepareInsertWithCtx(context.Context) (Inserter, error) // All query All data and map to containers. // cols means the Columns when querying. // for example: // var users []*User // qs.All(&users) // users[0],users[1],users[2] ... All(container interface{}, cols ...string) (int64, error) AllWithCtx(ctx context.Context, container interface{}, cols ...string) (int64, error) // One query one row data and map to containers. // cols means the Columns when querying. // for example: // var user User // qs.One(&user) //user.UserName == "slene" One(container interface{}, cols ...string) error OneWithCtx(ctx context.Context, container interface{}, cols ...string) error // Values query All data and map to []map[string]interface. // expres means condition expression. // it converts data to []map[column]value. // for example: // var maps []Params // qs.Values(&maps) //maps[0]["UserName"]=="slene" Values(results *[]Params, exprs ...string) (int64, error) ValuesWithCtx(ctx context.Context, results *[]Params, exprs ...string) (int64, error) // ValuesList query All data and map to [][]interface // it converts data to [][column_index]value // for example: // var list []ParamsList // qs.ValuesList(&list) // list[0][1] == "slene" ValuesList(results *[]ParamsList, exprs ...string) (int64, error) ValuesListWithCtx(ctx context.Context, results *[]ParamsList, exprs ...string) (int64, error) // ValuesFlat query All data and map to []interface. // it's designed for one column record Set, auto change to []value, not [][column]value. // for example: // var list ParamsList // qs.ValuesFlat(&list, "UserName") // list[0] == "slene" ValuesFlat(result *ParamsList, expr string) (int64, error) ValuesFlatWithCtx(ctx context.Context, result *ParamsList, expr string) (int64, error) // RowsToMap query All rows into map[string]interface with specify key and value column name. // keyCol = "name", valueCol = "value" // table data // name | value // total | 100 // found | 200 // to map[string]interface{}{ // "total": 100, // "found": 200, // } RowsToMap(result *Params, keyCol, valueCol string) (int64, error) // RowsToStruct query All rows into struct with specify key and value column name. // keyCol = "name", valueCol = "value" // table data // name | value // total | 100 // found | 200 // to struct { // Total int // Found int // } RowsToStruct(ptrStruct interface{}, keyCol, valueCol string) (int64, error) // Aggregate aggregate func. // for example: // type result struct { // DeptName string // Total int // } // var res []result // o.QueryTable("dept_info").Aggregate("dept_name,sum(salary) as total").GroupBy("dept_name").All(&res) Aggregate(s string) QuerySeter }
QuerySeter query seter
type RawPreparer ¶
RawPreparer raw query statement
type RawSeter ¶
type RawSeter interface { // Exec execute sql and Get result Exec() (sql.Result, error) // QueryRow query data and map to container // for example: // var name string // var id int // rs.QueryRow(&id,&name) // id==2 name=="slene" QueryRow(containers ...interface{}) error // QueryRows query data rows and map to container // var ids []int // var names []int // query = fmt.Sprintf("SELECT 'id','name' FROM %suser%s", Q, Q) // num, err = dORM.Raw(query).QueryRows(&ids,&names) // ids=>{1,2},names=>{"nobody","slene"} QueryRows(containers ...interface{}) (int64, error) SetArgs(...interface{}) RawSeter // Values query data to []map[string]interface // see QuerySeter's Values Values(container *[]Params, cols ...string) (int64, error) // ValuesList query data to [][]interface // see QuerySeter's ValuesList ValuesList(container *[]ParamsList, cols ...string) (int64, error) // ValuesFlat query data to []interface // see QuerySeter's ValuesFlat ValuesFlat(container *ParamsList, cols ...string) (int64, error) // RowsToMap query All rows into map[string]interface with specify key and value column name. // keyCol = "name", valueCol = "value" // table data // name | value // total | 100 // found | 200 // to map[string]interface{}{ // "total": 100, // "found": 200, // } RowsToMap(result *Params, keyCol, valueCol string) (int64, error) // RowsToStruct query All rows into struct with specify key and value column name. // keyCol = "name", valueCol = "value" // table data // name | value // total | 100 // found | 200 // to struct { // Total int // Found int // } RowsToStruct(ptrStruct interface{}, keyCol, valueCol string) (int64, error) // Prepare return prepared raw statement for used in times. // for example: // pre, err := dORM.Raw("INSERT INTO tag (name) VALUES (?)").Prepare() // r, err := pre.Exec("name1") // INSERT INTO tag (name) VALUES (`name1`) Prepare() (RawPreparer, error) }
RawSeter raw query seter create From Ormer.Raw for example:
sql := fmt.Sprintf("SELECT %sid%s,%sname%s FROM %suser%s WHERE id = ?",Q,Q,Q,Q,Q,Q) rs := Ormer.Raw(sql, 1)
type SmallIntegerField ¶
type SmallIntegerField = models.SmallIntegerField
SmallIntegerField -32768 to 32767
type TableEngineI ¶
type TableEngineI interface {
TableEngine() string
}
TableEngineI is usually used by model when you want to use specific engine, like myisam, you can implement this interface for example:
type User struct { ... } func (u *User) TableEngine() string { return "myisam" }
type TableIndexI ¶
type TableIndexI interface {
TableIndex() [][]string
}
TableIndexI is usually used by model when you want to create indexes, you can implement this interface for example:
type User struct { ... } func (u *User) TableIndex() [][]string { return [][]string{{"Name"}} }
type TableNameI ¶
type TableNameI interface {
TableName() string
}
TableNameI is usually used by model when you custom your table name, please implement this interfaces for example:
type User struct { ... } func (u *User) TableName() string { return "USER_TABLE" }
type TableUniqueI ¶
type TableUniqueI interface {
TableUnique() [][]string
}
TableUniqueI is usually used by model when you want to create unique indexes, you can implement this interface for example:
type User struct { ... } func (u *User) TableUnique() [][]string { return [][]string{{"Email"}} }
type TiDBQueryBuilder ¶
type TiDBQueryBuilder struct { MySQLQueryBuilder // contains filtered or unexported fields }
TiDBQueryBuilder is the SQL build
type TimeField ¶
TimeField A time, represented in go by a time.Time instance. only time values like 10:00:00 Has a few extra, optional attr tag:
auto_now: Automatically Set the field to now every time the object is saved. Useful for “last-modified” timestamps. Note that the current date is always used; it’s not just a default value that you can override.
auto_now_add: Automatically Set the field to now when the object is first created. Useful for creation of timestamps. Note that the current date is always used; it’s not just a default value that you can override.
eg: `orm:"auto_now"` or `orm:"auto_now_add"`
type TxBeginner ¶
type TxBeginner interface { // Begin self control transaction Begin() (TxOrmer, error) BeginWithCtx(ctx context.Context) (TxOrmer, error) BeginWithOpts(opts *sql.TxOptions) (TxOrmer, error) BeginWithCtxAndOpts(ctx context.Context, opts *sql.TxOptions) (TxOrmer, error) // DoTx closure control transaction DoTx(task func(ctx context.Context, txOrm TxOrmer) error) error DoTxWithCtx(ctx context.Context, task func(ctx context.Context, txOrm TxOrmer) error) error DoTxWithOpts(opts *sql.TxOptions, task func(ctx context.Context, txOrm TxOrmer) error) error DoTxWithCtxAndOpts(ctx context.Context, opts *sql.TxOptions, task func(ctx context.Context, txOrm TxOrmer) error) error }
type TxCommitter ¶
type TxCommitter interface {
// contains filtered or unexported methods
}
type TxDB ¶
type TxDB struct {
// contains filtered or unexported fields
}
func (*TxDB) ExecContext ¶
func (*TxDB) PrepareContext ¶
func (*TxDB) QueryContext ¶
func (*TxDB) QueryRowContext ¶
func (*TxDB) RollbackUnlessCommit ¶
type TxOrmer ¶
type TxOrmer interface { QueryExecutor TxCommitter }
Source Files ¶
- cmd.go
- cmd_utils.go
- db.go
- db_alias.go
- db_mysql.go
- db_oracle.go
- db_postgres.go
- db_sqlite.go
- db_tables.go
- db_tidb.go
- db_utils.go
- ddl.go
- do_nothing_orm.go
- filter.go
- filter_orm_decorator.go
- invocation.go
- models_boot.go
- models_fields.go
- orm.go
- orm_conds.go
- orm_log.go
- orm_object.go
- orm_querym2m.go
- orm_queryset.go
- orm_raw.go
- qb.go
- qb_mysql.go
- qb_postgres.go
- qb_tidb.go
- types.go
- utils.go
Directories ¶
Path | Synopsis |
---|---|
filter
|
|
internal
|
|
Package migration enables you to generate migrations back and forth.
|
Package migration enables you to generate migrations back and forth. |