| 139 | } |
| 140 | |
| 141 | export class TempDbReader { |
| 142 | private db: DatabaseAdapter |
| 143 | |
| 144 | constructor(db: DatabaseAdapter) { |
| 145 | this.db = db |
| 146 | } |
| 147 | |
| 148 | getMeta(): TempDbMeta | null { |
| 149 | const row = this.db.prepare('SELECT * FROM meta LIMIT 1').get() as |
| 150 | | { name: string; platform: string; type: string; group_id: string | null; group_avatar: string | null } |
| 151 | | undefined |
| 152 | if (!row) return null |
| 153 | return { |
| 154 | name: row.name, |
| 155 | platform: row.platform, |
| 156 | type: row.type, |
| 157 | groupId: row.group_id || undefined, |
| 158 | groupAvatar: row.group_avatar || undefined, |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | getMembers(): ParsedMember[] { |
| 163 | const rows = this.db.prepare('SELECT * FROM member').all() as Array<{ |
| 164 | platform_id: string |
| 165 | account_name: string | null |
| 166 | group_nickname: string | null |
| 167 | avatar: string | null |
| 168 | }> |
| 169 | return rows.map((r) => ({ |
| 170 | platformId: r.platform_id, |
| 171 | accountName: r.account_name || r.platform_id, |
| 172 | groupNickname: r.group_nickname || undefined, |
| 173 | avatar: r.avatar || undefined, |
| 174 | })) |
| 175 | } |
| 176 | |
| 177 | getMessageCount(): number { |
| 178 | const row = this.db.prepare('SELECT COUNT(*) as count FROM message').get() as { count: number } |
| 179 | return row.count |
| 180 | } |
| 181 | |
| 182 | streamMessages(batchSize: number, callback: (messages: ParsedMessage[]) => void): void { |
| 183 | const stmt = this.db.prepare(` |
| 184 | SELECT sender_platform_id, sender_account_name, sender_group_nickname, timestamp, type, content |
| 185 | FROM message ORDER BY timestamp ASC LIMIT ? OFFSET ? |
| 186 | `) |
| 187 | |
| 188 | let offset = 0 |
| 189 | while (true) { |
| 190 | const rows = stmt.all(batchSize, offset) as Array<{ |
| 191 | sender_platform_id: string |
| 192 | sender_account_name: string | null |
| 193 | sender_group_nickname: string | null |
| 194 | timestamp: number |
| 195 | type: number |
| 196 | content: string | null |
| 197 | }> |
| 198 |
nothing calls this directly
no outgoing calls
no test coverage detected