@@ -30,7 +30,7 @@ struct AdmissionCreateInput {
3030 expires_at_ms: int
3131}
3232
33- pub fn storage_admission_create(db_id: int , payload_json: string) -> map {
33+ pub fn storage_admission_create(db_id: resource< sqlite .connection> , payload_json: string) -> map {
3434 let input: AdmissionCreateInput = json::decode::<AdmissionCreateInput >(payload_json);
3535 let mut failed: bool = false;
3636 let mut failure_code: string = "";
@@ -55,7 +55,7 @@ pub fn storage_admission_create(db_id: int, payload_json: string) -> map {
5555 if failed == false {
5656 if input.idempotency_key.copy() != "" {
5757 let existing: map = sqlite::query(
58- db_id,
58+ & db_id,
5959 "SELECT scope, key, request_hash, resource_type, resource_id, state, response_json FROM idempotency_records WHERE scope = ? AND key = ? LIMIT 1",
6060 [& input.idempotency_scope, & input.idempotency_key],
6161 { max_rows: 1, max_result_bytes: 8192 }
@@ -116,12 +116,12 @@ pub fn storage_admission_create(db_id: int, payload_json: string) -> map {
116116 sql: "INSERT INTO run_retention (run_id, first_seq, high_water_seq, updated_at_ms) SELECT ?, COALESCE((SELECT MIN(seq) FROM run_events WHERE run_id = ?), 0), COALESCE((SELECT MAX(seq) FROM run_events WHERE run_id = ?), 0), ? WHERE EXISTS (SELECT 1 FROM runs WHERE id = ?) ON CONFLICT (run_id) DO UPDATE SET first_seq = excluded.first_seq, high_water_seq = MAX(run_retention.high_water_seq, excluded.high_water_seq), updated_at_ms = excluded.updated_at_ms",
117117 params: [& input.run_id, & input.run_id, & input.run_id, input.now_ms.copy(), & input.run_id]
118118 };
119- sqlite::transaction(db_id, statements);
119+ sqlite::transaction(& db_id, statements);
120120 }
121121 }
122122 let query_run_id: string = if replay => { existing_run_id } else => { input.run_id.copy() };
123123 let run_result: map = sqlite::query(
124- db_id,
124+ & db_id,
125125 "SELECT id, session_id, parent_run_id, status, input_json, provider, model, script_hash, idempotency_scope, idempotency_key, turn_count, input_tokens, output_tokens, error_code, error_message, recovery_reason, created_at_ms, started_at_ms, finished_at_ms, updated_at_ms FROM runs WHERE id = ? LIMIT 1",
126126 [& query_run_id],
127127 { max_rows: 1, max_result_bytes: 65536 }
@@ -141,13 +141,13 @@ pub fn storage_admission_create(db_id: int, payload_json: string) -> map {
141141 }
142142 }
143143 let session_result: map = sqlite::query(
144- db_id,
144+ & db_id,
145145 "SELECT id, profile, platform, account_id, chat_id, thread_id, user_id, generation, status, system_prompt, model, provider, toolset_hash, metadata_json, last_message_seq, created_at_ms, updated_at_ms FROM sessions WHERE id = ? LIMIT 1",
146146 [& input.session_id],
147147 { max_rows: 1, max_result_bytes: 65536 }
148148 );
149149 let message_result: map = sqlite::query(
150- db_id,
150+ & db_id,
151151 "SELECT id, session_id, ordinal, role, content_json, name, tool_call_id, parent_message_id, token_estimate, compacted, metadata_json, run_id, finish_reason, created_at_ms FROM messages WHERE id = ? AND session_id = ? LIMIT 1",
152152 [& input.message_id, & input.session_id],
153153 { max_rows: 1, max_result_bytes: 65536 }
@@ -156,7 +156,7 @@ pub fn storage_admission_create(db_id: int, payload_json: string) -> map {
156156 { columns: [], rows: [] }
157157 } else => {
158158 sqlite::query(
159- db_id,
159+ & db_id,
160160 "SELECT scope, key, request_hash, resource_type, resource_id, state, response_json, created_at_ms, expires_at_ms, completed_at_ms FROM idempotency_records WHERE scope = ? AND key = ? LIMIT 1",
161161 [& input.idempotency_scope, & input.idempotency_key],
162162 { max_rows: 1, max_result_bytes: 8192 }
0 commit comments