db/relays: add "domain" column
This commit is contained in:
parent
2e983154bb
commit
92f5bea891
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue