Skip to content

Commit 665c9dc

Browse files
committed
add storagePrefix for db factory...
avoids conflicts between different packages that do db operations
1 parent e0632f3 commit 665c9dc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/db/src/factory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ interface DBEnv {
1010
COUCHDB_SERVER_PROTOCOL: string; // Protocol of CouchDB server (http or https)
1111
COUCHDB_USERNAME?: string;
1212
COUCHDB_PASSWORD?: string;
13+
LOCAL_STORAGE_PREFIX: string; // Prefix for IndexedDB storage names
1314
}
1415

1516
export const ENV: DBEnv = {
1617
COUCHDB_SERVER_PROTOCOL: 'NOT_SET',
1718
COUCHDB_SERVER_URL: 'NOT_SET',
19+
LOCAL_STORAGE_PREFIX: '',
1820
};
1921

2022
// Configuration type for data layer initialization
@@ -44,6 +46,9 @@ export async function initializeDataLayer(config: DataLayerConfig): Promise<Data
4446
logger.warn('Data layer already initialized. Returning existing instance.');
4547
return dataLayerInstance;
4648
}
49+
if (config.options.localStoragePrefix) {
50+
ENV.LOCAL_STORAGE_PREFIX = config.options.localStoragePrefix;
51+
}
4752

4853
if (config.type === 'couch') {
4954
if (!config.options.COUCHDB_SERVER_URL || !config.options.COUCHDB_SERVER_PROTOCOL) {

packages/db/src/util/dataDirectory.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import * as fs from 'fs';
55
import * as path from 'path';
66
import * as os from 'os';
77
import { logger } from './tuiLogger';
8+
import { ENV } from '@db/factory';
89

910
/**
1011
* Get the application data directory for the current platform
1112
* Uses ~/.tuilder as requested by user for simplicity
1213
*/
1314
export function getAppDataDirectory(): string {
14-
return path.join(os.homedir(), '.tuilder');
15+
if (ENV.LOCAL_STORAGE_PREFIX) {
16+
return path.join(os.homedir(), `.tuilder`, ENV.LOCAL_STORAGE_PREFIX);
17+
} else {
18+
return path.join(os.homedir(), '.tuilder');
19+
}
1520
}
1621

1722
/**

0 commit comments

Comments
 (0)