Skip to content
File

Blob: src/worker/do/repo/db/dal/shared.ts

typescript24 lines
1/**
2 * Shared helpers for repo SQLite DAL modules.
3 */
4 
5/**
6 * Safe maximum bound parameters per SQLite query on the platform.
7 * Keep some headroom below the documented 100 to account for potential
8 * extra bound params Drizzle may include.
9 */
10export const SQLITE_PARAM_LIMIT = 100;
11export const SAFE_ROWS_2COL = 45; // 2 columns per row -> 90 params (< 100)
12export const SAFE_ROWS_3COL = 30; // 3 columns per row -> 90 params (< 100)
13export const SAFE_ROWS_1COL = 80; // 1 column per row -> 80 params (< 100)
14 
15/**
16 * Normalize a pack key to its basename (for example `pack-123.pack`).
17 * SQLite stores basenames only to avoid duplicating the full repo prefix.
18 */
19export function normalizePackKey(key: string): string {
20 if (!key) return key;
21 const slash = key.lastIndexOf("/");
22 return slash >= 0 ? key.slice(slash + 1) : key;
23}