feat: sqlc, nix formatting

This commit is contained in:
2025-04-16 00:58:44 -04:00
parent 32f85fd0be
commit 967e2650ad
74 changed files with 1962 additions and 6811 deletions

View File

@ -0,0 +1,31 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
package sqlc
import (
"context"
"database/sql"
)
type DBTX interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
return &Queries{
db: tx,
}
}

View File

@ -0,0 +1,113 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: file.sql
package sqlc
import (
"context"
)
const deleteFile = `-- name: DeleteFile :exec
DELETE FROM file
WHERE
id = ?1
AND
user_id = ?2
`
type DeleteFileParams struct {
ID int64
UserID int64
}
func (q *Queries) DeleteFile(ctx context.Context, arg DeleteFileParams) error {
_, err := q.db.ExecContext(ctx, deleteFile, arg.ID, arg.UserID)
return err
}
const getFile = `-- name: GetFile :one
SELECT
id,
name,
data,
user_id
FROM file
WHERE
id = ?1
AND
user_id = ?2
LIMIT 1
`
type GetFileParams struct {
ID int64
UserID int64
}
func (q *Queries) GetFile(ctx context.Context, arg GetFileParams) (File, error) {
row := q.db.QueryRowContext(ctx, getFile, arg.ID, arg.UserID)
var i File
err := row.Scan(
&i.ID,
&i.Name,
&i.Data,
&i.UserID,
)
return i, err
}
const insertFile = `-- name: InsertFile :one
INSERT INTO file (
name,
data,
user_id
) VALUES (
?1,
?2,
?3
)
RETURNING id
`
type InsertFileParams struct {
Name string
Data []byte
UserID int64
}
func (q *Queries) InsertFile(ctx context.Context, arg InsertFileParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertFile, arg.Name, arg.Data, arg.UserID)
var id int64
err := row.Scan(&id)
return id, err
}
const updateFile = `-- name: UpdateFile :exec
UPDATE file
SET
name = COALESCE(?1, name),
data = COALESCE(?2, data)
WHERE
id = ?3
AND
user_id = ?4
`
type UpdateFileParams struct {
Name *string
Data []byte
ID int64
UserID int64
}
func (q *Queries) UpdateFile(ctx context.Context, arg UpdateFileParams) error {
_, err := q.db.ExecContext(ctx, updateFile,
arg.Name,
arg.Data,
arg.ID,
arg.UserID,
)
return err
}

View File

@ -0,0 +1,250 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: item.sql
package sqlc
import (
"context"
"time"
)
const deleteItem = `-- name: DeleteItem :exec
DELETE FROM item
WHERE
id = ?1
AND
user_id = ?2
`
type DeleteItemParams struct {
ID int64
UserID int64
}
func (q *Queries) DeleteItem(ctx context.Context, arg DeleteItemParams) error {
_, err := q.db.ExecContext(ctx, deleteItem, arg.ID, arg.UserID)
return err
}
const getItem = `-- name: GetItem :one
SELECT
id,
name,
added,
description,
price,
quantity,
user_id
FROM item
WHERE
id = ?1
AND
user_id = ?2
LIMIT 1
`
type GetItemParams struct {
ID int64
UserID int64
}
func (q *Queries) GetItem(ctx context.Context, arg GetItemParams) (Item, error) {
row := q.db.QueryRowContext(ctx, getItem, arg.ID, arg.UserID)
var i Item
err := row.Scan(
&i.ID,
&i.Name,
&i.Added,
&i.Description,
&i.Price,
&i.Quantity,
&i.UserID,
)
return i, err
}
const getItems = `-- name: GetItems :many
SELECT
id,
name,
added,
description,
price,
quantity,
user_id
FROM item
WHERE
user_id = ?1
AND
(
(name LIKE ?2 OR ?2 IS NULL)
AND
(added >= ?3 OR ?3 IS NULL)
AND
(added <= ?4 OR ?4 IS NULL)
)
LIMIT
?6
OFFSET
?5
`
type GetItemsParams struct {
UserID int64
Name *string
Start *time.Time
End *time.Time
Offset int64
Limit int64
}
func (q *Queries) GetItems(ctx context.Context, arg GetItemsParams) ([]Item, error) {
rows, err := q.db.QueryContext(ctx, getItems,
arg.UserID,
arg.Name,
arg.Start,
arg.End,
arg.Offset,
arg.Limit,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Item
for rows.Next() {
var i Item
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Added,
&i.Description,
&i.Price,
&i.Quantity,
&i.UserID,
); 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 getItemsCount = `-- name: GetItemsCount :one
SELECT COUNT(id)
FROM item
WHERE
user_id = ?1
AND
(
(name LIKE ?2 OR ?2 IS NULL)
AND
(added >= ?3 OR ?3 IS NULL)
AND
(added <= ?4 OR ?4 IS NULL)
)
LIMIT 1
`
type GetItemsCountParams struct {
UserID int64
Name *string
Start *time.Time
End *time.Time
}
func (q *Queries) GetItemsCount(ctx context.Context, arg GetItemsCountParams) (int64, error) {
row := q.db.QueryRowContext(ctx, getItemsCount,
arg.UserID,
arg.Name,
arg.Start,
arg.End,
)
var count int64
err := row.Scan(&count)
return count, err
}
const insertItem = `-- name: InsertItem :one
INSERT INTO item (
name,
added,
description,
price,
quantity,
user_id
) VALUES (
?1,
?2,
?3,
?4,
?5,
?6
)
RETURNING id
`
type InsertItemParams struct {
Name string
Added time.Time
Description string
Price float64
Quantity int64
UserID int64
}
func (q *Queries) InsertItem(ctx context.Context, arg InsertItemParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertItem,
arg.Name,
arg.Added,
arg.Description,
arg.Price,
arg.Quantity,
arg.UserID,
)
var id int64
err := row.Scan(&id)
return id, err
}
const updateItem = `-- name: UpdateItem :exec
UPDATE item
SET
name = COALESCE(?1, name),
description = COALESCE(?2, description),
price = COALESCE(?3, price),
quantity = COALESCE(?4, quantity)
WHERE
id = ?5
AND
user_id = ?6
`
type UpdateItemParams struct {
Name *string
Description *string
Price *float64
Quantity *int64
ID int64
UserID int64
}
func (q *Queries) UpdateItem(ctx context.Context, arg UpdateItemParams) error {
_, err := q.db.ExecContext(ctx, updateItem,
arg.Name,
arg.Description,
arg.Price,
arg.Quantity,
arg.ID,
arg.UserID,
)
return err
}

View File

@ -0,0 +1,37 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
package sqlc
import (
"time"
)
type File struct {
ID int64
Name string
Data []byte
UserID int64
}
type Item struct {
ID int64
Name string
Added time.Time
Description string
Price float64
Quantity int64
UserID int64
}
type SchemaMigration struct {
Version string
}
type User struct {
ID int64
Username string
Password string
ProfilePictureID *int64
}

View File

@ -0,0 +1,120 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: user.sql
package sqlc
import (
"context"
)
const deleteUser = `-- name: DeleteUser :exec
DELETE FROM user
WHERE id = ?1
`
func (q *Queries) DeleteUser(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteUser, id)
return err
}
const getUser = `-- name: GetUser :one
SELECT
id,
username,
password,
profile_picture_id
FROM user
WHERE
id = ?1
LIMIT 1
`
func (q *Queries) GetUser(ctx context.Context, id int64) (User, error) {
row := q.db.QueryRowContext(ctx, getUser, id)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Password,
&i.ProfilePictureID,
)
return i, err
}
const getUserbyUsername = `-- name: GetUserbyUsername :one
SELECT
id,
username,
password,
profile_picture_id
FROM user
WHERE
username = ?1
LIMIT 1
`
func (q *Queries) GetUserbyUsername(ctx context.Context, username string) (User, error) {
row := q.db.QueryRowContext(ctx, getUserbyUsername, username)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Password,
&i.ProfilePictureID,
)
return i, err
}
const insertUser = `-- name: InsertUser :one
INSERT INTO user (
username,
password
) VALUES (
?1,
?2
)
RETURNING id
`
type InsertUserParams struct {
Username string
Password string
}
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertUser, arg.Username, arg.Password)
var id int64
err := row.Scan(&id)
return id, err
}
const updateUser = `-- name: UpdateUser :exec
UPDATE user
SET
username = COALESCE(?1, username),
password = COALESCE(?2, password),
profile_picture_id = COALESCE(
?3,
profile_picture_id
)
WHERE id = ?4
`
type UpdateUserParams struct {
Username *string
Password *string
ProfilePictureID *int64
ID int64
}
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
_, err := q.db.ExecContext(ctx, updateUser,
arg.Username,
arg.Password,
arg.ProfilePictureID,
arg.ID,
)
return err
}