413 lines
12 KiB
Go
413 lines
12 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: documents.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
const countDocuments = `-- name: CountDocuments :one
|
|
SELECT COUNT(*) FROM documents
|
|
`
|
|
|
|
func (q *Queries) CountDocuments(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countDocuments)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countDocumentsByType = `-- name: CountDocumentsByType :one
|
|
SELECT COUNT(*) FROM documents WHERE type = ?
|
|
`
|
|
|
|
func (q *Queries) CountDocumentsByType(ctx context.Context, type_ DocumentsType) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countDocumentsByType, type_)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createDocument = `-- name: CreateDocument :execresult
|
|
INSERT INTO documents (
|
|
type, created, user_id, doc_page_count, cmc_reference,
|
|
pdf_filename, pdf_created_at, pdf_created_by_user_id,
|
|
shipping_details, revision, bill_to, ship_to,
|
|
email_sent_at, email_sent_by_user_id
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
`
|
|
|
|
type CreateDocumentParams struct {
|
|
Type DocumentsType `json:"type"`
|
|
Created time.Time `json:"created"`
|
|
UserID int32 `json:"user_id"`
|
|
DocPageCount int32 `json:"doc_page_count"`
|
|
CmcReference string `json:"cmc_reference"`
|
|
PdfFilename string `json:"pdf_filename"`
|
|
PdfCreatedAt time.Time `json:"pdf_created_at"`
|
|
PdfCreatedByUserID int32 `json:"pdf_created_by_user_id"`
|
|
ShippingDetails sql.NullString `json:"shipping_details"`
|
|
Revision int32 `json:"revision"`
|
|
BillTo sql.NullString `json:"bill_to"`
|
|
ShipTo sql.NullString `json:"ship_to"`
|
|
EmailSentAt time.Time `json:"email_sent_at"`
|
|
EmailSentByUserID int32 `json:"email_sent_by_user_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateDocument(ctx context.Context, arg CreateDocumentParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createDocument,
|
|
arg.Type,
|
|
arg.Created,
|
|
arg.UserID,
|
|
arg.DocPageCount,
|
|
arg.CmcReference,
|
|
arg.PdfFilename,
|
|
arg.PdfCreatedAt,
|
|
arg.PdfCreatedByUserID,
|
|
arg.ShippingDetails,
|
|
arg.Revision,
|
|
arg.BillTo,
|
|
arg.ShipTo,
|
|
arg.EmailSentAt,
|
|
arg.EmailSentByUserID,
|
|
)
|
|
}
|
|
|
|
const deleteDocument = `-- name: DeleteDocument :exec
|
|
DELETE FROM documents WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteDocument(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, deleteDocument, id)
|
|
return err
|
|
}
|
|
|
|
const getDocument = `-- name: GetDocument :one
|
|
SELECT id, type, created, user_id, doc_page_count, cmc_reference, pdf_filename, pdf_created_at, pdf_created_by_user_id, shipping_details, revision, bill_to, ship_to, email_sent_at, email_sent_by_user_id FROM documents WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) GetDocument(ctx context.Context, id int32) (Document, error) {
|
|
row := q.db.QueryRowContext(ctx, getDocument, id)
|
|
var i Document
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Type,
|
|
&i.Created,
|
|
&i.UserID,
|
|
&i.DocPageCount,
|
|
&i.CmcReference,
|
|
&i.PdfFilename,
|
|
&i.PdfCreatedAt,
|
|
&i.PdfCreatedByUserID,
|
|
&i.ShippingDetails,
|
|
&i.Revision,
|
|
&i.BillTo,
|
|
&i.ShipTo,
|
|
&i.EmailSentAt,
|
|
&i.EmailSentByUserID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getDocumentWithUser = `-- name: GetDocumentWithUser :one
|
|
SELECT
|
|
d.id,
|
|
d.type,
|
|
d.created,
|
|
d.user_id,
|
|
d.doc_page_count,
|
|
d.cmc_reference,
|
|
d.pdf_filename,
|
|
d.pdf_created_at,
|
|
d.pdf_created_by_user_id,
|
|
d.shipping_details,
|
|
d.revision,
|
|
d.bill_to,
|
|
d.ship_to,
|
|
d.email_sent_at,
|
|
d.email_sent_by_user_id,
|
|
u.username as user_username,
|
|
u.first_name as user_first_name,
|
|
u.last_name as user_last_name,
|
|
u.email as user_email,
|
|
pu.username as pdf_creator_username,
|
|
pu.first_name as pdf_creator_first_name,
|
|
pu.last_name as pdf_creator_last_name,
|
|
pu.email as pdf_creator_email
|
|
FROM documents d
|
|
LEFT JOIN users u ON d.user_id = u.id
|
|
LEFT JOIN users pu ON d.pdf_created_by_user_id = pu.id
|
|
WHERE d.id = ?
|
|
`
|
|
|
|
type GetDocumentWithUserRow struct {
|
|
ID int32 `json:"id"`
|
|
Type DocumentsType `json:"type"`
|
|
Created time.Time `json:"created"`
|
|
UserID int32 `json:"user_id"`
|
|
DocPageCount int32 `json:"doc_page_count"`
|
|
CmcReference string `json:"cmc_reference"`
|
|
PdfFilename string `json:"pdf_filename"`
|
|
PdfCreatedAt time.Time `json:"pdf_created_at"`
|
|
PdfCreatedByUserID int32 `json:"pdf_created_by_user_id"`
|
|
ShippingDetails sql.NullString `json:"shipping_details"`
|
|
Revision int32 `json:"revision"`
|
|
BillTo sql.NullString `json:"bill_to"`
|
|
ShipTo sql.NullString `json:"ship_to"`
|
|
EmailSentAt time.Time `json:"email_sent_at"`
|
|
EmailSentByUserID int32 `json:"email_sent_by_user_id"`
|
|
UserUsername sql.NullString `json:"user_username"`
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
|
UserEmail sql.NullString `json:"user_email"`
|
|
PdfCreatorUsername sql.NullString `json:"pdf_creator_username"`
|
|
PdfCreatorFirstName sql.NullString `json:"pdf_creator_first_name"`
|
|
PdfCreatorLastName sql.NullString `json:"pdf_creator_last_name"`
|
|
PdfCreatorEmail sql.NullString `json:"pdf_creator_email"`
|
|
}
|
|
|
|
func (q *Queries) GetDocumentWithUser(ctx context.Context, id int32) (GetDocumentWithUserRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getDocumentWithUser, id)
|
|
var i GetDocumentWithUserRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Type,
|
|
&i.Created,
|
|
&i.UserID,
|
|
&i.DocPageCount,
|
|
&i.CmcReference,
|
|
&i.PdfFilename,
|
|
&i.PdfCreatedAt,
|
|
&i.PdfCreatedByUserID,
|
|
&i.ShippingDetails,
|
|
&i.Revision,
|
|
&i.BillTo,
|
|
&i.ShipTo,
|
|
&i.EmailSentAt,
|
|
&i.EmailSentByUserID,
|
|
&i.UserUsername,
|
|
&i.UserFirstName,
|
|
&i.UserLastName,
|
|
&i.UserEmail,
|
|
&i.PdfCreatorUsername,
|
|
&i.PdfCreatorFirstName,
|
|
&i.PdfCreatorLastName,
|
|
&i.PdfCreatorEmail,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getRecentDocuments = `-- name: GetRecentDocuments :many
|
|
SELECT
|
|
d.id,
|
|
d.type,
|
|
d.created,
|
|
d.cmc_reference,
|
|
d.pdf_filename,
|
|
d.revision,
|
|
u.username as created_by_username,
|
|
CASE
|
|
WHEN d.type = 'quote' THEN CONCAT('Quote ', d.cmc_reference)
|
|
WHEN d.type = 'invoice' THEN CONCAT('Invoice ', d.cmc_reference)
|
|
WHEN d.type = 'purchaseOrder' THEN CONCAT('Purchase Order ', d.cmc_reference)
|
|
WHEN d.type = 'orderAck' THEN CONCAT('Order Ack ', d.cmc_reference)
|
|
WHEN d.type = 'packingList' THEN CONCAT('Packing List ', d.cmc_reference)
|
|
ELSE CONCAT(d.type, ' ', d.cmc_reference)
|
|
END as display_name
|
|
FROM documents d
|
|
LEFT JOIN users u ON d.user_id = u.id
|
|
ORDER BY d.created DESC
|
|
LIMIT ?
|
|
`
|
|
|
|
type GetRecentDocumentsRow struct {
|
|
ID int32 `json:"id"`
|
|
Type DocumentsType `json:"type"`
|
|
Created time.Time `json:"created"`
|
|
CmcReference string `json:"cmc_reference"`
|
|
PdfFilename string `json:"pdf_filename"`
|
|
Revision int32 `json:"revision"`
|
|
CreatedByUsername sql.NullString `json:"created_by_username"`
|
|
DisplayName interface{} `json:"display_name"`
|
|
}
|
|
|
|
func (q *Queries) GetRecentDocuments(ctx context.Context, limit int32) ([]GetRecentDocumentsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getRecentDocuments, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetRecentDocumentsRow{}
|
|
for rows.Next() {
|
|
var i GetRecentDocumentsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Type,
|
|
&i.Created,
|
|
&i.CmcReference,
|
|
&i.PdfFilename,
|
|
&i.Revision,
|
|
&i.CreatedByUsername,
|
|
&i.DisplayName,
|
|
); 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 listDocuments = `-- name: ListDocuments :many
|
|
SELECT id, type, created, user_id, doc_page_count, cmc_reference, pdf_filename, pdf_created_at, pdf_created_by_user_id, shipping_details, revision, bill_to, ship_to, email_sent_at, email_sent_by_user_id FROM documents ORDER BY created DESC LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListDocumentsParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListDocuments(ctx context.Context, arg ListDocumentsParams) ([]Document, error) {
|
|
rows, err := q.db.QueryContext(ctx, listDocuments, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Document{}
|
|
for rows.Next() {
|
|
var i Document
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Type,
|
|
&i.Created,
|
|
&i.UserID,
|
|
&i.DocPageCount,
|
|
&i.CmcReference,
|
|
&i.PdfFilename,
|
|
&i.PdfCreatedAt,
|
|
&i.PdfCreatedByUserID,
|
|
&i.ShippingDetails,
|
|
&i.Revision,
|
|
&i.BillTo,
|
|
&i.ShipTo,
|
|
&i.EmailSentAt,
|
|
&i.EmailSentByUserID,
|
|
); 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 listDocumentsByType = `-- name: ListDocumentsByType :many
|
|
SELECT id, type, created, user_id, doc_page_count, cmc_reference, pdf_filename, pdf_created_at, pdf_created_by_user_id, shipping_details, revision, bill_to, ship_to, email_sent_at, email_sent_by_user_id FROM documents WHERE type = ? ORDER BY created DESC LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListDocumentsByTypeParams struct {
|
|
Type DocumentsType `json:"type"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListDocumentsByType(ctx context.Context, arg ListDocumentsByTypeParams) ([]Document, error) {
|
|
rows, err := q.db.QueryContext(ctx, listDocumentsByType, arg.Type, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Document{}
|
|
for rows.Next() {
|
|
var i Document
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Type,
|
|
&i.Created,
|
|
&i.UserID,
|
|
&i.DocPageCount,
|
|
&i.CmcReference,
|
|
&i.PdfFilename,
|
|
&i.PdfCreatedAt,
|
|
&i.PdfCreatedByUserID,
|
|
&i.ShippingDetails,
|
|
&i.Revision,
|
|
&i.BillTo,
|
|
&i.ShipTo,
|
|
&i.EmailSentAt,
|
|
&i.EmailSentByUserID,
|
|
); 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 updateDocument = `-- name: UpdateDocument :exec
|
|
UPDATE documents SET
|
|
type = ?, user_id = ?, doc_page_count = ?, cmc_reference = ?,
|
|
pdf_filename = ?, pdf_created_at = ?, pdf_created_by_user_id = ?,
|
|
shipping_details = ?, revision = ?, bill_to = ?, ship_to = ?,
|
|
email_sent_at = ?, email_sent_by_user_id = ?
|
|
WHERE id = ?
|
|
`
|
|
|
|
type UpdateDocumentParams struct {
|
|
Type DocumentsType `json:"type"`
|
|
UserID int32 `json:"user_id"`
|
|
DocPageCount int32 `json:"doc_page_count"`
|
|
CmcReference string `json:"cmc_reference"`
|
|
PdfFilename string `json:"pdf_filename"`
|
|
PdfCreatedAt time.Time `json:"pdf_created_at"`
|
|
PdfCreatedByUserID int32 `json:"pdf_created_by_user_id"`
|
|
ShippingDetails sql.NullString `json:"shipping_details"`
|
|
Revision int32 `json:"revision"`
|
|
BillTo sql.NullString `json:"bill_to"`
|
|
ShipTo sql.NullString `json:"ship_to"`
|
|
EmailSentAt time.Time `json:"email_sent_at"`
|
|
EmailSentByUserID int32 `json:"email_sent_by_user_id"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateDocument(ctx context.Context, arg UpdateDocumentParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateDocument,
|
|
arg.Type,
|
|
arg.UserID,
|
|
arg.DocPageCount,
|
|
arg.CmcReference,
|
|
arg.PdfFilename,
|
|
arg.PdfCreatedAt,
|
|
arg.PdfCreatedByUserID,
|
|
arg.ShippingDetails,
|
|
arg.Revision,
|
|
arg.BillTo,
|
|
arg.ShipTo,
|
|
arg.EmailSentAt,
|
|
arg.EmailSentByUserID,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|