// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.29.0 // source: raffle.sql package dbgen import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const CreateRaffle = `-- name: CreateRaffle :one INSERT INTO raffles (company_id, name, expires_at, type) VALUES ($1, $2, $3, $4) RETURNING id, company_id, name, created_at, expires_at, type, status ` type CreateRaffleParams struct { CompanyID int32 `json:"company_id"` Name string `json:"name"` ExpiresAt pgtype.Timestamp `json:"expires_at"` Type string `json:"type"` } func (q *Queries) CreateRaffle(ctx context.Context, arg CreateRaffleParams) (Raffle, error) { row := q.db.QueryRow(ctx, CreateRaffle, arg.CompanyID, arg.Name, arg.ExpiresAt, arg.Type, ) var i Raffle err := row.Scan( &i.ID, &i.CompanyID, &i.Name, &i.CreatedAt, &i.ExpiresAt, &i.Type, &i.Status, ) return i, err } const CreateRaffleTicket = `-- name: CreateRaffleTicket :one INSERT INTO raffle_tickets (raffle_id, user_id) VALUES ($1, $2) RETURNING id, raffle_id, user_id, is_active ` type CreateRaffleTicketParams struct { RaffleID int32 `json:"raffle_id"` UserID int32 `json:"user_id"` } func (q *Queries) CreateRaffleTicket(ctx context.Context, arg CreateRaffleTicketParams) (RaffleTicket, error) { row := q.db.QueryRow(ctx, CreateRaffleTicket, arg.RaffleID, arg.UserID) var i RaffleTicket err := row.Scan( &i.ID, &i.RaffleID, &i.UserID, &i.IsActive, ) return i, err } const DeleteRaffle = `-- name: DeleteRaffle :one DELETE FROM raffles WHERE id = $1 RETURNING id, company_id, name, created_at, expires_at, type, status ` func (q *Queries) DeleteRaffle(ctx context.Context, id int32) (Raffle, error) { row := q.db.QueryRow(ctx, DeleteRaffle, id) var i Raffle err := row.Scan( &i.ID, &i.CompanyID, &i.Name, &i.CreatedAt, &i.ExpiresAt, &i.Type, &i.Status, ) return i, err } const GetRafflesOfCompany = `-- name: GetRafflesOfCompany :many SELECT id, company_id, name, created_at, expires_at, type, status FROM raffles WHERE company_id = $1 ` func (q *Queries) GetRafflesOfCompany(ctx context.Context, companyID int32) ([]Raffle, error) { rows, err := q.db.Query(ctx, GetRafflesOfCompany, companyID) if err != nil { return nil, err } defer rows.Close() var items []Raffle for rows.Next() { var i Raffle if err := rows.Scan( &i.ID, &i.CompanyID, &i.Name, &i.CreatedAt, &i.ExpiresAt, &i.Type, &i.Status, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const GetUserRaffleTickets = `-- name: GetUserRaffleTickets :many SELECT rt.id AS ticket_id, rt.user_id, r.name, r.type, r.expires_at, r.status FROM raffle_tickets rt JOIN raffles r ON rt.raffle_id = r.id WHERE rt.user_id = $1 ` type GetUserRaffleTicketsRow struct { TicketID int32 `json:"ticket_id"` UserID int32 `json:"user_id"` Name string `json:"name"` Type string `json:"type"` ExpiresAt pgtype.Timestamp `json:"expires_at"` Status string `json:"status"` } func (q *Queries) GetUserRaffleTickets(ctx context.Context, userID int32) ([]GetUserRaffleTicketsRow, error) { rows, err := q.db.Query(ctx, GetUserRaffleTickets, userID) if err != nil { return nil, err } defer rows.Close() var items []GetUserRaffleTicketsRow for rows.Next() { var i GetUserRaffleTicketsRow if err := rows.Scan( &i.TicketID, &i.UserID, &i.Name, &i.Type, &i.ExpiresAt, &i.Status, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const UpdateRaffleTicketStatus = `-- name: UpdateRaffleTicketStatus :exec UPDATE raffle_tickets SET is_active = $1 WHERE id = $2 ` type UpdateRaffleTicketStatusParams struct { IsActive pgtype.Bool `json:"is_active"` ID int32 `json:"id"` } func (q *Queries) UpdateRaffleTicketStatus(ctx context.Context, arg UpdateRaffleTicketStatusParams) error { _, err := q.db.Exec(ctx, UpdateRaffleTicketStatus, arg.IsActive, arg.ID) return err }