148 lines
3.4 KiB
Go
148 lines
3.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: payments.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createPayment = `-- name: CreatePayment :one
|
|
INSERT INTO payments (user_id, amount, currency, status, payment_processor_id, paid_at)
|
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
RETURNING id, user_id, amount, currency, status, payment_processor_id, paid_at, created_at, updated_at
|
|
`
|
|
|
|
type CreatePaymentParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
Amount int64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Status string `json:"status"`
|
|
PaymentProcessorID sql.NullString `json:"payment_processor_id"`
|
|
PaidAt sql.NullTime `json:"paid_at"`
|
|
}
|
|
|
|
func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) (Payment, error) {
|
|
row := q.db.QueryRowContext(ctx, createPayment,
|
|
arg.UserID,
|
|
arg.Amount,
|
|
arg.Currency,
|
|
arg.Status,
|
|
arg.PaymentProcessorID,
|
|
arg.PaidAt,
|
|
)
|
|
var i Payment
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.PaymentProcessorID,
|
|
&i.PaidAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPaymentByID = `-- name: GetPaymentByID :one
|
|
SELECT id, user_id, amount, currency, status, payment_processor_id, paid_at, created_at, updated_at FROM payments
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) GetPaymentByID(ctx context.Context, id int64) (Payment, error) {
|
|
row := q.db.QueryRowContext(ctx, getPaymentByID, id)
|
|
var i Payment
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.PaymentProcessorID,
|
|
&i.PaidAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPaymentsByUserID = `-- name: GetPaymentsByUserID :many
|
|
SELECT id, user_id, amount, currency, status, payment_processor_id, paid_at, created_at, updated_at FROM payments
|
|
WHERE user_id = ?
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) GetPaymentsByUserID(ctx context.Context, userID int64) ([]Payment, error) {
|
|
rows, err := q.db.QueryContext(ctx, getPaymentsByUserID, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Payment{}
|
|
for rows.Next() {
|
|
var i Payment
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.PaymentProcessorID,
|
|
&i.PaidAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updatePaymentStatus = `-- name: UpdatePaymentStatus :one
|
|
UPDATE payments
|
|
SET status = ?, paid_at = CASE WHEN ? IS NOT NULL THEN ? ELSE paid_at END
|
|
WHERE id = ?
|
|
RETURNING id, user_id, amount, currency, status, payment_processor_id, paid_at, created_at, updated_at
|
|
`
|
|
|
|
type UpdatePaymentStatusParams struct {
|
|
Status string `json:"status"`
|
|
Column2 interface{} `json:"column_2"`
|
|
PaidAt sql.NullTime `json:"paid_at"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdatePaymentStatus(ctx context.Context, arg UpdatePaymentStatusParams) (Payment, error) {
|
|
row := q.db.QueryRowContext(ctx, updatePaymentStatus,
|
|
arg.Status,
|
|
arg.Column2,
|
|
arg.PaidAt,
|
|
arg.ID,
|
|
)
|
|
var i Payment
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.PaymentProcessorID,
|
|
&i.PaidAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|