// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.17.2 // source: product.sql package db import ( "context" "database/sql" "github.com/google/uuid" ) const createProduct = `-- name: CreateProduct :one INSERT INTO products ( merchant_id, name, selling_price, product_type_id, purchase_price, product_category_id, image, stock ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8 ) RETURNING id, merchant_id, product_type_id, index_id, name, selling_price, purchase_price, stock, created_at, updated_at, product_category_id, image ` type CreateProductParams struct { MerchantID uuid.UUID `json:"merchant_id"` Name string `json:"name"` SellingPrice float64 `json:"selling_price"` ProductTypeID int16 `json:"product_type_id"` PurchasePrice float64 `json:"purchase_price"` ProductCategoryID uuid.UUID `json:"product_category_id"` Image sql.NullString `json:"image"` 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.ProductTypeID, arg.PurchasePrice, arg.ProductCategoryID, arg.Image, arg.Stock, ) var i Product err := row.Scan( &i.ID, &i.MerchantID, &i.ProductTypeID, &i.IndexID, &i.Name, &i.SellingPrice, &i.PurchasePrice, &i.Stock, &i.CreatedAt, &i.UpdatedAt, &i.ProductCategoryID, &i.Image, ) 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, product_type_id, index_id, name, selling_price, purchase_price, stock, created_at, updated_at, product_category_id, image 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.ProductTypeID, &i.IndexID, &i.Name, &i.SellingPrice, &i.PurchasePrice, &i.Stock, &i.CreatedAt, &i.UpdatedAt, &i.ProductCategoryID, &i.Image, ) return i, err } const getStockForUpdateStock = `-- name: GetStockForUpdateStock :one SELECT id, merchant_id, product_type_id, index_id, name, selling_price, purchase_price, stock, created_at, updated_at, product_category_id, image 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.ProductTypeID, &i.IndexID, &i.Name, &i.SellingPrice, &i.PurchasePrice, &i.Stock, &i.CreatedAt, &i.UpdatedAt, &i.ProductCategoryID, &i.Image, ) return i, err } const listProducts = `-- name: ListProducts :many SELECT id, merchant_id, product_type_id, index_id, name, selling_price, purchase_price, stock, created_at, updated_at, product_category_id, image FROM products WHERE merchant_id = $1 ORDER BY index_id LIMIT $2 OFFSET $3 ` type ListProductsParams struct { MerchantID uuid.UUID `json:"merchant_id"` 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.MerchantID, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() items := []Product{} for rows.Next() { var i Product if err := rows.Scan( &i.ID, &i.MerchantID, &i.ProductTypeID, &i.IndexID, &i.Name, &i.SellingPrice, &i.PurchasePrice, &i.Stock, &i.CreatedAt, &i.UpdatedAt, &i.ProductCategoryID, &i.Image, ); 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, product_category_id = $5, image = $6, updated_at = $7 WHERE id = $1 RETURNING id, merchant_id, product_type_id, index_id, name, selling_price, purchase_price, stock, created_at, updated_at, product_category_id, image ` type UpdateProductParams struct { ID uuid.UUID `json:"id"` Name string `json:"name"` SellingPrice float64 `json:"selling_price"` PurchasePrice float64 `json:"purchase_price"` ProductCategoryID uuid.UUID `json:"product_category_id"` Image sql.NullString `json:"image"` 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.ProductCategoryID, arg.Image, arg.UpdatedAt, ) var i Product err := row.Scan( &i.ID, &i.MerchantID, &i.ProductTypeID, &i.IndexID, &i.Name, &i.SellingPrice, &i.PurchasePrice, &i.Stock, &i.CreatedAt, &i.UpdatedAt, &i.ProductCategoryID, &i.Image, ) 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 }