summaryrefslogtreecommitdiffhomepage
path: root/internal/db/files.sql.go
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-13 11:29:20 +0200
committerKujtim Hoxha <[email protected]>2025-04-21 13:38:42 +0200
commitd63d0c4c44cb2356645fd112cec01598301f5949 (patch)
treea3a863a1c08ebb34885c1e38cfa76f9515cf7e54 /internal/db/files.sql.go
parentbd2ec29b65e430f83f430db5fdc424c7d631989d (diff)
downloadopencode-d63d0c4c44cb2356645fd112cec01598301f5949.tar.gz
opencode-d63d0c4c44cb2356645fd112cec01598301f5949.zip
wip files
Diffstat (limited to 'internal/db/files.sql.go')
-rw-r--r--internal/db/files.sql.go309
1 files changed, 309 insertions, 0 deletions
diff --git a/internal/db/files.sql.go b/internal/db/files.sql.go
new file mode 100644
index 000000000..b45731098
--- /dev/null
+++ b/internal/db/files.sql.go
@@ -0,0 +1,309 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+// sqlc v1.27.0
+// source: files.sql
+
+package db
+
+import (
+ "context"
+)
+
+const createFile = `-- name: CreateFile :one
+INSERT INTO files (
+ id,
+ session_id,
+ path,
+ content,
+ version,
+ created_at,
+ updated_at
+) VALUES (
+ ?, ?, ?, ?, ?, strftime('%s', 'now'), strftime('%s', 'now')
+)
+RETURNING id, session_id, path, content, version, created_at, updated_at
+`
+
+type CreateFileParams struct {
+ ID string `json:"id"`
+ SessionID string `json:"session_id"`
+ Path string `json:"path"`
+ Content string `json:"content"`
+ Version string `json:"version"`
+}
+
+func (q *Queries) CreateFile(ctx context.Context, arg CreateFileParams) (File, error) {
+ row := q.queryRow(ctx, q.createFileStmt, createFile,
+ arg.ID,
+ arg.SessionID,
+ arg.Path,
+ arg.Content,
+ arg.Version,
+ )
+ var i File
+ err := row.Scan(
+ &i.ID,
+ &i.SessionID,
+ &i.Path,
+ &i.Content,
+ &i.Version,
+ &i.CreatedAt,
+ &i.UpdatedAt,
+ )
+ return i, err
+}
+
+const deleteFile = `-- name: DeleteFile :exec
+DELETE FROM files
+WHERE id = ?
+`
+
+func (q *Queries) DeleteFile(ctx context.Context, id string) error {
+ _, err := q.exec(ctx, q.deleteFileStmt, deleteFile, id)
+ return err
+}
+
+const deleteSessionFiles = `-- name: DeleteSessionFiles :exec
+DELETE FROM files
+WHERE session_id = ?
+`
+
+func (q *Queries) DeleteSessionFiles(ctx context.Context, sessionID string) error {
+ _, err := q.exec(ctx, q.deleteSessionFilesStmt, deleteSessionFiles, sessionID)
+ return err
+}
+
+const getFile = `-- name: GetFile :one
+SELECT id, session_id, path, content, version, created_at, updated_at
+FROM files
+WHERE id = ? LIMIT 1
+`
+
+func (q *Queries) GetFile(ctx context.Context, id string) (File, error) {
+ row := q.queryRow(ctx, q.getFileStmt, getFile, id)
+ var i File
+ err := row.Scan(
+ &i.ID,
+ &i.SessionID,
+ &i.Path,
+ &i.Content,
+ &i.Version,
+ &i.CreatedAt,
+ &i.UpdatedAt,
+ )
+ return i, err
+}
+
+const getFileByPathAndSession = `-- name: GetFileByPathAndSession :one
+SELECT id, session_id, path, content, version, created_at, updated_at
+FROM files
+WHERE path = ? AND session_id = ? LIMIT 1
+`
+
+type GetFileByPathAndSessionParams struct {
+ Path string `json:"path"`
+ SessionID string `json:"session_id"`
+}
+
+func (q *Queries) GetFileByPathAndSession(ctx context.Context, arg GetFileByPathAndSessionParams) (File, error) {
+ row := q.queryRow(ctx, q.getFileByPathAndSessionStmt, getFileByPathAndSession, arg.Path, arg.SessionID)
+ var i File
+ err := row.Scan(
+ &i.ID,
+ &i.SessionID,
+ &i.Path,
+ &i.Content,
+ &i.Version,
+ &i.CreatedAt,
+ &i.UpdatedAt,
+ )
+ return i, err
+}
+
+const listFilesByPath = `-- name: ListFilesByPath :many
+SELECT id, session_id, path, content, version, created_at, updated_at
+FROM files
+WHERE path = ?
+ORDER BY created_at DESC
+`
+
+func (q *Queries) ListFilesByPath(ctx context.Context, path string) ([]File, error) {
+ rows, err := q.query(ctx, q.listFilesByPathStmt, listFilesByPath, path)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ items := []File{}
+ for rows.Next() {
+ var i File
+ if err := rows.Scan(
+ &i.ID,
+ &i.SessionID,
+ &i.Path,
+ &i.Content,
+ &i.Version,
+ &i.CreatedAt,
+ &i.UpdatedAt,
+ ); 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 listFilesBySession = `-- name: ListFilesBySession :many
+SELECT id, session_id, path, content, version, created_at, updated_at
+FROM files
+WHERE session_id = ?
+ORDER BY created_at ASC
+`
+
+func (q *Queries) ListFilesBySession(ctx context.Context, sessionID string) ([]File, error) {
+ rows, err := q.query(ctx, q.listFilesBySessionStmt, listFilesBySession, sessionID)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ items := []File{}
+ for rows.Next() {
+ var i File
+ if err := rows.Scan(
+ &i.ID,
+ &i.SessionID,
+ &i.Path,
+ &i.Content,
+ &i.Version,
+ &i.CreatedAt,
+ &i.UpdatedAt,
+ ); 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 listLatestSessionFiles = `-- name: ListLatestSessionFiles :many
+SELECT f.id, f.session_id, f.path, f.content, f.version, f.created_at, f.updated_at
+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
+`
+
+func (q *Queries) ListLatestSessionFiles(ctx context.Context, sessionID string) ([]File, error) {
+ rows, err := q.query(ctx, q.listLatestSessionFilesStmt, listLatestSessionFiles, sessionID)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ items := []File{}
+ for rows.Next() {
+ var i File
+ if err := rows.Scan(
+ &i.ID,
+ &i.SessionID,
+ &i.Path,
+ &i.Content,
+ &i.Version,
+ &i.CreatedAt,
+ &i.UpdatedAt,
+ ); 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 listNewFiles = `-- name: ListNewFiles :many
+SELECT id, session_id, path, content, version, created_at, updated_at
+FROM files
+WHERE is_new = 1
+ORDER BY created_at DESC
+`
+
+func (q *Queries) ListNewFiles(ctx context.Context) ([]File, error) {
+ rows, err := q.query(ctx, q.listNewFilesStmt, listNewFiles)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ items := []File{}
+ for rows.Next() {
+ var i File
+ if err := rows.Scan(
+ &i.ID,
+ &i.SessionID,
+ &i.Path,
+ &i.Content,
+ &i.Version,
+ &i.CreatedAt,
+ &i.UpdatedAt,
+ ); 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 updateFile = `-- name: UpdateFile :one
+UPDATE files
+SET
+ content = ?,
+ version = ?,
+ updated_at = strftime('%s', 'now')
+WHERE id = ?
+RETURNING id, session_id, path, content, version, created_at, updated_at
+`
+
+type UpdateFileParams struct {
+ Content string `json:"content"`
+ Version string `json:"version"`
+ ID string `json:"id"`
+}
+
+func (q *Queries) UpdateFile(ctx context.Context, arg UpdateFileParams) (File, error) {
+ row := q.queryRow(ctx, q.updateFileStmt, updateFile, arg.Content, arg.Version, arg.ID)
+ var i File
+ err := row.Scan(
+ &i.ID,
+ &i.SessionID,
+ &i.Path,
+ &i.Content,
+ &i.Version,
+ &i.CreatedAt,
+ &i.UpdatedAt,
+ )
+ return i, err
+}