feat: kysely and base schema
This commit is contained in:
@@ -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>;
|
||||
Reference in New Issue
Block a user