Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ export function initCommand(program: Command): void {
await saveEnvs(configOutputPath, envs, 'init');
// 获取数据库统计信息
const dbManager = createDatabaseManagerFromConfigPath(configOutputPath);
const dbStats = dbManager.getStats();
dbManager.close();
let dbStats;
try {
dbStats = dbManager.getStats();
} finally {
dbManager.close();
}

console.log(chalk.green(`✅ Configuration file created successfully: ${options.output}`));
console.log(chalk.green(`🗄️ Database initialized successfully: .envx/envx.db`));
Expand Down
18 changes: 11 additions & 7 deletions src/utils/com.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ export async function getEnvs(configPath: string, tag?: string): Promise<EnvMap>

if (tag) {
const dbManager = createDatabaseManagerFromConfigPath(configPath);
envMap = dbManager.getTaggedValues(tag);
dbManager.close();
return envMap;
try {
envMap = dbManager.getTaggedValues(tag);
return envMap;
} finally {
dbManager.close();
}
}

// 合并 .env 文件内容
Expand Down Expand Up @@ -56,10 +59,11 @@ export async function getEnvs(configPath: string, tag?: string): Promise<EnvMap>

export async function saveEnvs(configPath: string, envMap: EnvMap, tag?: string) {
const dbManager = createDatabaseManagerFromConfigPath(configPath);

dbManager.batchUpsertTaggedValues(envMap, tag);

dbManager.close();
try {
dbManager.batchUpsertTaggedValues(envMap, tag);
} finally {
dbManager.close();
}
}

export async function writeEnvs(configPath: string, envMap: EnvMap) {
Expand Down
Loading