Giving kysely a go

This commit is contained in:
Christian Benincasa
2023-12-03 09:05:15 -05:00
parent f41f648c69
commit 2353fba81a
5 changed files with 33 additions and 6 deletions

3
.gitignore vendored
View File

@@ -10,4 +10,5 @@ package-lock.json
config/
.vscode/
build/
log.txt
log.txt
*.db

3
pnpm-lock.yaml generated
View File

@@ -59,6 +59,9 @@ importers:
cors:
specifier: ^2.8.5
version: 2.8.5
dayjs:
specifier: ^1.11.10
version: 1.11.10
dizquetv-types:
specifier: workspace:*
version: link:../types

View File

@@ -1,7 +1,15 @@
import { Generated, Selectable } from 'kysely';
import { ColumnType, Selectable } from 'kysely';
export interface PlexServerSettingsTable {
id: Generated<number>;
id: string;
name: string;
uri: string;
access_token: string;
send_guide_updates: boolean;
send_channel_updates: boolean;
index: number;
created_at: ColumnType<Date, string | undefined, never>;
// updated_at: ColumnType<Date,
}
export type PlexServerSettings = Selectable<PlexServerSettingsTable>;

View File

@@ -1,10 +1,24 @@
import { Kysely } from 'kysely';
import { Kysely, sql } from 'kysely';
export async function up(db: Kysely<unknown>): Promise<void> {
await db.schema
const query = db.schema
.createTable('plexServerSettings')
.addColumn('id', 'integer', (col) => col.primaryKey())
.execute();
.addColumn('name', 'text', (col) => col.notNull())
.addColumn('uri', 'text', (col) => col.notNull())
.addColumn('access_token', 'text', (col) => col.notNull())
.addColumn('send_guide_updates', 'integer', (col) =>
col.notNull().defaultTo(sql`TRUE`),
)
.addColumn('send_channel_updates', 'integer', (col) =>
col.notNull().defaultTo(sql`TRUE`),
)
.addColumn('index', 'integer', (col) => col.notNull())
.addColumn('created_at', 'timestamp', (col) =>
col.notNull().defaultTo(sql`(unixepoch())`),
);
console.log(query.compile());
return query.execute();
}
export async function down(db: Kysely<unknown>): Promise<void> {

View File

@@ -27,6 +27,7 @@
"body-parser": "^1.19.0",
"chalk": "^5.3.0",
"cors": "^2.8.5",
"dayjs": "^1.11.10",
"dizquetv-types": "workspace:*",
"express-fileupload": "^1.2.1",
"fast-json-stringify": "^5.9.1",