()
| 15 | import type { DataAdapter } from '../data/types' |
| 16 | |
| 17 | function createDb(): Database.Database { |
| 18 | const db = new Database(':memory:') |
| 19 | db.exec(` |
| 20 | CREATE TABLE segment ( |
| 21 | id INTEGER PRIMARY KEY, |
| 22 | start_ts INTEGER, |
| 23 | end_ts INTEGER, |
| 24 | message_count INTEGER, |
| 25 | summary TEXT |
| 26 | ); |
| 27 | CREATE TABLE message_context ( |
| 28 | message_id INTEGER, |
| 29 | segment_id INTEGER, |
| 30 | topic_id INTEGER |
| 31 | ); |
| 32 | `) |
| 33 | const insSeg = db.prepare('INSERT INTO segment (id, start_ts, end_ts, message_count, summary) VALUES (?, ?, ?, ?, ?)') |
| 34 | insSeg.run(1, 100, 200, 3, null) |
| 35 | insSeg.run(2, 300, 400, 2, 'summary-2') |
| 36 | |
| 37 | // 故意打乱插入顺序,验证 firstMessageId 取的是 message_id 最小值 |
| 38 | const insCtx = db.prepare('INSERT INTO message_context (message_id, segment_id, topic_id) VALUES (?, ?, NULL)') |
| 39 | insCtx.run(11, 1) |
| 40 | insCtx.run(10, 1) |
| 41 | insCtx.run(12, 1) |
| 42 | insCtx.run(31, 2) |
| 43 | insCtx.run(30, 2) |
| 44 | return db |
| 45 | } |
| 46 | |
| 47 | function registerSqliteDataAdapter(db: Database.Database): void { |
| 48 | const fake = { |
no test coverage detected