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


Golang db.ModelTx类代码示例

本文整理汇总了Golang中ftnox/com/db.ModelTx的典型用法代码示例。如果您正苦于以下问题:Golang ModelTx类的具体用法?Golang ModelTx怎么用?Golang ModelTx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ModelTx类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SaveAPIKey

func SaveAPIKey(tx *db.ModelTx, apiKey *APIKey) *APIKey {
	_, err := tx.Exec(
		`INSERT INTO auth_api_key (`+APIKeyModel.FieldsInsert+`)
         VALUES (`+APIKeyModel.Placeholders+`)`,
		apiKey,
	)
	if err != nil {
		panic(err)
	}
	return apiKey
}
开发者ID:jaekwon,项目名称:ftnox-backend,代码行数:11,代码来源:models.go

示例2: UpdateDepositSetStatus

// NOTE: This should be called in a serializable transaction to ensure that
// the user's balance gets updated in a safe manner.
func UpdateDepositSetStatus(tx *db.ModelTx, depositId int64, status int32) {
	updated := time.Now().Unix()
	_, err := tx.Exec(
		`UPDATE account_deposit
         SET status=?, updated=?
         WHERE id=?`,
		status, updated, depositId,
	)
	if err != nil {
		panic(err)
	}
}
开发者ID:jaekwon,项目名称:ftnox-backend,代码行数:14,代码来源:models.go

示例3: UpdatePriceLog

func UpdatePriceLog(tx *db.ModelTx, plog *PriceLog) {
	_, err := tx.Exec(
		`UPDATE exchange_price_log
         SET low=?, high=?, close=?, ask_volume=?, bid_volume=?
         WHERE market=? AND interval=? AND time=?`,
		plog.Low, plog.High, plog.Close, plog.AskVolume, plog.BidVolume,
		plog.Market, plog.Interval, plog.Time,
	)
	if err != nil {
		panic(err)
	}
}
开发者ID:jaekwon,项目名称:ftnox-backend,代码行数:12,代码来源:models.go

示例4: 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

示例5: UpdateOrder

func UpdateOrder(tx *db.ModelTx, order *Order) {
	order.Updated = time.Now().Unix()
	_, err := tx.Exec(
		`UPDATE exchange_order
         SET status=?, filled=?, basis_filled=?, updated=?
         WHERE id=?`,
		order.Status, order.Filled, order.BasisFilled, order.Updated, order.Id,
	)
	if err != nil {
		panic(err)
	}
}
开发者ID:jaekwon,项目名称:ftnox-backend,代码行数:12,代码来源:models.go

示例6: 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

示例7: 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

示例8: 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

示例9: UpdateWithdrawals

func UpdateWithdrawals(tx *db.ModelTx, wthIds []interface{}, oldStatus, newStatus int, wtxId int64) {
	if len(wthIds) == 0 {
		return
	}

	res, err := tx.Exec(
		`UPDATE account_withdrawal
         SET status=?, wtx_id=?, updated=?
         WHERE status=? AND id IN (`+Placeholders(len(wthIds))+`)`,
		append([]interface{}{newStatus, wtxId, time.Now().Unix(), oldStatus}, wthIds...)...,
	)
	if err != nil {
		panic(err)
	}
	count, err := res.RowsAffected()
	if err != nil {
		panic(err)
	}
	if int(count) != len(wthIds) {
		panic(NewError("Unexpected affected rows count: %v Expected %v", count, len(wthIds)))
	}
}
开发者ID:jaekwon,项目名称:ftnox-backend,代码行数:22,代码来源:models.go

示例10: UpdatePaymentsSpent

func UpdatePaymentsSpent(tx *db.ModelTx, paymentIds []interface{}, oldStatus, newStatus int, wtxId int64) {
	if len(paymentIds) == 0 {
		return
	}
	now := time.Now().Unix()

	res, err := tx.Exec(
		`UPDATE payment
         SET spent=?, wtx_id=?, updated=?
         WHERE spent=? AND id IN (`+Placeholders(len(paymentIds))+`)`,
		append([]interface{}{newStatus, wtxId, now, oldStatus}, paymentIds...)...,
	)
	if err != nil {
		panic(err)
	}
	count, err := res.RowsAffected()
	if int(count) != len(paymentIds) {
		panic(NewError("Unexpected affected rows count: %v Expected %v", count, len(paymentIds)))
	}
	if err != nil {
		panic(err)
	}
}
开发者ID:jaekwon,项目名称:ftnox-backend,代码行数:23,代码来源:models.go

示例11: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。