// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.17.2 // source: products.sql package db import ( "context" "database/sql" "github.com/google/uuid" ) const createProduct = `-- name: CreateProduct :one INSERT INTO products ( merchant_id, name, selling_price, purchase_price, stock ) VALUES ( $1, $2, $3, $4, $5 ) RETURNING id, merchant_id, index_id, name, selling_price, purchase_price, stock, created_at, updated_at ` type CreateProductParams struct { MerchantID uuid.UUID `json:"merchant_id"` Name string `json:"name"` SellingPrice float64 `json:"selling_price"` PurchasePrice float64 `json:"purchase_price"` Stock float64 `json:"stock"` } func (q *Queries) CreateProduct(ctx context.Context, arg CreateProductParams) (Product, error) { row := q.db.QueryRowContext(ctx, createProduct, arg.MerchantID, arg.Name, arg.SellingPrice, arg.PurchasePrice, arg.Stock, ) var i Product err := row.Scan( &i.ID, &i.MerchantID, &i.IndexID, &i.Name, &i.SellingPrice, &i.PurchasePrice, &i.Stock, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const deleteProduct = `-- name: DeleteProduct :exec DELETE FROM products WHERE id = $1 ` func (q *Queries) DeleteProduct(ctx context.Context, id uuid.UUID) error { _, err := q.db.ExecContext(ctx, deleteProduct, id) return err } const getProduct = `-- name: GetProduct :one SELECT id, merchant_id, index_id, name, selling_price, purchase_price, stock, created_at, updated_at FROM products WHERE id = $1 ` func (q *Queries) GetProduct(ctx context.Context, id uuid.UUID) (Product, error) { row := q.db.QueryRowContext(ctx, getProduct, id) var i Product err := row.Scan( &i.ID, &i.MerchantID, &i.IndexID, &i.Name, &i.SellingPrice, &i.PurchasePrice, &i.Stock, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const getStockForUpdateStock = `-- name: GetStockForUpdateStock :one SELECT id, merchant_id, index_id, name, selling_price, purchase_price, stock, created_at, updated_at FROM products WHERE id = $1 LIMIT 1 FOR NO KEY UPDATE ` func (q *Queries) GetStockForUpdateStock(ctx context.Context, id uuid.UUID) (Product, error) { row := q.db.QueryRowContext(ctx, getStockForUpdateStock, id) var i Product err := row.Scan( &i.ID, &i.MerchantID, &i.IndexID, &i.Name, &i.SellingPrice, &i.PurchasePrice, &i.Stock, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const listProducts = `-- name: ListProducts :many SELECT id, merchant_id, index_id, name, selling_price, purchase_price, stock, created_at, updated_at FROM products ORDER BY index_id LIMIT $1 OFFSET $2 ` type ListProductsParams struct { Limit int32 `json:"limit"` Offset int32 `json:"offset"` } func (q *Queries) ListProducts(ctx context.Context, arg ListProductsParams) ([]Product, error) { rows, err := q.db.QueryContext(ctx, listProducts, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() var items []Product for rows.Next() { var i Product if err := rows.Scan( &i.ID, &i.MerchantID, &i.IndexID, &i.Name, &i.SellingPrice, &i.PurchasePrice, &i.Stock, &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 updateProduct = `-- name: UpdateProduct :one UPDATE products SET name = $2, selling_price = $3, purchase_price = $4, stock = $5, updated_at = $6 WHERE id = $1 RETURNING id, merchant_id, index_id, name, selling_price, purchase_price, stock, created_at, updated_at ` type UpdateProductParams struct { ID uuid.UUID `json:"id"` Name string `json:"name"` SellingPrice float64 `json:"selling_price"` PurchasePrice float64 `json:"purchase_price"` Stock float64 `json:"stock"` UpdatedAt sql.NullTime `json:"updated_at"` } func (q *Queries) UpdateProduct(ctx context.Context, arg UpdateProductParams) (Product, error) { row := q.db.QueryRowContext(ctx, updateProduct, arg.ID, arg.Name, arg.SellingPrice, arg.PurchasePrice, arg.Stock, arg.UpdatedAt, ) var i Product err := row.Scan( &i.ID, &i.MerchantID, &i.IndexID, &i.Name, &i.SellingPrice, &i.PurchasePrice, &i.Stock, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const updateProductStock = `-- name: UpdateProductStock :exec UPDATE products SET stock = $1 WHERE id = $2 ` type UpdateProductStockParams struct { Stock float64 `json:"stock"` ID uuid.UUID `json:"id"` } func (q *Queries) UpdateProductStock(ctx context.Context, arg UpdateProductStockParams) error { _, err := q.db.ExecContext(ctx, updateProductStock, arg.Stock, arg.ID) return err }