當前位置: 首頁>>代碼示例>>Golang>>正文


Golang DbConnection.ExecInTx方法代碼示例

本文整理匯總了Golang中github.com/blendlabs/spiffy.DbConnection.ExecInTx方法的典型用法代碼示例。如果您正苦於以下問題:Golang DbConnection.ExecInTx方法的具體用法?Golang DbConnection.ExecInTx怎麽用?Golang DbConnection.ExecInTx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/blendlabs/spiffy.DbConnection的用法示例。


在下文中一共展示了DbConnection.ExecInTx方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Invoke

// Invoke executes the statement block
func (s Statement) Invoke(c *spiffy.DbConnection, tx *sql.Tx) (err error) {
	for _, step := range s {
		err = c.ExecInTx(step, tx)
		if err != nil {
			return
		}
	}
	return
}
開發者ID:blendlabs,項目名稱:spiffy,代碼行數:10,代碼來源:statement.go

示例2: invoke

// Invoke consumes the data file and writes it to the db.
func (dfr *DataFileReader) invoke(c *spiffy.DbConnection, tx *sql.Tx) (err error) {
	var f *os.File
	if f, err = os.Open(dfr.path); err != nil {
		return
	}
	defer f.Close()

	var stmt *sql.Stmt
	var state int

	var cursor int64
	var readBuffer = make([]byte, 32)
	var readErr error
	var lineBuffer = bytes.NewBuffer([]byte{})
	var line string
	var pieces []interface{}

	for readErr == nil {
		lineBuffer.Reset()

		switch state {
		case 0:
			cursor, readErr = dfr.readLine(f, cursor, readBuffer, lineBuffer)
			if readErr != nil {
				continue
			}
			line = lineBuffer.String()

			if spiffy.HasPrefixCaseInsensitive(line, "--") {
				continue
			}

			if spiffy.HasPrefixCaseInsensitive(line, "set") {
				continue
			}

			if spiffy.HasPrefixCaseInsensitive(line, "copy") {
				if !spiffy.HasSuffixCaseInsensitive(line, "from stdin;") {
					err = fmt.Errorf("Only `stdin` from clauses supported at this time, cannot continue.")
					return
				}

				stmt, err = dfr.executeCopyLine(line, c, tx)
				if err != nil {
					return
				}
				state = 1
				continue
			}

			err = c.ExecInTx(line, tx)
			if err != nil {
				return
			}
		case 1:
			pieces, cursor, readErr = dfr.readTabLine(f, cursor, readBuffer, lineBuffer)
			if readErr != nil {
				continue
			}

			if len(pieces) == 0 {
				err = fmt.Errorf("Empty data line, we error on this for now.")
				return
			}

			if len(pieces) == 1 && spiffy.HasPrefixCaseInsensitive(pieces[0].(string), `\.`) {
				err = stmt.Close()
				if err != nil {
					return
				}
				state = 0
				continue
			}

			_, err = stmt.Exec(pieces...)
			if err != nil {
				return
			}
		}
	}
	return nil
}
開發者ID:blendlabs,項目名稱:spiffy,代碼行數:83,代碼來源:data_file_reader.go


注:本文中的github.com/blendlabs/spiffy.DbConnection.ExecInTx方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。