Skip to content

Commit

Permalink
Merge pull request #20 from shubhvjain/main
Browse files Browse the repository at this point in the history
new ver release
  • Loading branch information
shubhvjain authored Oct 1, 2024
2 parents a8df8dd + fd96dce commit 4559d73
Show file tree
Hide file tree
Showing 13 changed files with 955 additions and 585 deletions.
136 changes: 7 additions & 129 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,137 +1,15 @@
# BeanbagDB

<div style="text-align:center">

<img src="./docs/logo.png" alt="Alt text" style="width:auto; height:100px">

v 0.0.0
</div>

## The Database architecture
A BeanbagDB is a collection of JSON documents. In a NoSQL database, documents don't need to follow a specific schema. Typically, the developer defines a schema based on the specific problem the app is intended to solve.

While, BeanBagDB allows users to create their own schemas for documents, all document internally share a consistent structure that accommodates the user defined schema.

Each document in the database follows this structure :
```
{
_id, _rev
data : {
user data
},
schema: "name_of_the_schema",
meta : {},
}
```

Here, the `data` object contains user's information, while the `schema` defines it's associated structure. The `meta` field holds metadata such as creation and last updated on date and user defined tags.

Even schema documents follow this structure.

### Examples :

A system defined schema :
```
{
schema:"schema"
data : {
name: "system_tags",
.....
},
...
}
```
(In this example, the schema of this doc is `schema` because it stores the schema document, which will be use to validate documents that follows this schema)
[![Test code on master](https://github.com/shubhvjain/beanbagdb/actions/workflows/test_on_master.yml/badge.svg)](https://github.com/shubhvjain/beanbagdb/tree/main)

The document adhering to this schema might look like :
```
{
schema:"system_tags",
data:{
tags:["tag1","tag2"]
}
....
}
```
User Defined schemas :
```
{
"schema":"schema",
"data":{
"name":"contacts",
...
}
}
```
And a sample document based on this user defined schema might look like :
```
{
schema:"contacts",
"data":{
"name":"Human 1",
"email":"[email protected]"
}
}
```
[![npm](https://github.com/shubhvjain/beanbagdb/actions/workflows/release.yml/badge.svg)](https://www.npmjs.com/package/beanbagdb)

### System defined schemas
To ensure the system functions smoothly, each DB is initialized with a set of system defined schemas and seed documents. These are automatically added when the database is first created. These system defined are typically named with the prefix `system_`.
[![Generate and Deploy JSDoc](https://github.com/shubhvjain/beanbagdb/actions/workflows/deploy_docs.yml/badge.svg)](http://svja.in/beanbagdb/)

List of system schemas :
- `logs` : to log system and user actions
- `settings` : System level settings (`name`,`value`,`json` for more details)
- `keys` : user level settings , these are encrypted and stored in the DB
- `secrets` : encrypted text (TODO)
- `relations` : To create a network of relations (TODO)
- `index` : (TODO)
- `scripts` : (TODO)

## The BeanBagDB class

The `BeanBagDB` class contains the the logical part of how to interact with a local database. However, it does not itself makes any changes in the database. To make it (somewhat) compatible with multiple databases (e.g. CouchDB on the server, PouchDB in the browser), the class takes an db_instance object where the actual CRUD actions on the database can be performed.

To add support for a database, we extend the `BeanBagDB` class.

### API
- `initialize_db()`
- `log(stuff={whatever})`
- `get_setting_doc(setting_name)`
- `get_schema_doc()`
- `validate_data()`
- `insert_pre_check()`
- `insert()`
- `get()`
- `load_doc()`
- `update_data()`
- ...


## JSON Schema (in progress)
[Source](https://json-schema.org/) and [another](https://www.learnjsonschema.com/2020-12/)

### Basic schema structure
```
{
"name":"",
"description":"",
"properties":{
},
"settings":{
<div style="text-align:center">

}
}
```
#### Properties:
- Settings :
- `additionalProperties:true`
- `required:[]`
-
- Defining custom fields :
- `type:""` Valid values: ``
<img src="./doc-src/logo.png" alt="Alt text" style="width:auto; height:100px">
</div>


#### Settings :
- `primary_key:[]`
- `editable_fields:[]`
- `single_record : true`
Please see the project [documentation website](http://svja.in/beanbagdb/) for more details.
115 changes: 115 additions & 0 deletions doc-src/0_about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
## The Database architecture
A BeanbagDB is a collection of JSON documents. In a NoSQL database, documents don't need to follow a specific schema. Typically, the developer defines a schema based on the specific problem the app is intended to solve.

While, BeanBagDB allows users to create their own schemas for documents, all document internally share a consistent structure that accommodates the user defined schema.

Each document in the database follows this structure :
```
{
_id, _rev
data : {
user data
},
schema: "name_of_the_schema",
meta : {},
}
```

Here, the `data` object contains user's information, while the `schema` defines it's associated structure. The `meta` field holds metadata such as creation and last updated on date and user defined tags.

Even schema documents follow this structure.

### Examples :

A system defined schema :
```
{
schema:"schema"
data : {
name: "system_tags",
.....
},
...
}
```
(In this example, the schema of this doc is `schema` because it stores the schema document, which will be use to validate documents that follows this schema)

The document adhering to this schema might look like :
```
{
schema:"system_tags",
data:{
tags:["tag1","tag2"]
}
....
}
```
User Defined schemas :
```
{
"schema":"schema",
"data":{
"name":"contacts",
...
}
}
```
And a sample document based on this user defined schema might look like :
```
{
schema:"contacts",
"data":{
"name":"Human 1",
"email":"[email protected]"
}
}
```

### System defined schemas
To ensure the system functions smoothly, each DB is initialized with a set of system defined schemas and seed documents. These are automatically added when the database is first created. These system defined are typically named with the prefix `system_`.

List of system schemas :
- `logs` : to log system and user actions
- `settings` : System level settings (`name`,`value`,`json` for more details)
- `keys` : user level settings , these are encrypted and stored in the DB
- `secrets` : encrypted text (TODO)
- `relations` : To create a network of relations (TODO)
- `index` : (TODO)
- `scripts` : (TODO)

## The BeanBagDB class

The `BeanBagDB` class contains the the logical part of how to interact with a local database. However, it does not itself makes any changes in the database. To make it (somewhat) compatible with multiple databases (e.g. CouchDB on the server, PouchDB in the browser), the class takes an db_instance object where the actual CRUD actions on the database can be performed.

To add support for a database, we extend the `BeanBagDB` class.


## JSON Schema (in progress)
[Source](https://json-schema.org/) and [another](https://www.learnjsonschema.com/2020-12/)

### Basic schema structure
```
{
"name":"",
"description":"",
"properties":{
},
"settings":{
}
}
```
#### Properties:
- Settings :
- `additionalProperties:true`
- `required:[]`
-
- Defining custom fields :
- `type:""` Valid values: ``


#### Settings :
- `primary_key:[]`
- `editable_fields:[]`
- `single_record : true`
1 change: 1 addition & 0 deletions doc-src/1_getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Getting started
1 change: 1 addition & 0 deletions doc-src/2_schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# How to add a new schema
1 change: 1 addition & 0 deletions doc-src/3_plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# How to use plugins
15 changes: 15 additions & 0 deletions doc-src/contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"0_about": {
"title": "About BeanBagDB"
},
"1_getting-started": {
"title": "Getting Started"
},
"2_schema": {
"title": "How to create a schema?"
},

"3_plugins": {
"title": "How to use plugins?"
}
}
File renamed without changes
2 changes: 1 addition & 1 deletion jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"destination": "./docs-static",
"recurse": true,
"readme":"./index.md",
"tutorials": "./docs"
"tutorials": "./doc-src"
},
"plugins": [
"plugins/markdown"
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "beanbagdb",
"version": "0.5.51",
"version": "0.5.52",
"description": "A JS library to introduce a schema layer to a No-SQL local database",
"main": "src/index.js",
"module": "src/index.js",
"type": "module",
"scripts": {
"test": "mocha"
"test": "mocha",
"docgen": "npx jsdoc -c jsdoc.json"
},
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit 4559d73

Please sign in to comment.