本文整理汇总了Golang中upper/io/db/util/sqlgen.Statement.Compile方法的典型用法代码示例。如果您正苦于以下问题:Golang Statement.Compile方法的具体用法?Golang Statement.Compile怎么用?Golang Statement.Compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类upper/io/db/util/sqlgen.Statement
的用法示例。
在下文中一共展示了Statement.Compile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doExec
func (s *source) doExec(stmt sqlgen.Statement, args ...interface{}) (sql.Result, error) {
var query string
var res sql.Result
var err error
var start, end int64
start = time.Now().UnixNano()
defer func() {
end = time.Now().UnixNano()
debugLog(query, args, err, start, end)
}()
if s.session == nil {
return nil, db.ErrNotConnected
}
query = stmt.Compile(template)
if s.tx != nil {
res, err = s.tx.sqlTx.Exec(query, args...)
} else {
res, err = s.session.Exec(query, args...)
}
return res, err
}
示例2: doQueryRow
func (self *Source) doQueryRow(stmt sqlgen.Statement, args ...interface{}) (*sql.Row, error) {
var query string
var row *sql.Row
var err error
var start, end int64
start = time.Now().UnixNano()
defer func() {
end = time.Now().UnixNano()
debugLog(query, args, err, start, end)
}()
if self.session == nil {
return nil, db.ErrNotConnected
}
query = stmt.Compile(template)
if self.tx != nil {
row = self.tx.QueryRow(query, args...)
} else {
row = self.session.QueryRow(query, args...)
}
return row, err
}
示例3: doExec
func (self *source) doExec(stmt sqlgen.Statement, args ...interface{}) (sql.Result, error) {
var query string
var res sql.Result
var err error
var start, end int64
start = time.Now().UnixNano()
defer func() {
end = time.Now().UnixNano()
debugLog(query, args, err, start, end)
}()
if self.session == nil {
return nil, db.ErrNotConnected
}
query = stmt.Compile(template)
l := len(args)
for i := 0; i < l; i++ {
query = strings.Replace(query, `?`, fmt.Sprintf(`$%d`, i+1), 1)
}
if self.tx != nil {
res, err = self.tx.Exec(query, args...)
} else {
var tx *sql.Tx
if tx, err = self.session.Begin(); err != nil {
return nil, err
}
if res, err = tx.Exec(query, args...); err != nil {
return nil, err
}
if err = tx.Commit(); err != nil {
return nil, err
}
}
return res, err
}