Classplugin-kyselyv0.9.0
abstract class KyselyService<
TTable extends LiteralUnion<KyselyTable, string> =
KyselyTable
>\@RegisterKyselyService('users')
export class UsersService extends KyselyService<'users'> {
public async findById(id: string) {
return this.db
.selectFrom(this.table)
.selectAll().where('id', '=', id)
.executeTakeFirst();
}
}
// Usage inside handlers:
const user = await this.core.db.services.users.findById('abc');Member visibility
Filter class members by access level.
TTable
The table that this service works with. Defaults to every table in the schema.
TTable extends LiteralUnion<KyselyTable, string> = KyselyTableprotected readonly core: CoreBasepublic get db(): Kysely<KyselySchema>protected readonly kysely: Kyselypublic readonly table: TTable