feat: kysely and base schema
This commit is contained in:
@@ -22,3 +22,6 @@ dist-ssr
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
# Project-specific
|
||||
data.db
|
||||
Executable
+7
@@ -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
|
||||
@@ -10,6 +10,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^5.1.0",
|
||||
"kysely": "^0.29.2",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"tsx": "^4.19.3",
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
@@ -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
|
||||
);
|
||||
@@ -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>;
|
||||
@@ -1241,6 +1241,11 @@ json5@^2.2.3:
|
||||
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
|
||||
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:
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"
|
||||
|
||||
Reference in New Issue
Block a user