// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.29.0 // source: purchase_orders.sql package db import ( "context" "database/sql" "time" ) const createPurchaseOrder = `-- name: CreatePurchaseOrder :execresult INSERT INTO purchase_orders ( issue_date, dispatch_date, date_arrived, title, principle_id, principle_reference, document_id, currency_id, ordered_from, description, dispatch_by, deliver_to, shipping_instructions, jobs_text, freight_forwarder_text, parent_purchase_order_id ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ` type CreatePurchaseOrderParams struct { IssueDate time.Time `json:"issue_date"` DispatchDate time.Time `json:"dispatch_date"` DateArrived time.Time `json:"date_arrived"` Title string `json:"title"` PrincipleID int32 `json:"principle_id"` PrincipleReference string `json:"principle_reference"` DocumentID int32 `json:"document_id"` CurrencyID sql.NullInt32 `json:"currency_id"` OrderedFrom string `json:"ordered_from"` Description string `json:"description"` DispatchBy string `json:"dispatch_by"` DeliverTo string `json:"deliver_to"` ShippingInstructions string `json:"shipping_instructions"` JobsText string `json:"jobs_text"` FreightForwarderText string `json:"freight_forwarder_text"` ParentPurchaseOrderID int32 `json:"parent_purchase_order_id"` } func (q *Queries) CreatePurchaseOrder(ctx context.Context, arg CreatePurchaseOrderParams) (sql.Result, error) { return q.db.ExecContext(ctx, createPurchaseOrder, arg.IssueDate, arg.DispatchDate, arg.DateArrived, arg.Title, arg.PrincipleID, arg.PrincipleReference, arg.DocumentID, arg.CurrencyID, arg.OrderedFrom, arg.Description, arg.DispatchBy, arg.DeliverTo, arg.ShippingInstructions, arg.JobsText, arg.FreightForwarderText, arg.ParentPurchaseOrderID, ) } const deletePurchaseOrder = `-- name: DeletePurchaseOrder :exec DELETE FROM purchase_orders WHERE id = ? ` func (q *Queries) DeletePurchaseOrder(ctx context.Context, id int32) error { _, err := q.db.ExecContext(ctx, deletePurchaseOrder, id) return err } const getPurchaseOrder = `-- name: GetPurchaseOrder :one SELECT id, issue_date, dispatch_date, date_arrived, title, principle_id, principle_reference, document_id, currency_id, ordered_from, description, dispatch_by, deliver_to, shipping_instructions, jobs_text, freight_forwarder_text, parent_purchase_order_id FROM purchase_orders WHERE id = ? LIMIT 1 ` func (q *Queries) GetPurchaseOrder(ctx context.Context, id int32) (PurchaseOrder, error) { row := q.db.QueryRowContext(ctx, getPurchaseOrder, id) var i PurchaseOrder err := row.Scan( &i.ID, &i.IssueDate, &i.DispatchDate, &i.DateArrived, &i.Title, &i.PrincipleID, &i.PrincipleReference, &i.DocumentID, &i.CurrencyID, &i.OrderedFrom, &i.Description, &i.DispatchBy, &i.DeliverTo, &i.ShippingInstructions, &i.JobsText, &i.FreightForwarderText, &i.ParentPurchaseOrderID, ) return i, err } const getPurchaseOrderRevisions = `-- name: GetPurchaseOrderRevisions :many SELECT id, issue_date, dispatch_date, date_arrived, title, principle_id, principle_reference, document_id, currency_id, ordered_from, description, dispatch_by, deliver_to, shipping_instructions, jobs_text, freight_forwarder_text, parent_purchase_order_id FROM purchase_orders WHERE parent_purchase_order_id = ? ORDER BY id DESC ` func (q *Queries) GetPurchaseOrderRevisions(ctx context.Context, parentPurchaseOrderID int32) ([]PurchaseOrder, error) { rows, err := q.db.QueryContext(ctx, getPurchaseOrderRevisions, parentPurchaseOrderID) if err != nil { return nil, err } defer rows.Close() items := []PurchaseOrder{} for rows.Next() { var i PurchaseOrder if err := rows.Scan( &i.ID, &i.IssueDate, &i.DispatchDate, &i.DateArrived, &i.Title, &i.PrincipleID, &i.PrincipleReference, &i.DocumentID, &i.CurrencyID, &i.OrderedFrom, &i.Description, &i.DispatchBy, &i.DeliverTo, &i.ShippingInstructions, &i.JobsText, &i.FreightForwarderText, &i.ParentPurchaseOrderID, ); 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 getPurchaseOrdersByPrinciple = `-- name: GetPurchaseOrdersByPrinciple :many SELECT id, issue_date, dispatch_date, date_arrived, title, principle_id, principle_reference, document_id, currency_id, ordered_from, description, dispatch_by, deliver_to, shipping_instructions, jobs_text, freight_forwarder_text, parent_purchase_order_id FROM purchase_orders WHERE principle_id = ? ORDER BY issue_date DESC LIMIT ? OFFSET ? ` type GetPurchaseOrdersByPrincipleParams struct { PrincipleID int32 `json:"principle_id"` Limit int32 `json:"limit"` Offset int32 `json:"offset"` } func (q *Queries) GetPurchaseOrdersByPrinciple(ctx context.Context, arg GetPurchaseOrdersByPrincipleParams) ([]PurchaseOrder, error) { rows, err := q.db.QueryContext(ctx, getPurchaseOrdersByPrinciple, arg.PrincipleID, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() items := []PurchaseOrder{} for rows.Next() { var i PurchaseOrder if err := rows.Scan( &i.ID, &i.IssueDate, &i.DispatchDate, &i.DateArrived, &i.Title, &i.PrincipleID, &i.PrincipleReference, &i.DocumentID, &i.CurrencyID, &i.OrderedFrom, &i.Description, &i.DispatchBy, &i.DeliverTo, &i.ShippingInstructions, &i.JobsText, &i.FreightForwarderText, &i.ParentPurchaseOrderID, ); 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 listPurchaseOrders = `-- name: ListPurchaseOrders :many SELECT id, issue_date, dispatch_date, date_arrived, title, principle_id, principle_reference, document_id, currency_id, ordered_from, description, dispatch_by, deliver_to, shipping_instructions, jobs_text, freight_forwarder_text, parent_purchase_order_id FROM purchase_orders ORDER BY issue_date DESC LIMIT ? OFFSET ? ` type ListPurchaseOrdersParams struct { Limit int32 `json:"limit"` Offset int32 `json:"offset"` } func (q *Queries) ListPurchaseOrders(ctx context.Context, arg ListPurchaseOrdersParams) ([]PurchaseOrder, error) { rows, err := q.db.QueryContext(ctx, listPurchaseOrders, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() items := []PurchaseOrder{} for rows.Next() { var i PurchaseOrder if err := rows.Scan( &i.ID, &i.IssueDate, &i.DispatchDate, &i.DateArrived, &i.Title, &i.PrincipleID, &i.PrincipleReference, &i.DocumentID, &i.CurrencyID, &i.OrderedFrom, &i.Description, &i.DispatchBy, &i.DeliverTo, &i.ShippingInstructions, &i.JobsText, &i.FreightForwarderText, &i.ParentPurchaseOrderID, ); 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 searchPurchaseOrdersByTitle = `-- name: SearchPurchaseOrdersByTitle :many SELECT id, issue_date, dispatch_date, date_arrived, title, principle_id, principle_reference, document_id, currency_id, ordered_from, description, dispatch_by, deliver_to, shipping_instructions, jobs_text, freight_forwarder_text, parent_purchase_order_id FROM purchase_orders WHERE title LIKE CONCAT('%', ?, '%') ORDER BY issue_date DESC LIMIT ? OFFSET ? ` type SearchPurchaseOrdersByTitleParams struct { CONCAT interface{} `json:"CONCAT"` Limit int32 `json:"limit"` Offset int32 `json:"offset"` } func (q *Queries) SearchPurchaseOrdersByTitle(ctx context.Context, arg SearchPurchaseOrdersByTitleParams) ([]PurchaseOrder, error) { rows, err := q.db.QueryContext(ctx, searchPurchaseOrdersByTitle, arg.CONCAT, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() items := []PurchaseOrder{} for rows.Next() { var i PurchaseOrder if err := rows.Scan( &i.ID, &i.IssueDate, &i.DispatchDate, &i.DateArrived, &i.Title, &i.PrincipleID, &i.PrincipleReference, &i.DocumentID, &i.CurrencyID, &i.OrderedFrom, &i.Description, &i.DispatchBy, &i.DeliverTo, &i.ShippingInstructions, &i.JobsText, &i.FreightForwarderText, &i.ParentPurchaseOrderID, ); 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 updatePurchaseOrder = `-- name: UpdatePurchaseOrder :exec UPDATE purchase_orders SET issue_date = ?, dispatch_date = ?, date_arrived = ?, title = ?, principle_id = ?, principle_reference = ?, document_id = ?, currency_id = ?, ordered_from = ?, description = ?, dispatch_by = ?, deliver_to = ?, shipping_instructions = ?, jobs_text = ?, freight_forwarder_text = ?, parent_purchase_order_id = ? WHERE id = ? ` type UpdatePurchaseOrderParams struct { IssueDate time.Time `json:"issue_date"` DispatchDate time.Time `json:"dispatch_date"` DateArrived time.Time `json:"date_arrived"` Title string `json:"title"` PrincipleID int32 `json:"principle_id"` PrincipleReference string `json:"principle_reference"` DocumentID int32 `json:"document_id"` CurrencyID sql.NullInt32 `json:"currency_id"` OrderedFrom string `json:"ordered_from"` Description string `json:"description"` DispatchBy string `json:"dispatch_by"` DeliverTo string `json:"deliver_to"` ShippingInstructions string `json:"shipping_instructions"` JobsText string `json:"jobs_text"` FreightForwarderText string `json:"freight_forwarder_text"` ParentPurchaseOrderID int32 `json:"parent_purchase_order_id"` ID int32 `json:"id"` } func (q *Queries) UpdatePurchaseOrder(ctx context.Context, arg UpdatePurchaseOrderParams) error { _, err := q.db.ExecContext(ctx, updatePurchaseOrder, arg.IssueDate, arg.DispatchDate, arg.DateArrived, arg.Title, arg.PrincipleID, arg.PrincipleReference, arg.DocumentID, arg.CurrencyID, arg.OrderedFrom, arg.Description, arg.DispatchBy, arg.DeliverTo, arg.ShippingInstructions, arg.JobsText, arg.FreightForwarderText, arg.ParentPurchaseOrderID, arg.ID, ) return err }