2023-10-03 20:47:38 +00:00
|
|
|
-- name: AddActivity :one
|
2023-11-03 23:38:31 +00:00
|
|
|
INSERT INTO activity (
|
2023-10-03 20:47:38 +00:00
|
|
|
user_id,
|
|
|
|
document_id,
|
|
|
|
device_id,
|
|
|
|
start_time,
|
|
|
|
duration,
|
2023-11-03 23:38:31 +00:00
|
|
|
start_percentage,
|
|
|
|
end_percentage
|
2023-10-03 20:47:38 +00:00
|
|
|
)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
|
|
RETURNING *;
|
|
|
|
|
2023-09-23 18:14:57 +00:00
|
|
|
-- name: AddMetadata :one
|
|
|
|
INSERT INTO metadata (
|
|
|
|
document_id,
|
|
|
|
title,
|
|
|
|
author,
|
|
|
|
description,
|
|
|
|
gbid,
|
|
|
|
olid,
|
|
|
|
isbn10,
|
|
|
|
isbn13
|
|
|
|
)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
RETURNING *;
|
|
|
|
|
2023-09-18 23:57:18 +00:00
|
|
|
-- name: CreateUser :execrows
|
2024-02-26 00:40:36 +00:00
|
|
|
INSERT INTO users (id, pass, auth_hash, admin)
|
|
|
|
VALUES (?, ?, ?, ?)
|
2023-09-18 23:57:18 +00:00
|
|
|
ON CONFLICT DO NOTHING;
|
|
|
|
|
|
|
|
-- name: DeleteDocument :execrows
|
|
|
|
UPDATE documents
|
|
|
|
SET
|
|
|
|
deleted = 1
|
|
|
|
WHERE id = $id;
|
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetActivity :many
|
|
|
|
WITH filtered_activity AS (
|
|
|
|
SELECT
|
|
|
|
document_id,
|
2023-11-27 02:41:17 +00:00
|
|
|
device_id,
|
2023-10-03 20:47:38 +00:00
|
|
|
user_id,
|
|
|
|
start_time,
|
|
|
|
duration,
|
2023-11-27 02:41:17 +00:00
|
|
|
ROUND(CAST(start_percentage AS REAL) * 100, 2) AS start_percentage,
|
|
|
|
ROUND(CAST(end_percentage AS REAL) * 100, 2) AS end_percentage,
|
2023-11-03 23:38:31 +00:00
|
|
|
ROUND(CAST(end_percentage - start_percentage AS REAL) * 100, 2) AS read_percentage
|
2023-10-03 20:47:38 +00:00
|
|
|
FROM activity
|
|
|
|
WHERE
|
|
|
|
activity.user_id = $user_id
|
|
|
|
AND (
|
|
|
|
(
|
|
|
|
CAST($doc_filter AS BOOLEAN) = TRUE
|
|
|
|
AND document_id = $document_id
|
|
|
|
) OR $doc_filter = FALSE
|
|
|
|
)
|
|
|
|
ORDER BY start_time DESC
|
|
|
|
LIMIT $limit
|
|
|
|
OFFSET $offset
|
2023-09-18 23:57:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
document_id,
|
2023-11-27 02:41:17 +00:00
|
|
|
device_id,
|
2024-03-11 17:13:26 +00:00
|
|
|
CAST(STRFTIME('%Y-%m-%d %H:%M:%S', LOCAL_TIME(activity.start_time, users.timezone)) AS TEXT) AS start_time,
|
2023-10-03 20:47:38 +00:00
|
|
|
title,
|
|
|
|
author,
|
2023-09-18 23:57:18 +00:00
|
|
|
duration,
|
2023-11-27 02:41:17 +00:00
|
|
|
start_percentage,
|
|
|
|
end_percentage,
|
2023-11-03 23:38:31 +00:00
|
|
|
read_percentage
|
2023-10-03 20:47:38 +00:00
|
|
|
FROM filtered_activity AS activity
|
|
|
|
LEFT JOIN documents ON documents.id = activity.document_id
|
|
|
|
LEFT JOIN users ON users.id = activity.user_id;
|
2023-09-18 23:57:18 +00:00
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetDailyReadStats :many
|
|
|
|
WITH RECURSIVE last_30_days AS (
|
2024-03-11 17:13:26 +00:00
|
|
|
SELECT DATE(LOCAL_TIME(STRFTIME('%Y-%m-%dT%H:%M:%SZ', 'now'), timezone)) AS date
|
2023-10-03 20:47:38 +00:00
|
|
|
FROM users WHERE users.id = $user_id
|
|
|
|
UNION ALL
|
|
|
|
SELECT DATE(date, '-1 days')
|
|
|
|
FROM last_30_days
|
|
|
|
LIMIT 30
|
|
|
|
),
|
|
|
|
filtered_activity AS (
|
|
|
|
SELECT
|
2023-11-03 23:38:31 +00:00
|
|
|
user_id,
|
2023-10-03 20:47:38 +00:00
|
|
|
start_time,
|
2023-11-03 23:38:31 +00:00
|
|
|
duration
|
2023-10-03 20:47:38 +00:00
|
|
|
FROM activity
|
|
|
|
WHERE start_time > DATE('now', '-31 days')
|
|
|
|
AND activity.user_id = $user_id
|
|
|
|
),
|
|
|
|
activity_days AS (
|
|
|
|
SELECT
|
|
|
|
SUM(duration) AS seconds_read,
|
2024-03-11 17:13:26 +00:00
|
|
|
DATE(LOCAL_TIME(start_time, timezone)) AS day
|
2023-10-03 20:47:38 +00:00
|
|
|
FROM filtered_activity AS activity
|
|
|
|
LEFT JOIN users ON users.id = activity.user_id
|
|
|
|
GROUP BY day
|
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
CAST(date AS TEXT),
|
|
|
|
CAST(CASE
|
|
|
|
WHEN seconds_read IS NULL THEN 0
|
|
|
|
ELSE seconds_read / 60
|
|
|
|
END AS INTEGER) AS minutes_read
|
|
|
|
FROM last_30_days
|
|
|
|
LEFT JOIN activity_days ON activity_days.day == last_30_days.date
|
|
|
|
ORDER BY date DESC
|
|
|
|
LIMIT 30;
|
2023-09-18 23:57:18 +00:00
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetDatabaseInfo :one
|
2023-09-19 23:29:55 +00:00
|
|
|
SELECT
|
2023-10-03 20:47:38 +00:00
|
|
|
(SELECT COUNT(rowid) FROM activity WHERE activity.user_id = $user_id) AS activity_size,
|
|
|
|
(SELECT COUNT(rowid) FROM documents) AS documents_size,
|
|
|
|
(SELECT COUNT(rowid) FROM document_progress WHERE document_progress.user_id = $user_id) AS progress_size,
|
|
|
|
(SELECT COUNT(rowid) FROM devices WHERE devices.user_id = $user_id) AS devices_size
|
|
|
|
LIMIT 1;
|
2023-09-18 23:57:18 +00:00
|
|
|
|
|
|
|
-- name: GetDeletedDocuments :many
|
|
|
|
SELECT documents.id
|
|
|
|
FROM documents
|
|
|
|
WHERE
|
|
|
|
documents.deleted = true
|
|
|
|
AND documents.id IN (sqlc.slice('document_ids'));
|
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetDevice :one
|
|
|
|
SELECT * FROM devices
|
|
|
|
WHERE id = $device_id LIMIT 1;
|
2023-09-18 23:57:18 +00:00
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetDevices :many
|
2023-09-23 02:12:36 +00:00
|
|
|
SELECT
|
2023-11-27 02:41:17 +00:00
|
|
|
devices.id,
|
2023-10-03 20:47:38 +00:00
|
|
|
devices.device_name,
|
2024-03-11 17:13:26 +00:00
|
|
|
CAST(STRFTIME('%Y-%m-%d %H:%M:%S', LOCAL_TIME(devices.created_at, users.timezone)) AS TEXT) AS created_at,
|
|
|
|
CAST(STRFTIME('%Y-%m-%d %H:%M:%S', LOCAL_TIME(devices.last_synced, users.timezone)) AS TEXT) AS last_synced
|
2023-10-03 20:47:38 +00:00
|
|
|
FROM devices
|
|
|
|
JOIN users ON users.id = devices.user_id
|
2023-10-14 01:06:49 +00:00
|
|
|
WHERE users.id = $user_id
|
|
|
|
ORDER BY devices.last_synced DESC;
|
2023-10-01 23:17:22 +00:00
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetDocument :one
|
|
|
|
SELECT * FROM documents
|
|
|
|
WHERE id = $document_id LIMIT 1;
|
2023-09-23 02:12:36 +00:00
|
|
|
|
2024-01-01 04:12:46 +00:00
|
|
|
-- name: GetDocumentProgress :one
|
|
|
|
SELECT
|
|
|
|
document_progress.*,
|
|
|
|
devices.device_name
|
|
|
|
FROM document_progress
|
|
|
|
JOIN devices ON document_progress.device_id = devices.id
|
|
|
|
WHERE
|
|
|
|
document_progress.user_id = $user_id
|
|
|
|
AND document_progress.document_id = $document_id
|
|
|
|
ORDER BY
|
|
|
|
document_progress.created_at
|
|
|
|
DESC
|
|
|
|
LIMIT 1;
|
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetDocumentWithStats :one
|
|
|
|
SELECT
|
|
|
|
docs.id,
|
|
|
|
docs.title,
|
|
|
|
docs.author,
|
|
|
|
docs.description,
|
|
|
|
docs.isbn10,
|
|
|
|
docs.isbn13,
|
|
|
|
docs.filepath,
|
|
|
|
docs.words,
|
|
|
|
|
2024-01-24 04:00:51 +00:00
|
|
|
CAST(COALESCE(dus.total_wpm, 0.0) AS INTEGER) AS wpm,
|
2023-11-03 23:38:31 +00:00
|
|
|
COALESCE(dus.read_percentage, 0) AS read_percentage,
|
2023-10-03 20:47:38 +00:00
|
|
|
COALESCE(dus.total_time_seconds, 0) AS total_time_seconds,
|
2024-04-07 00:40:21 +00:00
|
|
|
STRFTIME('%Y-%m-%d %H:%M:%S', LOCAL_TIME(COALESCE(dus.last_read, STRFTIME('%Y-%m-%dT%H:%M:%SZ', 0, 'unixepoch')), users.timezone))
|
2023-10-03 20:47:38 +00:00
|
|
|
AS last_read,
|
2023-11-03 23:38:31 +00:00
|
|
|
ROUND(CAST(CASE
|
2023-10-03 20:47:38 +00:00
|
|
|
WHEN dus.percentage IS NULL THEN 0.0
|
2023-11-03 23:38:31 +00:00
|
|
|
WHEN (dus.percentage * 100.0) > 97.0 THEN 100.0
|
|
|
|
ELSE dus.percentage * 100.0
|
|
|
|
END AS REAL), 2) AS percentage,
|
2023-09-18 23:57:18 +00:00
|
|
|
CAST(CASE
|
2023-10-03 20:47:38 +00:00
|
|
|
WHEN dus.total_time_seconds IS NULL THEN 0.0
|
|
|
|
ELSE
|
2023-11-03 23:38:31 +00:00
|
|
|
CAST(dus.total_time_seconds AS REAL)
|
|
|
|
/ (dus.read_percentage * 100.0)
|
|
|
|
END AS INTEGER) AS seconds_per_percent
|
2023-10-03 20:47:38 +00:00
|
|
|
FROM documents AS docs
|
|
|
|
LEFT JOIN users ON users.id = $user_id
|
|
|
|
LEFT JOIN
|
|
|
|
document_user_statistics AS dus
|
|
|
|
ON dus.document_id = docs.id AND dus.user_id = $user_id
|
|
|
|
WHERE users.id = $user_id
|
|
|
|
AND docs.id = $document_id
|
|
|
|
LIMIT 1;
|
2023-09-18 23:57:18 +00:00
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetDocuments :many
|
|
|
|
SELECT * FROM documents
|
|
|
|
ORDER BY created_at DESC
|
|
|
|
LIMIT $limit
|
|
|
|
OFFSET $offset;
|
|
|
|
|
2023-11-18 04:10:59 +00:00
|
|
|
-- name: GetDocumentsSize :one
|
|
|
|
SELECT
|
|
|
|
COUNT(rowid) AS length
|
|
|
|
FROM documents AS docs
|
|
|
|
WHERE $query IS NULL OR (
|
|
|
|
docs.title LIKE $query OR
|
|
|
|
docs.author LIKE $query
|
|
|
|
)
|
|
|
|
LIMIT 1;
|
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetDocumentsWithStats :many
|
|
|
|
SELECT
|
|
|
|
docs.id,
|
|
|
|
docs.title,
|
|
|
|
docs.author,
|
|
|
|
docs.description,
|
|
|
|
docs.isbn10,
|
|
|
|
docs.isbn13,
|
|
|
|
docs.filepath,
|
|
|
|
docs.words,
|
|
|
|
|
2024-01-24 04:00:51 +00:00
|
|
|
CAST(COALESCE(dus.total_wpm, 0.0) AS INTEGER) AS wpm,
|
2023-11-03 23:38:31 +00:00
|
|
|
COALESCE(dus.read_percentage, 0) AS read_percentage,
|
2023-10-03 20:47:38 +00:00
|
|
|
COALESCE(dus.total_time_seconds, 0) AS total_time_seconds,
|
2024-04-07 00:40:21 +00:00
|
|
|
STRFTIME('%Y-%m-%d %H:%M:%S', LOCAL_TIME(COALESCE(dus.last_read, STRFTIME('%Y-%m-%dT%H:%M:%SZ', 0, 'unixepoch')), users.timezone))
|
2023-10-03 20:47:38 +00:00
|
|
|
AS last_read,
|
2023-11-03 23:38:31 +00:00
|
|
|
ROUND(CAST(CASE
|
2023-10-03 20:47:38 +00:00
|
|
|
WHEN dus.percentage IS NULL THEN 0.0
|
2023-11-03 23:38:31 +00:00
|
|
|
WHEN (dus.percentage * 100.0) > 97.0 THEN 100.0
|
|
|
|
ELSE dus.percentage * 100.0
|
|
|
|
END AS REAL), 2) AS percentage,
|
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
CASE
|
|
|
|
WHEN dus.total_time_seconds IS NULL THEN 0.0
|
|
|
|
ELSE
|
|
|
|
ROUND(
|
|
|
|
CAST(dus.total_time_seconds AS REAL)
|
2023-11-03 23:38:31 +00:00
|
|
|
/ (dus.read_percentage * 100.0)
|
2023-10-03 20:47:38 +00:00
|
|
|
)
|
2023-11-03 23:38:31 +00:00
|
|
|
END AS seconds_per_percent
|
2023-10-03 20:47:38 +00:00
|
|
|
FROM documents AS docs
|
2023-09-21 00:35:01 +00:00
|
|
|
LEFT JOIN users ON users.id = $user_id
|
2023-10-03 20:47:38 +00:00
|
|
|
LEFT JOIN
|
|
|
|
document_user_statistics AS dus
|
|
|
|
ON dus.document_id = docs.id AND dus.user_id = $user_id
|
2023-11-18 02:24:19 +00:00
|
|
|
WHERE
|
|
|
|
docs.deleted = false AND (
|
|
|
|
$query IS NULL OR (
|
|
|
|
docs.title LIKE $query OR
|
|
|
|
docs.author LIKE $query
|
|
|
|
)
|
|
|
|
)
|
2023-10-03 20:47:38 +00:00
|
|
|
ORDER BY dus.last_read DESC, docs.created_at DESC
|
2023-09-18 23:57:18 +00:00
|
|
|
LIMIT $limit
|
|
|
|
OFFSET $offset;
|
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetLastActivity :one
|
|
|
|
SELECT start_time
|
|
|
|
FROM activity
|
|
|
|
WHERE device_id = $device_id
|
|
|
|
AND user_id = $user_id
|
|
|
|
ORDER BY start_time DESC LIMIT 1;
|
|
|
|
|
|
|
|
-- name: GetMissingDocuments :many
|
|
|
|
SELECT documents.* FROM documents
|
|
|
|
WHERE
|
|
|
|
documents.filepath IS NOT NULL
|
|
|
|
AND documents.deleted = false
|
|
|
|
AND documents.id NOT IN (sqlc.slice('document_ids'));
|
|
|
|
|
2024-01-01 04:12:46 +00:00
|
|
|
-- name: GetProgress :many
|
2023-10-03 20:47:38 +00:00
|
|
|
SELECT
|
2024-01-01 04:12:46 +00:00
|
|
|
documents.title,
|
|
|
|
documents.author,
|
|
|
|
devices.device_name,
|
|
|
|
ROUND(CAST(progress.percentage AS REAL) * 100, 2) AS percentage,
|
|
|
|
progress.document_id,
|
|
|
|
progress.user_id,
|
2024-04-07 00:40:21 +00:00
|
|
|
CAST(STRFTIME('%Y-%m-%d %H:%M:%S', LOCAL_TIME(progress.created_at, users.timezone)) AS TEXT) AS created_at
|
2024-01-01 04:12:46 +00:00
|
|
|
FROM document_progress AS progress
|
|
|
|
LEFT JOIN users ON progress.user_id = users.id
|
|
|
|
LEFT JOIN devices ON progress.device_id = devices.id
|
|
|
|
LEFT JOIN documents ON progress.document_id = documents.id
|
2023-10-03 20:47:38 +00:00
|
|
|
WHERE
|
2024-01-01 04:12:46 +00:00
|
|
|
progress.user_id = $user_id
|
|
|
|
AND (
|
|
|
|
(
|
|
|
|
CAST($doc_filter AS BOOLEAN) = TRUE
|
|
|
|
AND document_id = $document_id
|
|
|
|
) OR $doc_filter = FALSE
|
|
|
|
)
|
|
|
|
ORDER BY created_at DESC
|
|
|
|
LIMIT $limit
|
|
|
|
OFFSET $offset;
|
2023-10-03 20:47:38 +00:00
|
|
|
|
|
|
|
-- name: GetUser :one
|
|
|
|
SELECT * FROM users
|
|
|
|
WHERE id = $user_id LIMIT 1;
|
|
|
|
|
|
|
|
-- name: GetUserStreaks :many
|
|
|
|
SELECT * FROM user_streaks
|
|
|
|
WHERE user_id = $user_id;
|
|
|
|
|
2024-01-20 19:26:26 +00:00
|
|
|
-- name: GetUsers :many
|
|
|
|
SELECT * FROM users;
|
|
|
|
|
2024-01-24 04:00:51 +00:00
|
|
|
-- name: GetUserStatistics :many
|
2023-09-21 00:35:01 +00:00
|
|
|
SELECT
|
2023-10-03 20:47:38 +00:00
|
|
|
user_id,
|
2024-01-24 04:00:51 +00:00
|
|
|
|
|
|
|
CAST(SUM(total_words_read) AS INTEGER) AS total_words_read,
|
2023-10-03 20:47:38 +00:00
|
|
|
CAST(SUM(total_time_seconds) AS INTEGER) AS total_seconds,
|
2024-01-24 23:43:33 +00:00
|
|
|
ROUND(COALESCE(CAST(SUM(total_words_read) AS REAL) / (SUM(total_time_seconds) / 60.0), 0.0), 2)
|
2024-01-24 04:00:51 +00:00
|
|
|
AS total_wpm,
|
|
|
|
|
|
|
|
CAST(SUM(yearly_words_read) AS INTEGER) AS yearly_words_read,
|
|
|
|
CAST(SUM(yearly_time_seconds) AS INTEGER) AS yearly_seconds,
|
2024-01-24 23:43:33 +00:00
|
|
|
ROUND(COALESCE(CAST(SUM(yearly_words_read) AS REAL) / (SUM(yearly_time_seconds) / 60.0), 0.0), 2)
|
2024-01-24 04:00:51 +00:00
|
|
|
AS yearly_wpm,
|
|
|
|
|
|
|
|
CAST(SUM(monthly_words_read) AS INTEGER) AS monthly_words_read,
|
|
|
|
CAST(SUM(monthly_time_seconds) AS INTEGER) AS monthly_seconds,
|
2024-01-24 23:43:33 +00:00
|
|
|
ROUND(COALESCE(CAST(SUM(monthly_words_read) AS REAL) / (SUM(monthly_time_seconds) / 60.0), 0.0), 2)
|
2024-01-24 04:00:51 +00:00
|
|
|
AS monthly_wpm,
|
|
|
|
|
|
|
|
CAST(SUM(weekly_words_read) AS INTEGER) AS weekly_words_read,
|
|
|
|
CAST(SUM(weekly_time_seconds) AS INTEGER) AS weekly_seconds,
|
2024-01-24 23:43:33 +00:00
|
|
|
ROUND(COALESCE(CAST(SUM(weekly_words_read) AS REAL) / (SUM(weekly_time_seconds) / 60.0), 0.0), 2)
|
2024-01-24 04:00:51 +00:00
|
|
|
AS weekly_wpm
|
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
FROM document_user_statistics
|
2024-01-24 04:00:51 +00:00
|
|
|
WHERE total_words_read > 0
|
2023-10-03 20:47:38 +00:00
|
|
|
GROUP BY user_id
|
2024-01-24 04:00:51 +00:00
|
|
|
ORDER BY total_wpm DESC;
|
2023-09-18 23:57:18 +00:00
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: GetWantedDocuments :many
|
2023-09-27 22:58:47 +00:00
|
|
|
SELECT
|
2023-10-03 20:47:38 +00:00
|
|
|
CAST(value AS TEXT) AS id,
|
|
|
|
CAST((documents.filepath IS NULL) AS BOOLEAN) AS want_file,
|
2023-11-03 23:38:31 +00:00
|
|
|
CAST((documents.id IS NULL) AS BOOLEAN) AS want_metadata
|
2023-10-03 20:47:38 +00:00
|
|
|
FROM json_each(?1)
|
|
|
|
LEFT JOIN documents
|
|
|
|
ON value = documents.id
|
|
|
|
WHERE (
|
|
|
|
documents.id IS NOT NULL
|
|
|
|
AND documents.deleted = false
|
2023-11-03 23:38:31 +00:00
|
|
|
AND documents.filepath IS NULL
|
2023-10-03 20:47:38 +00:00
|
|
|
)
|
|
|
|
OR (documents.id IS NULL)
|
|
|
|
OR CAST($document_ids AS TEXT) != CAST($document_ids AS TEXT);
|
2023-09-18 23:57:18 +00:00
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: UpdateProgress :one
|
|
|
|
INSERT OR REPLACE INTO document_progress (
|
|
|
|
user_id,
|
|
|
|
document_id,
|
|
|
|
device_id,
|
|
|
|
percentage,
|
|
|
|
progress
|
2023-09-18 23:57:18 +00:00
|
|
|
)
|
2023-10-03 20:47:38 +00:00
|
|
|
VALUES (?, ?, ?, ?, ?)
|
|
|
|
RETURNING *;
|
2023-09-18 23:57:18 +00:00
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: UpdateUser :one
|
|
|
|
UPDATE users
|
|
|
|
SET
|
|
|
|
pass = COALESCE($password, pass),
|
2024-01-28 02:02:08 +00:00
|
|
|
auth_hash = COALESCE($auth_hash, auth_hash),
|
2024-03-11 17:13:26 +00:00
|
|
|
timezone = COALESCE($timezone, timezone),
|
2024-03-11 01:48:43 +00:00
|
|
|
admin = COALESCE($admin, admin)
|
2023-10-03 20:47:38 +00:00
|
|
|
WHERE id = $user_id
|
|
|
|
RETURNING *;
|
2023-09-18 23:57:18 +00:00
|
|
|
|
2024-02-02 01:05:35 +00:00
|
|
|
-- name: UpdateSettings :one
|
|
|
|
INSERT INTO settings (name, value)
|
|
|
|
VALUES (?, ?)
|
|
|
|
ON CONFLICT DO UPDATE
|
|
|
|
SET
|
|
|
|
name = COALESCE(excluded.name, name),
|
|
|
|
value = COALESCE(excluded.value, value)
|
|
|
|
RETURNING *;
|
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: UpsertDevice :one
|
|
|
|
INSERT INTO devices (id, user_id, last_synced, device_name)
|
|
|
|
VALUES (?, ?, ?, ?)
|
|
|
|
ON CONFLICT DO UPDATE
|
|
|
|
SET
|
|
|
|
device_name = COALESCE(excluded.device_name, device_name),
|
|
|
|
last_synced = COALESCE(excluded.last_synced, last_synced)
|
|
|
|
RETURNING *;
|
2023-09-18 23:57:18 +00:00
|
|
|
|
2023-10-03 20:47:38 +00:00
|
|
|
-- name: UpsertDocument :one
|
|
|
|
INSERT INTO documents (
|
|
|
|
id,
|
|
|
|
md5,
|
2024-05-18 20:47:26 +00:00
|
|
|
basepath,
|
2023-10-03 20:47:38 +00:00
|
|
|
filepath,
|
|
|
|
coverfile,
|
|
|
|
title,
|
|
|
|
author,
|
|
|
|
series,
|
|
|
|
series_index,
|
|
|
|
lang,
|
|
|
|
description,
|
|
|
|
words,
|
|
|
|
olid,
|
|
|
|
gbid,
|
|
|
|
isbn10,
|
|
|
|
isbn13
|
2023-09-18 23:57:18 +00:00
|
|
|
)
|
2024-05-18 20:47:26 +00:00
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
2023-10-03 20:47:38 +00:00
|
|
|
ON CONFLICT DO UPDATE
|
|
|
|
SET
|
|
|
|
md5 = COALESCE(excluded.md5, md5),
|
2024-05-18 20:47:26 +00:00
|
|
|
basepath = COALESCE(excluded.basepath, basepath),
|
2023-10-03 20:47:38 +00:00
|
|
|
filepath = COALESCE(excluded.filepath, filepath),
|
|
|
|
coverfile = COALESCE(excluded.coverfile, coverfile),
|
|
|
|
title = COALESCE(excluded.title, title),
|
|
|
|
author = COALESCE(excluded.author, author),
|
|
|
|
series = COALESCE(excluded.series, series),
|
|
|
|
series_index = COALESCE(excluded.series_index, series_index),
|
|
|
|
lang = COALESCE(excluded.lang, lang),
|
|
|
|
description = COALESCE(excluded.description, description),
|
|
|
|
words = COALESCE(excluded.words, words),
|
|
|
|
olid = COALESCE(excluded.olid, olid),
|
|
|
|
gbid = COALESCE(excluded.gbid, gbid),
|
|
|
|
isbn10 = COALESCE(excluded.isbn10, isbn10),
|
|
|
|
isbn13 = COALESCE(excluded.isbn13, isbn13)
|
|
|
|
RETURNING *;
|