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


Golang ModelTx.QueryRow方法代碼示例

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


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

示例1: SavePriceLog

func SavePriceLog(tx *db.ModelTx, plog *PriceLog) *PriceLog {
	err := tx.QueryRow(
		`INSERT INTO exchange_price_log (`+PriceLogModel.FieldsInsert+`)
         VALUES (`+PriceLogModel.Placeholders+`)
         RETURNING id`,
		plog,
	).Scan(&plog.Id)
	if err != nil {
		panic(err)
	}
	return plog
}
開發者ID:jaekwon,項目名稱:ftnox-backend,代碼行數:12,代碼來源:models.go

示例2: SaveTrade

func SaveTrade(tx *db.ModelTx, trade *Trade) *Trade {
	if trade.Time == 0 {
		trade.Time = time.Now().Unix()
	}
	err := tx.QueryRow(
		`INSERT INTO exchange_trade (`+TradeModel.FieldsInsert+`)
         VALUES (`+TradeModel.Placeholders+`)
         RETURNING id`,
		trade,
	).Scan(&trade.Id)
	if err != nil {
		panic(err)
	}
	return trade
}
開發者ID:jaekwon,項目名稱:ftnox-backend,代碼行數:15,代碼來源:models.go

示例3: SaveOrder

func SaveOrder(tx *db.ModelTx, order *Order) *Order {
	if order.Time == 0 {
		order.Time = time.Now().Unix()
	}
	err := tx.QueryRow(
		`INSERT INTO exchange_order (`+OrderModel.FieldsInsert+`)
         VALUES (`+OrderModel.Placeholders+`)
         RETURNING id`,
		order,
	).Scan(&order.Id)
	if err != nil {
		panic(err)
	}
	return order
}
開發者ID:jaekwon,項目名稱:ftnox-backend,代碼行數:15,代碼來源:models.go

示例4: SaveOrUpdatePriceLog

func SaveOrUpdatePriceLog(tx *db.ModelTx, plog *PriceLog) {
	var exists int
	err := tx.QueryRow(
		`SELECT 1 FROM exchange_price_log
         WHERE market=? AND interval=? AND time=?`,
		plog.Market, plog.Interval, plog.Time,
	).Scan(&exists)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		SavePriceLog(tx, plog)
	case nil:
		UpdatePriceLog(tx, plog)
	default:
		panic(err)
	}
}
開發者ID:jaekwon,項目名稱:ftnox-backend,代碼行數:16,代碼來源:models.go

示例5: UpdateBalanceByWallet

// Adds or subtracts an amount to a user's wallet.
// nonnegative: panics with INSUFFICIENT_FUNDS_ERROR if resulting balance is negative.
// Returns the new balance
func UpdateBalanceByWallet(tx *db.ModelTx, userId int64, wallet string, coin string, diff int64, nonnegative bool) *Balance {
	var balance Balance

	// Get existing balance.
	err := tx.QueryRow(
		`SELECT `+BalanceModel.FieldsSimple+`
         FROM account_balance WHERE
         user_id=? AND wallet=? AND coin=?`,
		userId, wallet, coin,
	).Scan(&balance)

	// Ensure nonnegative
	if nonnegative && balance.Amount+diff < 0 {
		panic(INSUFFICIENT_FUNDS_ERROR)
	}

	// First time balance?
	if err == sql.ErrNoRows {
		// Create new balance
		balance := Balance{UserId: userId, Wallet: wallet, Coin: coin, Amount: diff}
		SaveBalance(tx, &balance)
		return &balance
	}

	// Update balance
	balance.Amount += diff
	_, err = tx.Exec(
		`UPDATE account_balance
         SET amount=?
         WHERE user_id=? AND wallet=? AND coin=?`,
		balance.Amount, userId, wallet, coin,
	)
	if err != nil {
		panic(err)
	}
	return &balance
}
開發者ID:jaekwon,項目名稱:ftnox-backend,代碼行數:40,代碼來源:models.go


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