summaryrefslogtreecommitdiffhomepage
path: root/internal/db/sql/files.sql
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-21 19:59:35 +0200
committerGitHub <[email protected]>2025-04-21 19:59:35 +0200
commitf33dff87725764af0b675b5e5b2e011b21c14c90 (patch)
tree4fe2c022305f13775f2cab3cdd80cd808259765b /internal/db/sql/files.sql
parent6b1c64bcc75b89c530294b6a2d4404682b435d56 (diff)
parent3a6a26981a8074b6ab0eaadb520db986e04799ff (diff)
downloadopencode-f33dff87725764af0b675b5e5b2e011b21c14c90.tar.gz
opencode-f33dff87725764af0b675b5e5b2e011b21c14c90.zip
Merge pull request #27 from kujtimiihoxha/opencode
OpenCode - Initial Implementation
Diffstat (limited to 'internal/db/sql/files.sql')
-rw-r--r--internal/db/sql/files.sql71
1 files changed, 71 insertions, 0 deletions
diff --git a/internal/db/sql/files.sql b/internal/db/sql/files.sql
new file mode 100644
index 000000000..aba2a6111
--- /dev/null
+++ b/internal/db/sql/files.sql
@@ -0,0 +1,71 @@
+-- name: GetFile :one
+SELECT *
+FROM files
+WHERE id = ? LIMIT 1;
+
+-- name: GetFileByPathAndSession :one
+SELECT *
+FROM files
+WHERE path = ? AND session_id = ?
+ORDER BY created_at DESC
+LIMIT 1;
+
+-- name: ListFilesBySession :many
+SELECT *
+FROM files
+WHERE session_id = ?
+ORDER BY created_at ASC;
+
+-- name: ListFilesByPath :many
+SELECT *
+FROM files
+WHERE path = ?
+ORDER BY created_at DESC;
+
+-- name: CreateFile :one
+INSERT INTO files (
+ id,
+ session_id,
+ path,
+ content,
+ version,
+ created_at,
+ updated_at
+) VALUES (
+ ?, ?, ?, ?, ?, strftime('%s', 'now'), strftime('%s', 'now')
+)
+RETURNING *;
+
+-- name: UpdateFile :one
+UPDATE files
+SET
+ content = ?,
+ version = ?,
+ updated_at = strftime('%s', 'now')
+WHERE id = ?
+RETURNING *;
+
+-- name: DeleteFile :exec
+DELETE FROM files
+WHERE id = ?;
+
+-- name: DeleteSessionFiles :exec
+DELETE FROM files
+WHERE session_id = ?;
+
+-- name: ListLatestSessionFiles :many
+SELECT f.*
+FROM files f
+INNER JOIN (
+ SELECT path, MAX(created_at) as max_created_at
+ FROM files
+ GROUP BY path
+) latest ON f.path = latest.path AND f.created_at = latest.max_created_at
+WHERE f.session_id = ?
+ORDER BY f.path;
+
+-- name: ListNewFiles :many
+SELECT *
+FROM files
+WHERE is_new = 1
+ORDER BY created_at DESC;