Yimaru-BackEnd/gen/db/transactions.sql.go

133 lines
3.2 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: transactions.sql
package dbgen
import (
"context"
)
const CreateTransaction = `-- name: CreateTransaction :one
INSERT INTO transactions (amount, transaction_type, wallet_id) VALUES ($1, $2, $3) RETURNING id, amount, transaction_type, wallet_id, verified, created_at, updated_at
`
type CreateTransactionParams struct {
Amount int64
TransactionType string
WalletID int64
}
func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) {
row := q.db.QueryRow(ctx, CreateTransaction, arg.Amount, arg.TransactionType, arg.WalletID)
var i Transaction
err := row.Scan(
&i.ID,
&i.Amount,
&i.TransactionType,
&i.WalletID,
&i.Verified,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const GetAllTransactions = `-- name: GetAllTransactions :many
SELECT id, amount, transaction_type, wallet_id, verified, created_at, updated_at FROM transactions
`
func (q *Queries) GetAllTransactions(ctx context.Context) ([]Transaction, error) {
rows, err := q.db.Query(ctx, GetAllTransactions)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Transaction
for rows.Next() {
var i Transaction
if err := rows.Scan(
&i.ID,
&i.Amount,
&i.TransactionType,
&i.WalletID,
&i.Verified,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetTransactionByID = `-- name: GetTransactionByID :one
SELECT id, amount, transaction_type, wallet_id, verified, created_at, updated_at FROM transactions WHERE id = $1
`
func (q *Queries) GetTransactionByID(ctx context.Context, id int64) (Transaction, error) {
row := q.db.QueryRow(ctx, GetTransactionByID, id)
var i Transaction
err := row.Scan(
&i.ID,
&i.Amount,
&i.TransactionType,
&i.WalletID,
&i.Verified,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const GetTransactionsByWallet = `-- name: GetTransactionsByWallet :many
SELECT id, amount, transaction_type, wallet_id, verified, created_at, updated_at FROM transactions WHERE wallet_id = $1
`
func (q *Queries) GetTransactionsByWallet(ctx context.Context, walletID int64) ([]Transaction, error) {
rows, err := q.db.Query(ctx, GetTransactionsByWallet, walletID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Transaction
for rows.Next() {
var i Transaction
if err := rows.Scan(
&i.ID,
&i.Amount,
&i.TransactionType,
&i.WalletID,
&i.Verified,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const UpdateTransferVerification = `-- name: UpdateTransferVerification :exec
UPDATE transactions SET verified = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2
`
type UpdateTransferVerificationParams struct {
Verified bool
ID int64
}
func (q *Queries) UpdateTransferVerification(ctx context.Context, arg UpdateTransferVerificationParams) error {
_, err := q.db.Exec(ctx, UpdateTransferVerification, arg.Verified, arg.ID)
return err
}