How It Works
By default, if no argument is passed to the JasonDB()
class, it will create
a new database with the ‘db’ name, else it will use the name passed to the class as argument.
Here is how it is structured:
Directorydb
Directorysiths
- palpatine.json uuid is autogenerated if no id is passed
- …
Directorystormtroopers
- _metadata.json optional file with metadata about the collection
- CT-9901.json
- …
- …
Why it is structured like this?
We choose to make it NoSQL and Document base, because it is the most flexible way to store data. The database saves data locally.
It can create a database possibly anywhere in the system:
const db = new JasonDB({ basename: 'death-star', path: 'C:\\Users\\luke-skywalker' // or /home/luke-skywalker if you're on linux});
A database like that will create the following structure:
DirectoryC:\Users\luke-skywalker
Directorydeath-star
Directorycollection_product
- …
What is a collection?
A collection is a group of documents, it is like a table in a relational database. You can create as many collections as you want.
So inside the database folder, you will find a folder for each collection. And for each collection, you will find documents, one file for each document.
What is a document?
A document is a single record, it is like a row in a relational database.
You can create as many documents as you want. They’re save as .json
files.
For simplicity, other file formats are not supported yet.
The name for every document is autogenerated by the database, but you can pass an id to the document.
await collection.create({ id: 'jedi-1', name: 'Luke Skywalker', age: 19})
What is the _metadata.json file?
The _metadata.json file is an optional file that contains metadata about the collection. It is used to store information about the collection, like the number of documents, index keys, etc.
For example:
{ "name": "stormtroopers", "documentCount": 0, "indexes": ["name", "age"], "lastModified": 1684704469}