read_files.sql.go 1.9 KB

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