當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。