relay filter/appview bootstrap
1import { Kysely, PostgresDialect, Generated } from 'kysely' 2import { Pool } from 'pg' 3import dotenv from 'dotenv' 4 5dotenv.config(); 6 7type JsonValue = string | number | boolean | null | { [key: string]: JsonValue } | JsonValue[]; 8 9interface FirehoseEventTable { 10 timestamp: Date 11 event_type: 'commit' | 'identity' | 'account' 12 event_data: JsonValue 13}; 14 15interface PdsTable { 16 hostname: string; 17 added_at: Generated<Date>; 18} 19 20interface AccountTable { 21 did: string; 22 handle: string; 23 pds_hostname: string | null; 24 created_at: Generated<Date>; 25} 26 27interface LatticeTable { 28 uri: string; 29 cid: string; 30 creator_did: string; 31 description: string | null; 32 created_at: Generated<Date>; 33 indexed_at: Generated<Date>; 34 data: JsonValue; 35} 36 37interface ShardTable { 38 uri: string; 39 cid: string; 40 creator_did: string; 41 description: string | null; 42 created_at: Generated<Date>; 43 indexed_at: Generated<Date>; 44 data: JsonValue; 45} 46 47interface ChannelTable { 48 cid: string; 49 uri: string | null; 50 creator_did: string | null; 51 name: string | null; 52 topic: string | null; 53 created_at: Generated<Date>; 54 indexed_at: Generated<Date>; 55 data: JsonValue | null; 56} 57 58interface ChannelInviteTable { 59 cid: string; 60 uri: string | null; 61 channel: string | null; 62 creator_did: string | null; 63 recipient_did: string | null; 64 created_at: Generated<Date>; 65 indexed_at: Generated<Date>; 66 data: JsonValue | null; 67} 68 69interface ChannelMembershipTable { 70 uri: string; 71 cid: string; 72 channel: string; 73 invite: string; 74 recipient_did: string; 75 state: string; 76 created_at: Generated<Date>; 77 indexed_at: Generated<Date>; 78 updated_at: Date | null; 79 data: JsonValue; 80} 81 82type RawRecordQueueStatus = 'pending' | 'processing' | 'complete' | 'failed'; 83 84interface RawRecordQueueTable { 85 id: Generated<number>; 86 record_data: JsonValue; 87 status: Generated<RawRecordQueueStatus>; 88 created_at: Generated<Date>; 89 updated_at: Generated<Date>; 90} 91 92interface FirehoseCursorTable { 93 id: number; 94 cursor: string; 95 updated_at: Generated<Date>; 96} 97 98 99export interface Database { 100 firehose_event: FirehoseEventTable; 101 firehose_cursor: FirehoseCursorTable; 102 103 pds: PdsTable; 104 account: AccountTable; 105 lattice: LatticeTable; 106 shard: ShardTable; 107 channel: ChannelTable; 108 channel_invite: ChannelInviteTable; 109 channel_membership: ChannelMembershipTable; 110 raw_record_queue: RawRecordQueueTable; 111}; 112 113const pool = new Pool({ 114 connectionString: process.env.DATABASE_URL, 115 max: process.env.DB_POOL_SIZE ? parseInt(process.env.DB_POOL_SIZE, 10) : 10, 116}); 117 118const dialect = new PostgresDialect({ 119 pool, 120}); 121 122export const db = new Kysely<Database>({ 123 dialect, 124}); 125 126export { pool };