1// Code generated by sqlc. DO NOT EDIT.
2// versions:
3// sqlc v1.30.0
4// source: read_files.sql
5
6package db
7
8import (
9 "context"
10)
11
12const getFileRead = `-- name: GetFileRead :one
13SELECT session_id, path, read_at FROM read_files
14WHERE session_id = ? AND path = ? LIMIT 1
15`
16
17type GetFileReadParams struct {
18 SessionID string `json:"session_id"`
19 Path string `json:"path"`
20}
21
22func (q *Queries) GetFileRead(ctx context.Context, arg GetFileReadParams) (ReadFile, error) {
23 row := q.queryRow(ctx, q.getFileReadStmt, getFileRead, arg.SessionID, arg.Path)
24 var i ReadFile
25 err := row.Scan(
26 &i.SessionID,
27 &i.Path,
28 &i.ReadAt,
29 )
30 return i, err
31}
32
33const recordFileRead = `-- name: RecordFileRead :exec
34INSERT INTO read_files (
35 session_id,
36 path,
37 read_at
38) VALUES (
39 ?,
40 ?,
41 strftime('%s', 'now')
42) ON CONFLICT(path, session_id) DO UPDATE SET
43 read_at = excluded.read_at
44`
45
46type RecordFileReadParams struct {
47 SessionID string `json:"session_id"`
48 Path string `json:"path"`
49}
50
51const listSessionReadFiles = `-- name: ListSessionReadFiles :many
52SELECT session_id, path, read_at FROM read_files
53WHERE session_id = ?
54ORDER BY read_at DESC
55`
56
57func (q *Queries) ListSessionReadFiles(ctx context.Context, sessionID string) ([]ReadFile, error) {
58 rows, err := q.query(ctx, q.listSessionReadFilesStmt, listSessionReadFiles, sessionID)
59 if err != nil {
60 return nil, err
61 }
62 defer rows.Close()
63 items := []ReadFile{}
64 for rows.Next() {
65 var i ReadFile
66 if err := rows.Scan(
67 &i.SessionID,
68 &i.Path,
69 &i.ReadAt,
70 ); err != nil {
71 return nil, err
72 }
73 items = append(items, i)
74 }
75 if err := rows.Close(); err != nil {
76 return nil, err
77 }
78 if err := rows.Err(); err != nil {
79 return nil, err
80 }
81 return items, nil
82}
83
84func (q *Queries) RecordFileRead(ctx context.Context, arg RecordFileReadParams) error {
85 _, err := q.exec(ctx, q.recordFileReadStmt, recordFileRead,
86 arg.SessionID,
87 arg.Path,
88 )
89 return err
90}