本文整理汇总了Golang中github.com/jmoiron/sqlx.Stmt.Exec方法的典型用法代码示例。如果您正苦于以下问题:Golang Stmt.Exec方法的具体用法?Golang Stmt.Exec怎么用?Golang Stmt.Exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jmoiron/sqlx.Stmt
的用法示例。
在下文中一共展示了Stmt.Exec方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PrepAndExec
func PrepAndExec(query string, db Execer, args ...interface{}) (result sql.Result, err error) {
var stmt *sqlx.Stmt
var acid AcidTx = func(tx *sqlx.Tx) {
stmt, err = tx.Preparex(query)
if err != nil {
panic(err)
}
if result, err = stmt.Exec(args...); err != nil {
panic(err)
}
}
AcidCtx(acid, db)
return result, err
}
示例2: GetAPIStandings
func (d *dbInterface) GetAPIStandings(key XMLAPIKey, charID int) error {
k := &evego.XMLKey{
KeyID: key.ID,
VerificationCode: key.VerificationCode,
}
standings, err := d.xmlAPI.CharacterStandings(k, charID)
if err != nil {
return err
}
tx, err := d.db.Beginx()
if err != nil {
return err
}
// Clear standings before inserting the API's information.
_, err = tx.Stmtx(d.apiKeyClearCorpStandingsStmt).Exec(charID)
if err != nil {
return err
}
_, err = tx.Stmtx(d.apiKeyClearFacStandingsStmt).Exec(charID)
if err != nil {
return err
}
var insertStmt *sqlx.Stmt
for _, standing := range standings {
switch standing.EntityType {
case evego.NPCCorporation:
insertStmt = d.apiKeyInsertCorpStandingsStmt
case evego.NPCFaction:
insertStmt = d.apiKeyInsertFacStandingsStmt
default:
// Agent standings - we don't handle those, so skip.
continue
}
insertStmt = tx.Stmtx(insertStmt)
_, err := insertStmt.Exec(charID, standing.ID, standing.Standing)
if err != nil {
tx.Rollback()
return err
}
}
return tx.Commit()
}
示例3: CreateWithId
func (db DB) CreateWithId(stmt *sqlx.Stmt, args ...interface{}) (int64, error) {
var id int64
if db.driver == "postgres" {
err := stmt.QueryRow(args...).Scan(&id)
if err != nil {
return 0, err
}
} else {
res, err := stmt.Exec(args...)
if err != nil {
return 0, err
}
id, err = res.LastInsertId()
if err != nil {
return 0, err
}
}
return id, nil
}
示例4: Create
func (maker *courseMaker) Create(course *Course) error {
var (
err error
courseQuery = queries["create_course"]
courseMemberQuery = queries["create_course_members"]
courseTeachersQuery = queries["create_course_teachers"]
acid util.AcidTx
result sql.Result
stmt *sqlx.Stmt
)
acid = func(tx *sqlx.Tx) {
// Add the course
stmt, err = tx.Preparex(courseQuery)
if err != nil {
panic(err)
}
if result, err = stmt.Exec(course.Name); err != nil {
panic(err)
}
course.ID, err = result.LastInsertId()
if err != nil {
panic(err)
}
// Then add a new record for each of the students to course_members
for _, student := range course.Students {
stmt, err = tx.Preparex(courseMemberQuery)
if err != nil {
panic(err)
}
if result, err = stmt.Exec(course.ID, student.ID); err != nil {
panic(err)
}
}
// Then add a new record for each of the teachers to course_teachers
for _, teacher := range course.Teachers {
stmt, err = tx.Preparex(courseTeachersQuery)
if err != nil {
panic(err)
}
if result, err = stmt.Exec(course.ID, teacher.ID); err != nil {
panic(err)
}
}
}
return util.AcidCtx(acid, maker)
}