Skip to content

Commit 6bbd89f

Browse files
committed
chore: refactor db options type
1 parent f6db5e7 commit 6bbd89f

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

src/types.ts

+11-25
Original file line numberDiff line numberDiff line change
@@ -454,32 +454,18 @@ export interface IMiftahDB<T extends MiftahValue = MiftahValue> {
454454
/*
455455
Represents the PRAGMA statements that can be used to configure the database.
456456
*/
457-
export type JournalModes = "DELETE" | "TRUNCATE" | "PERSIST" | "WAL" | "MEMORY";
458-
export type SynchronousModes = "OFF" | "NORMAL" | "FULL" | "EXTRA";
459-
export type TempStoreModes = "DEFAULT" | "MEMORY" | "FILE";
460-
export type LockingModes = "NORMAL" | "EXCLUSIVE";
461-
export type AutoVacuumModes = "OFF" | "FULL" | "INCREMENTAL";
457+
export type DBOptions = Partial<{
458+
[K in keyof typeof defaultDBOptions]: K extends "cacheSize" | "mmapSize"
459+
? number
460+
: (typeof defaultDBOptions)[K];
461+
}>;
462462
export const defaultDBOptions = {
463-
journalMode: "WAL" as JournalModes,
464-
synchronousMode: "NORMAL" as SynchronousModes,
465-
tempStoreMode: "MEMORY" as TempStoreModes,
463+
journalMode: "WAL" as "DELETE" | "TRUNCATE" | "PERSIST" | "WAL" | "MEMORY",
464+
synchronousMode: "NORMAL" as "OFF" | "NORMAL" | "FULL" | "EXTRA",
465+
tempStoreMode: "MEMORY" as "DEFAULT" | "MEMORY" | "FILE",
466466
cacheSize: -64000,
467467
mmapSize: 30000000000,
468-
lockingMode: "NORMAL" as LockingModes,
469-
autoVacuumMode: "OFF" as AutoVacuumModes,
468+
lockingMode: "NORMAL" as "NORMAL" | "EXCLUSIVE",
469+
autoVacuumMode: "OFF" as "OFF" | "FULL" | "INCREMENTAL",
470+
cleanUpOnClose: false as boolean,
470471
} as const;
471-
export type DBOptions = {
472-
[K in keyof typeof defaultDBOptions]?: K extends "cacheSize" | "mmapSize"
473-
? number
474-
: K extends "journalMode"
475-
? JournalModes
476-
: K extends "synchronousMode"
477-
? SynchronousModes
478-
: K extends "tempStoreMode"
479-
? TempStoreModes
480-
: K extends "lockingMode"
481-
? LockingModes
482-
: K extends "autoVacuumMode"
483-
? AutoVacuumModes
484-
: never;
485-
};

0 commit comments

Comments
 (0)