sessions.sql

 1-- name: CreateSession :one
 2INSERT INTO sessions (
 3    id,
 4    parent_session_id,
 5    title,
 6    message_count,
 7    prompt_tokens,
 8    completion_tokens,
 9    cost,
10    summary_message_id,
11    updated_at,
12    created_at
13) VALUES (
14    ?,
15    ?,
16    ?,
17    ?,
18    ?,
19    ?,
20    ?,
21    null,
22    strftime('%s', 'now'),
23    strftime('%s', 'now')
24) RETURNING *;
25
26-- name: GetSessionByID :one
27SELECT *
28FROM sessions
29WHERE id = ? LIMIT 1;
30
31-- name: GetLastSession :one
32SELECT *
33FROM sessions
34ORDER BY updated_at DESC
35LIMIT 1;
36
37-- name: ListSessions :many
38SELECT *
39FROM sessions
40WHERE parent_session_id is NULL
41ORDER BY updated_at DESC;
42
43-- name: UpdateSession :one
44UPDATE sessions
45SET
46    title = ?,
47    prompt_tokens = ?,
48    completion_tokens = ?,
49    summary_message_id = ?,
50    cost = ?,
51    todos = ?
52WHERE id = ?
53RETURNING *;
54
55-- name: UpdateSessionTitleAndUsage :exec
56UPDATE sessions
57SET
58    title = ?,
59    prompt_tokens = prompt_tokens + ?,
60    completion_tokens = completion_tokens + ?,
61    cost = cost + ?,
62    updated_at = strftime('%s', 'now')
63WHERE id = ?;
64
65
66-- name: RenameSession :exec
67UPDATE sessions
68SET
69    title = ?
70WHERE id = ?;
71
72-- name: DeleteSession :exec
73DELETE FROM sessions
74WHERE id = ?;