Skip to content

Commit 735af2a

Browse files
author
StackMemory Bot (CLI)
committed
feat(database): add getTablePage() for paginated table reads
Add getTablePage() to DatabaseAdapter (default no-op) and implement in SQLiteAdapter with parameterized LIMIT/OFFSET. Wire into MigrationManager.getBatch() to replace placeholder stubs.
1 parent 4294b64 commit 735af2a

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

src/core/database/database-adapter.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ export abstract class DatabaseAdapter {
204204
callback: (adapter: DatabaseAdapter) => Promise<void>
205205
): Promise<void>;
206206

207+
// Paginated table reads (for migration)
208+
async getTablePage(
209+
table: 'frames' | 'events' | 'anchors',
210+
offset: number,
211+
limit: number
212+
): Promise<any[]> {
213+
void table;
214+
void offset;
215+
void limit;
216+
return []; // Default no-op; overridden in concrete adapters
217+
}
218+
207219
// Export/Import for migration
208220
abstract exportData(
209221
tables: string[],

src/core/database/migration-manager.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -453,25 +453,12 @@ export class MigrationManager extends EventEmitter {
453453
const safeLimit = Math.max(1, Math.min(limit, 10000));
454454
const safeOffset = Math.max(0, offset);
455455

456-
// TODO: Use these options when adapter methods support pagination
457-
void safeLimit;
458-
void safeOffset;
459-
460-
switch (table) {
461-
case 'frames':
462-
// This would need to be implemented in the adapter
463-
return []; // Placeholder
464-
case 'events':
465-
return []; // Placeholder
466-
case 'anchors':
467-
return []; // Placeholder
468-
default:
469-
throw new DatabaseError(
470-
`Unsupported table: ${table}`,
471-
ErrorCode.DB_QUERY_FAILED,
472-
{ table }
473-
);
474-
}
456+
const validTable = table as 'frames' | 'events' | 'anchors';
457+
return this.config.sourceAdapter.getTablePage(
458+
validTable,
459+
safeOffset,
460+
safeLimit
461+
);
475462
}
476463

477464
private async migrateBatch(table: string, batch: any[]): Promise<void> {

src/core/database/sqlite-adapter.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,33 @@ export class SQLiteAdapter extends FeatureAwareDatabaseAdapter {
17671767
});
17681768
}
17691769

1770+
async getTablePage(
1771+
table: 'frames' | 'events' | 'anchors',
1772+
offset: number,
1773+
limit: number
1774+
): Promise<any[]> {
1775+
if (!this.db)
1776+
throw new DatabaseError(
1777+
'Database not connected',
1778+
ErrorCode.DB_CONNECTION_FAILED
1779+
);
1780+
1781+
const safeLimit = Math.max(1, Math.min(limit, 10000));
1782+
const safeOffset = Math.max(0, offset);
1783+
const allowedTables = ['frames', 'events', 'anchors'] as const;
1784+
if (!(allowedTables as readonly string[]).includes(table)) {
1785+
throw new DatabaseError(
1786+
`Invalid table name: ${table}`,
1787+
ErrorCode.DB_QUERY_FAILED,
1788+
{ table }
1789+
);
1790+
}
1791+
1792+
return this.db
1793+
.prepare(`SELECT * FROM ${table} ORDER BY rowid LIMIT ? OFFSET ?`)
1794+
.all(safeLimit, safeOffset);
1795+
}
1796+
17701797
async vacuum(): Promise<void> {
17711798
if (!this.db)
17721799
throw new DatabaseError(

0 commit comments

Comments
 (0)