From d7f8c68b09b8675f5fd41064cc9146bc57b044f1 Mon Sep 17 00:00:00 2001 From: Bolorunduro Valiant-Joshua Date: Wed, 19 Jan 2022 14:15:01 +0100 Subject: [PATCH] Base-Docs --- .gitignore | 1 + README.md | 105 ++++++++++++++++++++++++++++++++++++++++- lib/core/collection.js | 4 +- lib/core/db.js | 2 +- lib/core/writer.js | 4 +- package.json | 8 ++-- repl/index.js | 12 +++++ tests/test.js | 2 +- 8 files changed, 127 insertions(+), 11 deletions(-) create mode 100644 repl/index.js diff --git a/.gitignore b/.gitignore index 6ecdd9e..da62738 100644 --- a/.gitignore +++ b/.gitignore @@ -107,5 +107,6 @@ dist *.akvdb *.akvdbc *.akvdbi +*.sz database/ \ No newline at end of file diff --git a/README.md b/README.md index dca336e..d968cf0 100644 --- a/README.md +++ b/README.md @@ -1 +1,104 @@ -# akivaDB \ No newline at end of file +# 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.
+Fast, Secure, and Easy to use.
+ +## 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 \ No newline at end of file diff --git a/lib/core/collection.js b/lib/core/collection.js index 70bdd60..9fb541c 100644 --- a/lib/core/collection.js +++ b/lib/core/collection.js @@ -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; @@ -225,7 +225,7 @@ class Collection extends EventEmitter { return res(); } - data = Bison.decode(data); + data = Fns.decode(data); let json; diff --git a/lib/core/db.js b/lib/core/db.js index fb7f5d8..011d56d 100644 --- a/lib/core/db.js +++ b/lib/core/db.js @@ -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 ); diff --git a/lib/core/writer.js b/lib/core/writer.js index 1cd9d76..8b8a662 100644 --- a/lib/core/writer.js +++ b/lib/core/writer.js @@ -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"); @@ -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) { diff --git a/package.json b/package.json index 5ce573c..04ae5bd 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "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", @@ -13,7 +13,7 @@ }, "keywords": [], "author": "Bolorunduro Valiant-Joshua", - "license": "ISC", + "license": "BSD 3-Clause", "bugs": { "url": "https://github.com/bolorundurovj/akivaDB/issues" }, diff --git a/repl/index.js b/repl/index.js new file mode 100644 index 0000000..cefde6a --- /dev/null +++ b/repl/index.js @@ -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); +} \ No newline at end of file diff --git a/tests/test.js b/tests/test.js index 6036820..19c2cbd 100644 --- a/tests/test.js +++ b/tests/test.js @@ -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);