-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.ts
49 lines (45 loc) · 1.2 KB
/
db.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { createClient } from "@libsql/client";
const client = createClient({
url: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN,
});
interface Release {
version: string;
summary: string;
score: number;
relevance: string;
analyzed_at: string;
releaseLink: string;
relevantPRs: string[];
}
export async function getAnalyzedReleases(): Promise<Release[]> {
const result = await client.execute(
"SELECT * FROM releases ORDER BY analyzed_at DESC",
);
// TODO(serhalp) Verify the right turso typing pattern
return result.rows.map((row) => ({
...row,
relevantPRs: JSON.parse(row.relevantPRs as string),
})) as unknown[] as Release[];
}
export async function insertAnalyzedRelease(
version: string,
summary: string,
score: number,
relevance: string,
releaseLink: string,
relevantPRs: string[],
): Promise<void> {
await client.execute({
sql: "INSERT INTO releases (version, summary, score, relevance, releaseLink, relevantPRs, analyzed_at) VALUES (?, ?, ?, ?, ?, ?, ?)",
args: [
version,
summary,
score,
relevance,
releaseLink,
JSON.stringify(relevantPRs),
new Date().toISOString(),
],
});
}