本文整理匯總了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
}