feat: sqlc, nix formatting
This commit is contained in:
41
server/db/queries/file.sql
Normal file
41
server/db/queries/file.sql
Normal file
@ -0,0 +1,41 @@
|
||||
-- name: GetFile :one
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
data,
|
||||
user_id
|
||||
FROM file
|
||||
WHERE
|
||||
id = @id
|
||||
AND
|
||||
user_id = @user_id
|
||||
LIMIT 1;
|
||||
|
||||
-- name: InsertFile :one
|
||||
INSERT INTO file (
|
||||
name,
|
||||
data,
|
||||
user_id
|
||||
) VALUES (
|
||||
@name,
|
||||
@data,
|
||||
@user_id
|
||||
)
|
||||
RETURNING id;
|
||||
|
||||
-- name: UpdateFile :exec
|
||||
UPDATE file
|
||||
SET
|
||||
name = COALESCE(sqlc.narg('name'), name),
|
||||
data = COALESCE(sqlc.narg('data'), data)
|
||||
WHERE
|
||||
id = @id
|
||||
AND
|
||||
user_id = @user_id;
|
||||
|
||||
-- name: DeleteFile :exec
|
||||
DELETE FROM file
|
||||
WHERE
|
||||
id = @id
|
||||
AND
|
||||
user_id = @user_id;
|
92
server/db/queries/item.sql
Normal file
92
server/db/queries/item.sql
Normal file
@ -0,0 +1,92 @@
|
||||
-- name: GetItem :one
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
added,
|
||||
description,
|
||||
price,
|
||||
quantity,
|
||||
user_id
|
||||
FROM item
|
||||
WHERE
|
||||
id = @id
|
||||
AND
|
||||
user_id = @user_id
|
||||
LIMIT 1;
|
||||
|
||||
-- name: GetItems :many
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
added,
|
||||
description,
|
||||
price,
|
||||
quantity,
|
||||
user_id
|
||||
FROM item
|
||||
WHERE
|
||||
user_id = @user_id
|
||||
AND
|
||||
(
|
||||
(name LIKE sqlc.narg('name') OR sqlc.narg('name') IS NULL)
|
||||
AND
|
||||
(added >= sqlc.narg('start') OR sqlc.narg('start') IS NULL)
|
||||
AND
|
||||
(added <= sqlc.narg('end') OR sqlc.narg('end') IS NULL)
|
||||
)
|
||||
LIMIT
|
||||
@limit
|
||||
OFFSET
|
||||
@offset;
|
||||
|
||||
-- name: GetItemsCount :one
|
||||
SELECT COUNT(id)
|
||||
FROM item
|
||||
WHERE
|
||||
user_id = @user_id
|
||||
AND
|
||||
(
|
||||
(name LIKE sqlc.narg('name') OR sqlc.narg('name') IS NULL)
|
||||
AND
|
||||
(added >= sqlc.narg('start') OR sqlc.narg('start') IS NULL)
|
||||
AND
|
||||
(added <= sqlc.narg('end') OR sqlc.narg('end') IS NULL)
|
||||
)
|
||||
LIMIT 1;
|
||||
|
||||
-- name: InsertItem :one
|
||||
INSERT INTO item (
|
||||
name,
|
||||
added,
|
||||
description,
|
||||
price,
|
||||
quantity,
|
||||
user_id
|
||||
) VALUES (
|
||||
@name,
|
||||
@added,
|
||||
@description,
|
||||
@price,
|
||||
@quantity,
|
||||
@user_id
|
||||
)
|
||||
RETURNING id;
|
||||
|
||||
-- name: UpdateItem :exec
|
||||
UPDATE item
|
||||
SET
|
||||
name = COALESCE(sqlc.narg('name'), name),
|
||||
description = COALESCE(sqlc.narg('description'), description),
|
||||
price = COALESCE(sqlc.narg('price'), price),
|
||||
quantity = COALESCE(sqlc.narg('quantity'), quantity)
|
||||
WHERE
|
||||
id = @id
|
||||
AND
|
||||
user_id = @user_id;
|
||||
|
||||
-- name: DeleteItem :exec
|
||||
DELETE FROM item
|
||||
WHERE
|
||||
id = @id
|
||||
AND
|
||||
user_id = @user_id;
|
46
server/db/queries/user.sql
Normal file
46
server/db/queries/user.sql
Normal file
@ -0,0 +1,46 @@
|
||||
-- name: GetUser :one
|
||||
SELECT
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
profile_picture_id
|
||||
FROM user
|
||||
WHERE
|
||||
id = @id
|
||||
LIMIT 1;
|
||||
|
||||
-- name: GetUserbyUsername :one
|
||||
SELECT
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
profile_picture_id
|
||||
FROM user
|
||||
WHERE
|
||||
username = @username
|
||||
LIMIT 1;
|
||||
|
||||
-- name: InsertUser :one
|
||||
INSERT INTO user (
|
||||
username,
|
||||
password
|
||||
) VALUES (
|
||||
@username,
|
||||
@password
|
||||
)
|
||||
RETURNING id;
|
||||
|
||||
-- name: UpdateUser :exec
|
||||
UPDATE user
|
||||
SET
|
||||
username = COALESCE(sqlc.narg('username'), username),
|
||||
password = COALESCE(sqlc.narg('password'), password),
|
||||
profile_picture_id = COALESCE(
|
||||
sqlc.narg('profile_picture_id'),
|
||||
profile_picture_id
|
||||
)
|
||||
WHERE id = @id;
|
||||
|
||||
-- name: DeleteUser :exec
|
||||
DELETE FROM user
|
||||
WHERE id = @id;
|
Reference in New Issue
Block a user