Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base-Docs #13

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ dist
*.akvdb
*.akvdbc
*.akvdbi
*.sz

database/
105 changes: 104 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,104 @@
# akivaDB
# AkivaDB

[![NPM Info](https://nodei.co/npm/akivadb.png?downloads=true&stars=true)](https://nodei.co/npm/akivadb)
[![NPM Version](https://img.shields.io/npm/v/akivadb.svg?maxAge=3600)](https://www.npmjs.com/package/akivadb)
[![NPM Downloads](https://img.shields.io/npm/dt/akivadb.svg?maxAge=3600)](https://www.npmjs.com/package/akivadb)


## Table Of Contents
- [AkivaDB](#akivadb)
- [Table Of Contents](#table-of-contents)
- [About](#about)
- [Examples](#examples)
- [Setup](#setup)
- [Creating a Collection](#creating-a-collection)
- [Interacting with the Collection](#interacting-with-the-collection)
- [Methods](#methods)
- [Core](#core)
- [Database](#database)
- [Collection](#collection)
- [Collection Data Events](#collection-data-events)


## About
This is a Lightweight Schema-Free Object-Oriented LocalDatabase for Development and Educational Purposes.

An Object Oriented and Index Based Database. <br>
Fast, Secure, and Easy to use. </br>

## Examples

### Setup
```js
const AkivaDB = require('akivadb')
const DB = AkivaDB('database')
const Collection = DB.collection({
name: "Collection",
ttl: 15 //optional
})

;(async () => {
await Collection.insert({
fullName: "John Doe",
email: "john.doe@test.com"
}, {
_id: "random1234"
})

console.log(await Collection.find({
fullName: "John Doe"
})) //returns [{ fullName: "John Doe", email: "john.doe@test.com", _id: "random1234"}]
})()
```

### Creating a Collection
```js
const Collection = DB.collection({
name: "Collection",
ttl: 60 //ttl (Time to Live) in seconds
})
```

### Interacting with the Collection
```js
await Collection.insert({ name:"Joshua" })

const data = await Collection.findOne({ name:"Joshua" })

console.log(data) //returns { name:"Joshua" }
```

## Methods

### Core
- Core(name) - The constructor of Database
- Core.version - Return current version of akivadb

### Database
- Database.collection({ name:"string", ttl:15 }) - Method to create a Collection
- Database.isReady - Condition if database is ready to use
- Database.displayName - The name of the Database
- Database.on('ready', () => void) - Emitted whenever the database is ready to use

### Collection
- Collection.db - The main database of the collection
- Collection.displayName - The name of the Collection
- Collection.size - The size of the Collection
- Collection.isOpen - Condition if the Collection is Useable (ready and not closed), Returns Boolean
- Collection.find(filter, limit) - Finds the data in the Collection
- Collection.findOne(filter) - Find one data in the Collection
- Collection.insert(data, filter) - Creates a data in the Collection
- Collection.delete(filter, limit) - Delete a data in the collection
- Collection.update(filter, property, value, object?) - Update a data in the collection
- Collection.deleteMany(...filters) - Delete some datas in the collection
- Collection.close() - Close the collection, the data remains in file
- Collection.destroy() - Destroy the connection between the Collection and delete the data in the Collection
- Collection.on('ready', () => void) - Emitted whenever the collection is ready to use
- Collection.on('ttl', (started: Boolean) => void) - Emitted whenever the ttl checking process is started or ended
- Collection.on('expired', (data: Object) => void) - Emitted whenever a data is expired if ttl is active

### Collection Data Events
- Collection.on('dataInserted', (data) => {void}) - Emitted whenever a data is inserted into the collection
- Collection.on('dataDeleted', (data) => {void}) - Emitted whenever a data is deleted from the collection
- Collection.on('manyDeleted', (data) => {void}) - Emitted whenever batch data is deleted from the collection
- Collection.on('dataUpdated', (data) => {void}) - Emitted whenever a record is updated in the collection
4 changes: 2 additions & 2 deletions lib/core/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Util = require("../utils");
const AkivaDBError = require("../utils/ErrorHandler");
const Writer = require("./writer");
const DB = require("./db");
const Bison = require("../fns");
const Fns = require("../fns");
const { EventEmitter } = require("events");

const MAX_SIZE = 1018220;
Expand Down Expand Up @@ -225,7 +225,7 @@ class Collection extends EventEmitter {
return res();
}

data = Bison.decode(data);
data = Fns.decode(data);

let json;

Expand Down
2 changes: 1 addition & 1 deletion lib/core/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Database extends EventEmitter {

if (typeof opts.ttl === "number" && opts.ttl < 5)
throw new AkivaDBError(
"TTL check interval must be 5 seconds at minimal!",
"TTL must be a minimum of 5 seconds!",
5
);

Expand Down
4 changes: 2 additions & 2 deletions lib/core/writer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const AkivaDBError = require("../utils/ErrorHandler");
const Bison = require("../fns");
const Fns = require("../fns");
const { EventEmitter } = require("events");
const { Readable } = require("stream");

Expand Down Expand Up @@ -145,7 +145,7 @@ class Writer extends EventEmitter {

json[0] = json[0].substring(1, json[0].length - 1);

return [Bison.encode(json[0]), json[1]];
return [Fns.encode(json[0]), json[1]];
}

approximateSize(obj) {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "akivadb",
"version": "1.0.1-alpha.2",
"version": "1.0.1-alpha.2+001",
"description": "A Lightweight Schema-Free Object-Oriented LocalDatabase for Development and Educational Purposes",
"main": "lib/index.js",
"scripts": {
"repl": "node index.js repl",
"start": "node tests/test.js"
"repl": "node repl/index.js repl",
"test": "node tests/test.js"
},
"repository": {
"type": "git",
"url": "https://github.com/bolorundurovj/akivaDB.git"
},
"keywords": [],
"author": "Bolorunduro Valiant-Joshua",
"license": "ISC",
"license": "BSD 3-Clause",
"bugs": {
"url": "https://github.com/bolorundurovj/akivaDB/issues"
},
Expand Down
12 changes: 12 additions & 0 deletions repl/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const repl = require('repl')

if (process.argv[2] === 'repl') {
repl.start({
prompt: 'AkivaDB $ ',
eval: evaluateArgs
})
}

function evaluateArgs(params) {
console.log(params);
}
2 changes: 1 addition & 1 deletion tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ db.once("ready", async () => {
++i;
}

col.findOne({_index: 4985}).then((x) => {
col.find({_index: 4985}).then((x) => {
console.log(x);
}).catch((err) => {
console.log(err);
Expand Down