send all files

This commit is contained in:
2024-07-21 00:15:14 -03:00
parent 1e8cda0139
commit c9464c4a6f
72 changed files with 6335 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.26.0
package products
import (
"context"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
type DBTX interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}
+15
View File
@@ -0,0 +1,15 @@
package products
type Product struct {
CreatedBy string `json:"createdBy"`
CreatedAt uint64 `json:"createdAt"`
UpdatedBy *string `json:"updatedBy"`
UpdatedAt *uint64 `json:"updatedAt"`
Nome string `json:"nome"`
Codigo string `json:"codigo"`
EstoqueTotal int64 `json:"estoqueTotal"`
EstoqueCorte int64 `json:"estoqueCorte"`
EstoqueDisponivel int64 `json:"estoqueDisponivel"`
PrecoDe float32 `json:"precoDe"`
PrecoPor float32 `json:"precoPor"`
}
+174
View File
@@ -0,0 +1,174 @@
package products
import (
"context"
"time"
)
const createProduct = `-- name: CreateProduct :one
INSERT INTO products (
created_at, created_by, updated_at, updated_by, nome, codigo, estoque_total, estoque_corte, estoque_disponivel, preco_de, preco_por
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
)
RETURNING created_by, created_at, updated_by, updated_at, nome, codigo, estoque_total, estoque_corte, estoque_disponivel, preco_de, preco_por
`
type CreateProductParams struct {
CreatedAt uint64
CreatedBy string
UpdatedAt uint64
UpdatedBy string
Nome string
Codigo string
EstoqueTotal int64
EstoqueCorte int64
EstoqueDisponivel int64
PrecoDe float32
PrecoPor float32
}
func (q *Queries) CreateProduct(ctx context.Context, userId string, arg CreateProductParams) (Product, error) {
t := time.Now().Unix()
row := q.db.QueryRow(ctx, createProduct,
t,
userId,
nil,
nil,
arg.Nome,
arg.Codigo,
arg.EstoqueTotal,
arg.EstoqueCorte,
arg.EstoqueDisponivel,
arg.PrecoDe,
arg.PrecoPor,
)
var i Product
err := row.Scan(
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedBy,
&i.UpdatedAt,
&i.Nome,
&i.Codigo,
&i.EstoqueTotal,
&i.EstoqueCorte,
&i.EstoqueDisponivel,
&i.PrecoDe,
&i.PrecoPor,
)
return i, err
}
const getProduct = `-- name: GetProduct :one
SELECT created_by, created_at, updated_by, updated_at, nome, codigo, estoque_total, estoque_corte, estoque_disponivel, preco_de, preco_por FROM products
WHERE codigo = $1 LIMIT 1
`
func (q *Queries) GetProduct(ctx context.Context, codigo string) (Product, error) {
row := q.db.QueryRow(ctx, getProduct, codigo)
var i Product
err := row.Scan(
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedBy,
&i.UpdatedAt,
&i.Nome,
&i.Codigo,
&i.EstoqueTotal,
&i.EstoqueCorte,
&i.EstoqueDisponivel,
&i.PrecoDe,
&i.PrecoPor,
)
return i, err
}
const listProducts = `-- name: ListProducts :many
SELECT created_by, created_at, updated_by, updated_at, nome, codigo, estoque_total, estoque_corte, estoque_disponivel, preco_de, preco_por FROM products
ORDER BY created_at
`
func (q *Queries) ListProducts(ctx context.Context) ([]Product, error) {
rows, err := q.db.Query(ctx, listProducts)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Product
for rows.Next() {
var i Product
if err := rows.Scan(
&i.CreatedBy,
&i.CreatedAt,
&i.UpdatedBy,
&i.UpdatedAt,
&i.Nome,
&i.Codigo,
&i.EstoqueTotal,
&i.EstoqueCorte,
&i.EstoqueDisponivel,
&i.PrecoDe,
&i.PrecoPor,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateProduct = `-- name: UpdateProduct :exec
UPDATE products
SET
updated_at = $2,
updated_by = $3,
nome = $4,
estoque_total = $5,
estoque_corte = $6,
estoque_disponivel = $7,
preco_de = $8,
preco_por = $9
WHERE codigo = $1
`
type UpdateProductParams struct {
UpdatedAt uint64
UpdatedBy string
Nome string
Codigo string
EstoqueTotal int64
EstoqueCorte int64
EstoqueDisponivel int64
PrecoDe float32
PrecoPor float32
}
func (q *Queries) UpdateProduct(ctx context.Context, userId string, arg UpdateProductParams) error {
t := time.Now().Unix()
_, err := q.db.Exec(ctx, updateProduct,
arg.Codigo,
t,
userId,
arg.Nome,
arg.EstoqueTotal,
arg.EstoqueCorte,
arg.EstoqueDisponivel,
arg.PrecoDe,
arg.PrecoPor,
)
return err
}
const deleteProduct = `-- name: DeleteProduct :exec
DELETE FROM products
WHERE codigo = $1
`
func (q *Queries) DeleteProduct(ctx context.Context, codigo string) error {
_, err := q.db.Exec(ctx, deleteProduct, codigo)
return err
}
+32
View File
@@ -0,0 +1,32 @@
-- name: GetProduct :one
SELECT * FROM products
WHERE codigo = $1 LIMIT 1;
-- name: ListProducts :many
SELECT * FROM products
ORDER BY created_at;
-- name: CreateProduct :one
INSERT INTO products (
created_at, created_by, updated_at, updated_by, nome, codigo, estoque_total, estoque_corte, estoque_disponivel, preco_de, preco_por
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
)
RETURNING *;
-- name: UpdateProduct :exec
UPDATE products
SET
updated_at = $2,
updated_by = $3,
nome = $4,
estoque_total = $5,
estoque_corte = $6,
estoque_disponivel = $7,
preco_de = $8,
preco_por = $9
WHERE codigo = $1;
-- name: DeleteProduct :exec
DELETE FROM products
WHERE codigo = $1;
+15
View File
@@ -0,0 +1,15 @@
CREATE TABLE products (
product UUID NOT NULL,
created_by UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_by UUID,
updated_at TIMESTAMP,
nome text NOT NULL,
codigo text NOT NULL,
estoque_total BIGINT NOT NULL,
estoque_corte BIGINT NOT NULL,
estoque_disponivel BIGINT NOT NULL,
preco_de NUMERIC NOT NULL,
preco_por NUMERIC NOT NULL
)
+11
View File
@@ -0,0 +1,11 @@
version: "2
sql:
- engine: "postgresql"
queries: "query.sql"
schema: "schema.sql"
gen:
go:
package: "products"
out: "./"
sql_package: "pgx/v5"