当前位置: 首页>>代码示例>>Golang>>正文


Golang Stmt.Exec方法代码示例

本文整理汇总了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
}
开发者ID:alligrader,项目名称:gradebook-backend,代码行数:16,代码来源:util.go

示例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()
}
开发者ID:backerman,项目名称:eveindy,代码行数:42,代码来源:xmlapi.go

示例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
}
开发者ID:yourchanges,项目名称:readeef,代码行数:22,代码来源:db.go

示例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)
}
开发者ID:alligrader,项目名称:gradebook-backend,代码行数:50,代码来源:course_maker.go


注:本文中的github.com/jmoiron/sqlx.Stmt.Exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。