feat: kysely and base schema

This commit is contained in:
redglow
2026-06-20 14:29:53 +02:00
parent cbb457ea8c
commit 676b043ff5
7 changed files with 56 additions and 1 deletions
+3
View File
@@ -22,3 +22,6 @@ dist-ssr
*.njsproj *.njsproj
*.sln *.sln
*.sw? *.sw?
# Project-specific
data.db
Executable
+7
View File
@@ -0,0 +1,7 @@
read -p "This command will destroy the database and re-create it. Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm -f data.db
sqlite3 data.db < ./src/server/db/schema.sql
fi
+1
View File
@@ -10,6 +10,7 @@
}, },
"dependencies": { "dependencies": {
"express": "^5.1.0", "express": "^5.1.0",
"kysely": "^0.29.2",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"tsx": "^4.19.3", "tsx": "^4.19.3",
+11
View File
@@ -0,0 +1,11 @@
import SQLite from "better-sqlite3";
import { Kysely, SqliteDialect } from "kysely";
import type { Database } from "./types.ts";
const dialect = new SqliteDialect({
database: new SQLite("./data.db"),
});
export const db = new Kysely<Database>({
dialect,
});
+11
View File
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS announcements (
id INTEGER PRIMARY KEY,
title STRING,
text STRING,
image STRING,
publication_date TEXT
);
CREATE INDEX IF NOT EXISTS announcements_publication_date_index ON announcements (
publication_date
);
+17
View File
@@ -0,0 +1,17 @@
import type { Generated, Insertable, Selectable, Updateable } from "kysely";
export interface Database {
announcements: AnnouncementTable;
}
export interface AnnouncementTable {
id: Generated<number>;
title: string;
text: string;
image: string;
publication_date: Date;
}
export type Announcement = Selectable<AnnouncementTable>;
export type NewAnnouncement = Insertable<AnnouncementTable>;
export type AnnouncementUpdate = Updateable<AnnouncementTable>;
+5
View File
@@ -1241,6 +1241,11 @@ json5@^2.2.3:
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283" resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg== integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==
kysely@^0.29.2:
version "0.29.2"
resolved "https://registry.yarnpkg.com/kysely/-/kysely-0.29.2.tgz#4a07da18db3bba2911693c2b3bd4af415104a85f"
integrity sha512-s6WVJyEZrbm6jhBpiKHsGHyePMrVQKJ85wZCFCr9W4QHv6WTjWIrdvTmO9hDEA3bNK0xkrE2DqrHsXMLWuZpQg==
lru-cache@^5.1.1: lru-cache@^5.1.1:
version "5.1.1" version "5.1.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"