read_files.sql.go

 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(&i.SessionID, &i.Path, &i.ReadAt)
26	return i, err
27}
28
29const listSessionReadFiles = `-- name: ListSessionReadFiles :many
30SELECT session_id, path, read_at FROM read_files
31WHERE session_id = ?
32ORDER BY read_at DESC
33`
34
35func (q *Queries) ListSessionReadFiles(ctx context.Context, sessionID string) ([]ReadFile, error) {
36	rows, err := q.query(ctx, q.listSessionReadFilesStmt, listSessionReadFiles, sessionID)
37	if err != nil {
38		return nil, err
39	}
40	defer rows.Close()
41	items := []ReadFile{}
42	for rows.Next() {
43		var i ReadFile
44		if err := rows.Scan(&i.SessionID, &i.Path, &i.ReadAt); err != nil {
45			return nil, err
46		}
47		items = append(items, i)
48	}
49	if err := rows.Close(); err != nil {
50		return nil, err
51	}
52	if err := rows.Err(); err != nil {
53		return nil, err
54	}
55	return items, nil
56}
57
58const recordFileRead = `-- name: RecordFileRead :exec
59INSERT INTO read_files (
60    session_id,
61    path,
62    read_at
63) VALUES (
64    ?,
65    ?,
66    strftime('%s', 'now')
67) ON CONFLICT(path, session_id) DO UPDATE SET
68    read_at = excluded.read_at
69`
70
71type RecordFileReadParams struct {
72	SessionID string `json:"session_id"`
73	Path      string `json:"path"`
74}
75
76func (q *Queries) RecordFileRead(ctx context.Context, arg RecordFileReadParams) error {
77	_, err := q.exec(ctx, q.recordFileReadStmt, recordFileRead, arg.SessionID, arg.Path)
78	return err
79}