jillo-bot/src/lib/db.ts

45 lines
1.2 KiB
TypeScript

import knex from 'knex';
export const db = knex({
client: 'sqlite3',
connection: {
filename: './jillo.sqlite'
},
useNullAsDefault: true
});
export interface ScheduledSubscription {
name: string;
next: number;
}
export interface Subscription {
key: string,
channel: string,
guild?: string
}
export async function initTables() {
await db.schema.createTableIfNotExists('scheduledSubscriptions', table => {
table.string('name').primary();
table.timestamp('next').defaultTo(db.fn.now());
});
await db.schema.createTableIfNotExists('subscriptions', table => {
table.string('key')
.references('name').inTable('scheduledSubscriptions');
table.string('channel');
table.string('guild').nullable();
});
/*await db.schema.createTableIfNotExists('counters', table => {
table.string('key').primary();
table.string('name').notNullable();
table.string('emoji').notNullable();
table.integer('value').defaultTo(0);
table.string('channel').notNullable();
table.string('message');
table.boolean('allowlist');
});
await db.schema.createTableIfNotExists('counterUserLink', table => {
table.string('key').references('key').inTable('counters');
table.string('user').notNullable();
});*/
}