read_files.sql.go 1.9 KB

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