-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tests: adde some query and find tests * docs: added core concepts explains logic * fix!(SBTree): .insertDocument to return array on single inclusion * chore: update dependencies * doc: additional primitives doc * doc: improve navigation * fix: improve fieldName fetching from query * fix: finding recursive * fix: proper $in search
- Loading branch information
Showing
38 changed files
with
465 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
# Changelog | ||
|
||
## 3.0.2 | ||
|
||
- fix!(SBTree): .insertDocument to return array on single inclusion | ||
- fix: improve fieldName fetching from query | ||
- fix: finding recursive and $in | ||
- tests: added some query and find tests | ||
- doc: primitives documentation | ||
- doc: improved navigation |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
## Core Concepts | ||
|
||
SBTree allows you to insert, delete, update, replace and find withing a balance B+ tree supporting uniqueness, and optional fields. | ||
|
||
SBTree holds set of SBFTree (F stands for Field). | ||
|
||
On each insertion of a document, we parse all individual field, if we did not yet have a SBFTree with this fieldName, we creates. | ||
|
||
All further instruction (finding, inserting,...) are directed to this tree manager. | ||
|
||
## SBFTree | ||
|
||
A SBFTree is unique for each fields, for nested object, each field of this object also have their own SBFTree. | ||
|
||
Using B+Tree, we have a root, that lead to leaf, or intermediaries node (holding leafs) and we manage indexing this way. | ||
|
||
In those nodes (SBFRoot, SBFLeaf, SBFNode), we hold childrens reference (half splitting), set of keys (in a SBFTree of names, that would be ["Jean Valjean",...]) and identifiers (_id of the document). | ||
|
||
The logic is then that we parse query into those fieldTrees to output identifiers, and we resolves those identifiers by looking for a get of those document by Id. | ||
|
||
## Adapters | ||
|
||
This system allows to have a indices db locally, that support a MongoDB style command (but without any thing to install). | ||
|
||
Due to the fact that it request persistance on a key-value way (via document id), it can be adaptable to a range of usage (local memory with single file save persistance, fs-adapter with single file / id, localstorage, mongodb,...); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
### SBFLeaf | ||
|
||
SBFLeaf represents the end of the tree. | ||
They contain a size, the identifier array, and the set of keys. | ||
|
||
They rely on the adapter to fetch these informations back. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### SBFNode | ||
|
||
SBFNode represents a part of the tree that is not a Leaf (intermediary nodes). | ||
|
||
They contains the splitting keys (split of keys in the form of a binary search) and the references to the childrens nodes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
### SBFRoot | ||
|
||
SBFRoot represents the first node of our tree, the starting point from which we perform the insertion, replacement, deletion or search. | ||
|
||
It contains multiples SBFNode (or Leaf) childrens, and a tiny subset of data in a keys and identifiers array. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### SBFTree API | ||
|
||
```js | ||
const fielTree = new SBFTree([props]); | ||
``` | ||
- Constructor options : | ||
- `adapter` Adapter - (def: MemoryAdapter) : Allow to specific another adapter to use | ||
- `order` Number - (def: 511) : Primordial for the performance, the closest to L1 the better. Chose below 2^n. | ||
- `fillFactor` Float - (def: 0.5) : Used for balancing the tree. Should not be less than 0.5 (50%). | ||
- `verbose` Bool - (def: false) | ||
- `isUnique` Bool - (def: false) | ||
- `root` SBFRoot - (def: null) - Allow to set a root to the fieldTree. | ||
- `exclude` Array - (def: []) - Allow to exclude from indexing some field (important if you expect field value to be huge or nested). | ||
- `id` FieldId - Allow to identify a FieldTree by an id; useful especially for adapter. | ||
|
||
### Usage | ||
|
||
The SBFTree is an interface instance specific to a field. For a document {age, name}, you would have two SBFTree, one for age, one for name. | ||
|
||
The Tree has two components, an identifier (of the document), and a value and use a B+Tree. | ||
|
||
|
||
### Methods | ||
|
||
- [find](primitives/SBFTree/methods/find) | ||
- [get](primitives/SBFTree/methods/get) | ||
- [insert](primitives/SBFTree/methods/insert) | ||
- [remove](primitives/SBFTree/methods/remove) | ||
- [replace](primitives/SBFTree/methods/replace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#### async tree.find(value, operator) | ||
|
||
Will find a value using a specific operator. | ||
|
||
```js | ||
await tree.find(33, '$eq'); // Return set of identifiers and keys matching the find query. | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#### async tree.get(identifier) | ||
|
||
Will get back a specific identifier's value | ||
|
||
```js | ||
await tree.get('5d6755b71f9edbc997c8d156'); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#### async tree.insert(identifier, value) | ||
|
||
Will insert a set of identifier and value into the fieldTree. | ||
|
||
```js | ||
await tree.insert('5d6755b71f9edbc997c8d156', 33); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#### async tree.remove(identifier) | ||
|
||
Will remove a document from an identifier. | ||
The RemoveCommand instance holds the different fields to delete the identifiers from. | ||
|
||
```js | ||
const removeCommand = new RemoveCommand() | ||
await tree.remove(removeCommand); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#### async tree.replace(identifier, value) | ||
|
||
Will replace the value for an identifier. | ||
|
||
```js | ||
await tree.replace('5d6755b71f9edbc997c8d156', 60); | ||
``` | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
### SBTree | ||
|
||
```js | ||
const tree = new SBTree([props]); | ||
``` | ||
|
||
- Constructor options : | ||
- `adapter` Adapter - (def: MemoryAdapter) : Allow to specific another adapter to use | ||
- `order` Number - (def: 511) : Primordial for the performance, the closest to L1 the better. Chose below 2^n. | ||
- `fillFactor` Float - (def: 0.5) : Used for balancing the tree. Should not be less than 0.5 (50%). | ||
- `verbose` Bool - (def: false) | ||
- `uniques` Array - (def: []) - Allow to set some field unique by adding them to this array | ||
- `exclude` Array - (def: []) - Allow to exclude from indexing some field (important if you expect field value to be huge or nested). | ||
|
||
### Usage | ||
|
||
The SBTree is the instance that will allow you to insert, get, find, replace or delete documents. | ||
It internally hold multiple instances of [SBFTree](primitives/SBFTree.md) and works as a router, interfacing with the users. | ||
|
||
### Methods | ||
|
||
- [deleteDocuments](primitives/SBTree/methods/deleteDocuments) | ||
- [findDocuments](primitives/SBTree/methods/findDocuments) | ||
- [getDocument](primitives/SBTree/methods/getDocument) | ||
- [insertDocuments](primitives/SBTree/methods/insertDocuments) | ||
- [toJSON](primitives/SBTree/methods/toJSON) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#### async tree.deleteDocuments(query) | ||
|
||
Will delete all documents matching the query. | ||
|
||
See more info on [queries](/docs/usage/queries.md) | ||
|
||
```js | ||
await tree.deleteDocuments({age:33}); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#### async tree.findDocuments(query) | ||
|
||
Allow to find all documents matching the query | ||
|
||
See more info on [queries](/docs/usage/queries.md) | ||
|
||
|
||
```js | ||
await tree.findDocuments({age:33}); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
#### async tree.getDocument(_id) | ||
|
||
Allow to fetch a specific document by it's specific id. | ||
|
||
```js | ||
await tree.getDocument('507f191e810c19729de860ea') | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#### async tree.insertDocuments(documents) | ||
|
||
Allow to process an array (or unique) of documents and get them inserted. | ||
It returns the inserted array containing mutated (with their _id if not specified in document) values. | ||
|
||
```js | ||
await tree.insertDocuments({age:33, name:"Jean",_id:'507f191e810c19729de860ea'}) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#### tree.toJSON() | ||
|
||
Allow to return a representation in JSON of the tree. Useful for storing it, as it's result are valid params for the SBTree constructor. | ||
|
||
```js | ||
tree.toJSON() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.