db/relays: add "domain" column

This commit is contained in:
Alex Gleason 2023-08-15 18:59:49 -05:00
parent 2e983154bb
commit 92f5bea891
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 8 additions and 1 deletions

View File

@ -4,6 +4,7 @@ export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable('relays')
.addColumn('url', 'text', (col) => col.primaryKey())
.addColumn('domain', 'text', (col) => col.notNull())
.execute();
}

View File

@ -1,9 +1,14 @@
import { tldts } from '@/deps.ts';
import { db } from '@/db.ts';
/** Inserts relays into the database, skipping duplicates. */
function addRelays(relays: `wss://${string}`[]) {
if (!relays.length) return Promise.resolve();
const values = relays.map((url) => ({ url }));
const values = relays.map((url) => ({
url,
domain: tldts.getDomain(url),
}));
return db.insertInto('relays')
.values(values)

View File

@ -60,3 +60,4 @@ export {
sql,
} from 'npm:kysely@^0.25.0';
export { DenoSqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/v1.0.0/mod.ts';
export { default as tldts } from 'npm:tldts@^6.0.14';