当前位置: 首页>>代码示例>>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;未经允许,请勿转载。