@chcaa/json-db v0.2.0
json-db Core
The core module of json-db that can be used independently of the json-db Editor.
The module supports the following:
- CLI tools for exporting data and renaming collections and collection properties.
- Programmatically interaction with a json-db database, supporting the same features as the editor such as creating, editing and searching entries.
CLI Tools
The json-db core module includes a set of CLI tools for exporting data and altering the database schema. All CLI tools can be executed using npx.
Each CLI tool includes a -h / --help command that prints all required and optional arguments and options.
Example
npx @chcaa/json-db@latest export -hExporting Entries
Export entries from the database in ndjson format with the possibility of searching and populating relational entries.
Example - general usage
npx @chcaa/json-db@latest export "/path/to/db/root-dir" "collectionName" "/dest/path/entries.ndjson" -q "query" -p "populateField1,populateField12"Example - export "books" with "authors"
npx @chcaa/json-db@latest export /path/to/books-db books /desktop/books.ndjson -p authorsRenaming a Collection
Rename a collection and all references to the collection in the database schema.
Example - general usage
npx @chcaa/json-db@latest rename-collection "/path/to/db/root-dir" "currentPluralName" "newPluralName" "newSingularName"Example - rename the collection "books" to "works"
npx @chcaa/json-db@latest rename-collection /path/to/books-db books works workRenaming a Collection Field
Rename a collection field and all references to the field both in the schema and in entries of the collection.
Example - general usage
npx @chcaa/json-db@latest rename-collection-field "/path/to/db/root-dir" "collectionPluralName" "fieldPath" "newPropName" "newPropTitle"Example - rename the "author" field in the "books" collection to "writers"
npx @chcaa/json-db@latest rename-collection-field /path/to/books-db books authors writers WritersBulk Updating Entries
Currently, the CLI tools do not support bulk updates on entries such as updating the property of all entries where a specific condition is met.
But jq should is most cases be able to carry out the required task.
Install jq from https://jqlang.org/download/
E.g., to rename the genre of all books where the current genre is "classics" to "must-read" the following jq expression can be used.
jq '.entries |= map(if .genre == "classics" then .genre = "must-read" else . end)' books.json > books-new.jsonVerify that the content of the books-new.json is correct and overwrite the current file (mv books-new.json books.json).
Experiment with jq at https://play.jqlang.org/.
5 months ago