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
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,31 @@ db.set("key", "value", false); // Don't update the timestamp

### Import / Export

Importing JSON files can be done this way:
Importing structured data into the database can be done the following way:
```ts
// pass a filename, the import will be asynchronous
await db.importJson(filename);
// pass the object directly, the import will be synchronous
db.importJson({key: "value"});
db.importJSON({key: "value"});
```
In both cases, existing entries in the DB will not be deleted but will be overwritten if they exist.
Existing entries in the DB will not be deleted but will be overwritten if they exist.

Exporting JSON files is also possible:
Exporting the data as a JSON object is also possible:
```ts
await db.exportJson(filename[, options]);
const json = db.toJSON();
```
The file will be overwritten if it exists. The 2nd options argument can be used to control the file formatting. Since `fs-extra`'s `writeJson` is used under the hood, take a look at that [method documentation](https://github.com/jprichardson/node-fs-extra/blob/master/docs/writeJson.md) for details on the options object.

## Changelog

<!--
Placeholder for next release:
### __WORK IN PROGRESS__
-->
### __WORK IN PROGRESS__
* BREAKING: Drop support for Node.js versions older than v22 (#529)
* BREAKING: Removed `exportJson` method in favor of `toJSON`
* BREAKING: Renamed `importJson` method to `importJSON`. Importing from a file is no longer supported. Read the file yourself if you need this functionality.
* Filesystem access is now done using the native `fs.promises` instead of `fs-extra`
* The package is now a hybrid ESM/CJS package (#529)

### 3.1.1 (2024-01-25)
* Reduced CPU load while idle (#475)

Expand Down
30 changes: 8 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@commitlint/cli": "^20.1.0",
"@commitlint/config-conventional": "^20.0.0",
"@tsconfig/node22": "^22.0.2",
"@types/fs-extra": "^9.0.13",
"@types/node": "^22.18.8",
"@types/proper-lockfile": "^4.1.2",
"@vitest/coverage-istanbul": "^3.2.4",
Expand All @@ -64,8 +63,7 @@
},
"dependencies": {
"@alcalzone/proper-lockfile": "^4.1.3-0",
"alcalzone-shared": "^5.0.0",
"fs-extra": "^10.1.0"
"alcalzone-shared": "^5.0.0"
},
"overrides": {
"minimist@1.2.5": "^1.2.6"
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { FsWriteOptions, JsonlDB, JsonlDBOptions } from "./lib/db.js";
export { JsonlDB, JsonlDBOptions } from "./lib/db.js";
Loading