@mikhailsdv/detabase
v1.1.4
Published
CLI for Deta Base.
Downloads
3
Readme
detabase
Deta Base CLI with extended functionality written on Node.js
Use Cases
- Query, get, put, insert, delete, update items.
- Export databases with or without a specific query.
- Print databases in the table or json view.
- Put or insert data from command line or from file.
- Clone databases with or without a specific query.
- Delete or update multiple items with a query.
- Truncate databases.
- Create empty databases.
- Count items in database.
Usage
npm install -g @mikhailsdv/detabase
After installing it, run detabase --help
without arguments to see list of options:
Usage: detabase [options] [command]
Options:
-v, --version Output the current version.
-h, --help Read more information.
Commands:
export [options] <database> Create a .json dump of a given database. If no query provided, exports the
whole database.
count [options] <database> Count items of a given database with or without a query.
clone [options] <database> <new-name> Clone database.
insert [options] <database> Insert items into existing database. Creates a new item only if no item with
the same key exists.
put [options] <database> Put items into existing database. This request overwrites an item if it's key
already exists.
create <database> Creates a database.
truncate <database> Truncates a database.
query [options] <database> Show items matching a query.
delete [options] <database> [key] Deletes an item with the given key or items matching a query.
update [options] <database> [key] Update an item with the given key or items matching a query.
get <database> <key> Get an item with the given key. Use "detabase query <query>" in order to be
able to specify a query.
auth <project-key> Set your project key.
help [command] Display help for command.
First thing you need to do is to set your Deta project key by running:
detabase auth your_project_key
From now, you can run any command. Note that this project uses Deta's syntax for querying, so whenever you see <query>
it expects you to use queries as described here.
Available commands
export
Syntax:
detabase export <database> -q <query> -li <limit> -la <last> -fn <filename>
detabase export <database> --query <query> --limit <limit> --last <last> -filename <filename>
Examples:
# Export the whole database `users`
detabase export users
# Export only users whose age equals to 25
detabase export users -q "{age: 25}"
# Export only users whose age is greater than 18
# and save the file in the specific path
detabase export users -q "{'age?gt': 18}" -fn ../folder/export.json
insert
Syntax:
detabase insert <database> -i <items> -ff <from-file>
detabase insert <database> --items <items> --from-file <from-file>
Examples:
# Insert an item to database `users`
detabase insert users -i "{name: 'Jack', age: 22}"
# Insert two items to database `users`
detabase insert users -i "[{name: 'Jack', age: 22},{name: 'Hanna', age: 25}]"
# Insert data from json file
detabase insert users -ff "./some/path/data_to_insert.json"
put
Syntax:
detabase put <database> -i <items> -ff <from-file>
detabase put <database> --items <items> --from-file <from-file>
Examples:
# Insert an item to database `users`
detabase put users -i "{name: 'Jack', age: 22}"
# Insert two items to database `users`
detabase put users -i "[{name: 'Jack', age: 22},{name: 'Hanna', age: 25}]"
# Insert data from json file
detabase put users -ff "./some/path/data_to_insert.json"
delete
Syntax:
detabase delete <database> -q <query>
detabase delete <database> --query <query>
Examples:
# Delete an item from `users` with the key "csn9weej2"
detabase delete users csn9weej2
# Delete users with name Jack
detabase delete users -q "{name: 'Jack'}"
update
Syntax:
detabase update <database> -q <query> -s <object> -i <object> -a <object> -p <object> -d <string, array>
detabase update <database> --query <query> --set <object> --increment <object> --append <object> --prepend <object> --delete <string, array>
Examples:
# Update an item from `users` with the key "csn9weej2", set name to "Hanna"
detabase update users csn9weej2 --set "{name: 'Hanna'}"
# Update users with age = 18, increment their ages by 1.
detabase update users -q "{age: 18}" --increment "{age: 1}"
query
Syntax:
detabase query <database> -q <query> -li <limit> -la <last> -j
detabase query <database> --query <query> --limit <limit> --last <last> --json
Examples:
# Show all items from `users`
detabase query users
# Print a table with users whose age is 18
detabase query users -q "{age: 18}"
# Pring json items of users whose age is 18
detabase query users -q "{age: 18}" -j
create
Syntax:
detabase create <database>
Examples:
# Create a database named `new_db`
detabase create new_db
clone
Syntax:
detabase clone <database> <new-name> -q <query> -f
detabase clone <database> <new-name> --query <query> --force
Examples:
# Clone `some_db` into `new_db`
detabase clone some_db new_db
# Clone `some_db` into `existing_db` even if database with the given name already exists
detabase clone some_db existing_db --force
get
Syntax:
detabase get <database> <key>
Examples:
# Get an item with key "csn9weej2" from `users` database
detabase get users csn9weej2
truncate
Syntax:
detabase truncate <database>
Examples:
# Remove all the items from `users` database
detabase truncate users
count
Syntax:
detabase count <database> -q <query>
detabase count <database> --query <query>
Examples:
# Count items of `users` database
detabase count users
# Count items of `users` database where name = 'Jack'
detabase count users -q "{name: 'Jack'}"