mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Use explicit return type for getFilterQuery
This commit is contained in:
parent
55c957d10b
commit
ad112ff9a6
3 changed files with 7 additions and 6 deletions
|
|
@ -3,7 +3,7 @@ import path from 'node:path';
|
||||||
|
|
||||||
import { DenoSqliteDialect, FileMigrationProvider, Kysely, Migrator, Sqlite } from '@/deps.ts';
|
import { DenoSqliteDialect, FileMigrationProvider, Kysely, Migrator, Sqlite } from '@/deps.ts';
|
||||||
|
|
||||||
interface Tables {
|
interface DittoDB {
|
||||||
events: EventRow;
|
events: EventRow;
|
||||||
tags: TagRow;
|
tags: TagRow;
|
||||||
users: UserRow;
|
users: UserRow;
|
||||||
|
|
@ -33,7 +33,7 @@ interface UserRow {
|
||||||
inserted_at: Date;
|
inserted_at: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
const db = new Kysely<Tables>({
|
const db = new Kysely<DittoDB>({
|
||||||
dialect: new DenoSqliteDialect({
|
dialect: new DenoSqliteDialect({
|
||||||
database: new Sqlite('data/db.sqlite3'),
|
database: new Sqlite('data/db.sqlite3'),
|
||||||
}),
|
}),
|
||||||
|
|
@ -52,4 +52,4 @@ console.log('Running migrations...');
|
||||||
const results = await migrator.migrateToLatest();
|
const results = await migrator.migrateToLatest();
|
||||||
console.log('Migrations finished:', results);
|
console.log('Migrations finished:', results);
|
||||||
|
|
||||||
export { db, type EventRow, type TagRow, type UserRow };
|
export { db, type DittoDB, type EventRow, type TagRow, type UserRow };
|
||||||
|
|
|
||||||
|
|
@ -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 { 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<void> {
|
function insertEvent(event: SignedEvent): Promise<void> {
|
||||||
return db.transaction().execute(async (trx) => {
|
return db.transaction().execute(async (trx) => {
|
||||||
|
|
@ -34,7 +34,7 @@ function insertEvent(event: SignedEvent): Promise<void> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFilterQuery<K extends number = number>(filter: Filter<K>) {
|
function getFilterQuery(filter: Filter): SelectQueryBuilder<DittoDB, 'events', EventRow> {
|
||||||
let query = db.selectFrom('events').selectAll().orderBy('created_at', 'desc');
|
let query = db.selectFrom('events').selectAll().orderBy('created_at', 'desc');
|
||||||
|
|
||||||
for (const key of Object.keys(filter)) {
|
for (const key of Object.keys(filter)) {
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ export {
|
||||||
Kysely,
|
Kysely,
|
||||||
Migrator,
|
Migrator,
|
||||||
type NullableInsertKeys,
|
type NullableInsertKeys,
|
||||||
|
type SelectQueryBuilder,
|
||||||
sql,
|
sql,
|
||||||
} from 'npm:kysely@^0.25.0';
|
} from 'npm:kysely@^0.25.0';
|
||||||
export { DenoSqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/76748303a45fac64a889cd2b9265c6c9b8ef2e8b/mod.ts';
|
export { DenoSqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/76748303a45fac64a889cd2b9265c6c9b8ef2e8b/mod.ts';
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue