From ad112ff9a6efad4547a82caa1a87d30cd3daca11 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 9 Aug 2023 01:53:50 -0500 Subject: [PATCH] Use explicit return type for getFilterQuery --- src/db.ts | 6 +++--- src/db/events.ts | 6 +++--- src/deps.ts | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/db.ts b/src/db.ts index 4f382eb..8f682d1 100644 --- a/src/db.ts +++ b/src/db.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { DenoSqliteDialect, FileMigrationProvider, Kysely, Migrator, Sqlite } from '@/deps.ts'; -interface Tables { +interface DittoDB { events: EventRow; tags: TagRow; users: UserRow; @@ -33,7 +33,7 @@ interface UserRow { inserted_at: Date; } -const db = new Kysely({ +const db = new Kysely({ dialect: new DenoSqliteDialect({ database: new Sqlite('data/db.sqlite3'), }), @@ -52,4 +52,4 @@ console.log('Running migrations...'); const results = await migrator.migrateToLatest(); console.log('Migrations finished:', results); -export { db, type EventRow, type TagRow, type UserRow }; +export { db, type DittoDB, type EventRow, type TagRow, type UserRow }; diff --git a/src/db/events.ts b/src/db/events.ts index 5f38cc0..f5b9f69 100644 --- a/src/db/events.ts +++ b/src/db/events.ts @@ -1,7 +1,7 @@ -import { type Filter, type Insertable } from '@/deps.ts'; +import { type Filter, type Insertable, type SelectQueryBuilder } from '@/deps.ts'; import { type SignedEvent } from '@/event.ts'; -import { db, type TagRow } from '@/db.ts'; +import { db, type DittoDB, type EventRow, type TagRow } from '@/db.ts'; function insertEvent(event: SignedEvent): Promise { return db.transaction().execute(async (trx) => { @@ -34,7 +34,7 @@ function insertEvent(event: SignedEvent): Promise { }); } -function getFilterQuery(filter: Filter) { +function getFilterQuery(filter: Filter): SelectQueryBuilder { let query = db.selectFrom('events').selectAll().orderBy('created_at', 'desc'); for (const key of Object.keys(filter)) { diff --git a/src/deps.ts b/src/deps.ts index 12e2baf..cbb4537 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -56,6 +56,7 @@ export { Kysely, Migrator, type NullableInsertKeys, + type SelectQueryBuilder, sql, } from 'npm:kysely@^0.25.0'; export { DenoSqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/76748303a45fac64a889cd2b9265c6c9b8ef2e8b/mod.ts';