Files
ExpSplitter/src/expenses/db/repository/shares.sql.go
T

111 lines
2.4 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: shares.sql
package repository
import (
"context"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgtype"
)
const deleteShare = `-- name: DeleteShare :execresult
DELETE FROM "expensesShares" where "ExpShareID" = $1
`
func (q *Queries) DeleteShare(ctx context.Context, expshareid int32) (pgconn.CommandTag, error) {
return q.db.Exec(ctx, deleteShare, expshareid)
}
const getShares = `-- name: GetShares :many
SELECT
shares."ExpShareID", shares."ExpID", shares."UserID", shares."Share", shares."Calculated", users."UserID", users."UserName", users."UserPass"
FROM
"expensesShares" as shares
JOIN
users as users ON users.UserID = shares.UserID
WHERE "ExpID" = $1
`
type GetSharesRow struct {
ExpensesShare ExpensesShare
User User
}
func (q *Queries) GetShares(ctx context.Context, expid int32) ([]GetSharesRow, error) {
rows, err := q.db.Query(ctx, getShares, expid)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetSharesRow
for rows.Next() {
var i GetSharesRow
if err := rows.Scan(
&i.ExpensesShare.ExpShareID,
&i.ExpensesShare.ExpID,
&i.ExpensesShare.UserID,
&i.ExpensesShare.Share,
&i.ExpensesShare.Calculated,
&i.User.UserID,
&i.User.UserName,
&i.User.UserPass,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const insertShare = `-- name: InsertShare :execresult
INSERT INTO "expensesShares"(
"ExpID", "UserID", "Share", "Calculated"
)
VALUES($1, $2, $3, $4)
`
type InsertShareParams struct {
ExpID int32
UserID int32
Share pgtype.Numeric
Calculated pgtype.Numeric
}
func (q *Queries) InsertShare(ctx context.Context, arg InsertShareParams) (pgconn.CommandTag, error) {
return q.db.Exec(ctx, insertShare,
arg.ExpID,
arg.UserID,
arg.Share,
arg.Calculated,
)
}
const updateShare = `-- name: UpdateShare :execresult
UPDATE "expensesShares"
SET "UserID" = $1, "Share" = $2, "Calculated" = $3
WHERE "ExpShareID" = $4
`
type UpdateShareParams struct {
UserID int32
Share pgtype.Numeric
Calculated pgtype.Numeric
ExpShareID int32
}
func (q *Queries) UpdateShare(ctx context.Context, arg UpdateShareParams) (pgconn.CommandTag, error) {
return q.db.Exec(ctx, updateShare,
arg.UserID,
arg.Share,
arg.Calculated,
arg.ExpShareID,
)
}