Add context support for orm
Signed-off-by: Penghui Liao <liaoishere@gmail.com>
This commit is contained in:
@@ -15,12 +15,14 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// an insert queryer struct
|
||||
type insertSet struct {
|
||||
ctx context.Context
|
||||
mi *modelInfo
|
||||
orm *ormBase
|
||||
stmt stmtQuerier
|
||||
@@ -44,7 +46,7 @@ func (o *insertSet) Insert(md interface{}) (int64, error) {
|
||||
if name != o.mi.fullName {
|
||||
panic(fmt.Errorf("<Inserter.Insert> need model `%s` but found `%s`", o.mi.fullName, name))
|
||||
}
|
||||
id, err := o.orm.alias.DbBaser.InsertStmt(o.stmt, o.mi, ind, o.orm.alias.TZ)
|
||||
id, err := o.orm.alias.DbBaser.InsertStmt(o.ctx, o.stmt, o.mi, ind, o.orm.alias.TZ)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
@@ -70,11 +72,12 @@ func (o *insertSet) Close() error {
|
||||
}
|
||||
|
||||
// create new insert queryer.
|
||||
func newInsertSet(orm *ormBase, mi *modelInfo) (Inserter, error) {
|
||||
func newInsertSet(ctx context.Context, orm *ormBase, mi *modelInfo) (Inserter, error) {
|
||||
bi := new(insertSet)
|
||||
bi.ctx = ctx
|
||||
bi.orm = orm
|
||||
bi.mi = mi
|
||||
st, query, err := orm.alias.DbBaser.PrepareInsert(orm.db, mi)
|
||||
st, query, err := orm.alias.DbBaser.PrepareInsert(ctx, orm.db, mi)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user