-
-
Notifications
You must be signed in to change notification settings - Fork 960
Expand file tree
/
Copy pathin-memory.ts
More file actions
24 lines (21 loc) · 686 Bytes
/
in-memory.ts
File metadata and controls
24 lines (21 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// With this adapter, calling `db.write()` will do nothing.
// One use case for this adapter can be for tests.
import { LowSync, MemorySync, SyncAdapter } from '../index.js'
import { JSONFileSync } from '../node.js'
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace NodeJS {
interface ProcessEnv {
NODE_ENV: 'test' | 'dev' | 'prod'
}
}
}
type Data = Record<string, unknown>
const defaultData: Data = {}
const adapter: SyncAdapter<Data> =
process.env.NODE_ENV === 'test'
? new MemorySync<Data>()
: new JSONFileSync<Data>('db.json')
const db = new LowSync<Data>(adapter, defaultData)
db.read()
// Rest of your code...