feat: init db

This commit is contained in:
Julien Calixte
2026-02-08 23:26:52 +01:00
parent ab1be0efb6
commit 2312240d10
9 changed files with 109 additions and 270 deletions

43
src/data/db.ts Normal file
View File

@@ -0,0 +1,43 @@
import { DB } from "https://deno.land/x/sqlite/mod.ts";
import type { Note } from "./note"
export const db = new DB("notes.db");
export const createNote = async (note: Note) => {
return db.query(
`
INSERT INTO note (
title, content, publishedAt, createdAt, did, rkey
) VALUES (?, ?, ?, ?, ?, ?)
`,
[
note.title,
note.content,
new Date(note.publishedAt).toISOString(), // publishedAt
new Date(note.createdAt).toISOString(), // createdAt
note.did,
note.rkey,
],
);
}
export const updateNote = async (note: Note) => {
db.query(
`
UPDATE note
SET
title = ?,
content = ?,
publishedAt = ?
WHERE did = ?
AND rkey = ?
`,
[
note.title,
note.content,
note.publishedAt, // publishedAt
note.did,
note.rkey,
],
);
}