feat: init db
This commit is contained in:
43
src/data/db.ts
Normal file
43
src/data/db.ts
Normal 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,
|
||||
],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user