An amazing, simple and fun database for humans
- Coding is fun, so databases must be fun too.
- Data is the king.
- Data should be stored in the system as a file when a change happend.
- Data storage in the system must be hackable.
- The database can lead or connect your server components.
- Events are great... because we are asynchronous.
- We prefer facts over promises: facts are there, promises maybe yes or not. In fact, we're talking about callbacks.
- Data is not the only stuff that can be store in a database.
- We prefer ambush functions over lambda functions. As you know... we're talking about anonymous functions.
You can run a demo in 4 steps!
- Clone this repository
git clone https://github.com/UlisesGascon/GoblinDB
- Enter in the folder
cd GoblinDB
- Install the dependencies
npm install
- Run fear_the_goblin.js
node fear_the_goblin.js
Add it to your Node.js project
- In your terminal...
npm install goblindb --save
- In your file..
var GDB = require("goblindb");
var goblinDB = GDB();
Reitrieving data
By default Goblin will create an empty json file as database storage, if the file exist it will added to Goblin.
Just for the example, current database status... as you can see is a JSON file:
- goblin_bd.json:
{"hello":"world!","array":["aaaa",true,5],"objectData":{"property": 1}}
- get. Return the information from a key or the whole database
var GDB = require("goblindb");
var goblinDB = GDB();
console.log(goblinDB.get())
// {"hello":"world!","array":["aaaa",true,5],"objectData":{"property": 1}}
console.log(goblinDB.get("hello"))
// {"hello":"world!"}
Saving data
You have many options to save data. As Goblin is a key/value database you need to know what is the key that you want to use/create.
You can storage all the data that you want except functions. Until the next release.
- set(key, data). Write or replace data to a defined key (optional)
var GDB = require("goblindb");
var goblinDB = GDB();
// set data in db.admin
goblinDB.set({"name": "Ulises", "role": "developer"}, "admin");
// set data in root
goblinDB.set({"hello": "Human...!"});
- push(data). Write data in a new key (random name added)
var GDB = require("goblindb");
var goblinDB = GDB();
goblinDB.push({"name": "Ulises", "role": "developer"})
- update(data, key). Add and modify data to a defined key
var GDB = require("goblindb");
var goblinDB = GDB();
goblinDB.update({"name": "CodingCarlos", "friends": ["Ulises", "Jose"]}, "admin");
Fun with Events You can use events in order to react to changes in the database. All the events are managed internally by Goblin inside as hooks.
You can specify the trigger event:
- add
- update
- delete
- reconfigure
- change, in any case it will be triggered.
The event will return an object that contains previous data and current data. At the moment the the listeners can be added to the database root, but in the next release it will possible to focus in on or more specific paths
- on(), Add a new function to be triggered on a specific change.
var GDB = require("goblindb");
var http = require("http");
var goblinDB = GDB();
goblinDB.on('change', function(changes){
console.log("cambio:", changes)
console.log("====================")
});
- off(), Remove a previous record event
var GDB = require("goblindb");
var http = require("http");
var goblinDB = GDB();
goblinDB.on('change', function(changes){
console.log("cambio:", changes)
console.log("====================")
});
// more code...
goblinDB.off('change', function(changes){
console.log("cambio:", changes)
console.log("====================")
});
Extra features Some extra features that maybe can help you.
- getConfig() & updateConfig, modify/replace/extend configuration.
var GDB = require("goblindb");
var http = require("http");
var goblinDB = GDB();
console.log(goblinDB.getConfig())
// { logPrefix: '[GoblinDB]', file: './goblin_bd.json', recordChanges: true }
goblinDB.updateConfig({ logPrefix: '[GoblinDB-modify]'})
console.log(goblinDB.getConfig())
// { logPrefix: '[GoblinDB-modify]', file: './goblin_bd.json', recordChanges: true }
- stopStorage() & startStorage(). enable/disable the storage in disk.
var GDB = require("goblindb");
var http = require("http");
var goblinDB = GDB();
goblinDB.stopStorage();
// more code that will not touch be stored in the disk...
goblinDB.startStorage();
// Now the current GoblinDB will be stored in disk and it will keep doing it
You can test your changes...
npm test
- Logo, branding...
- Landing Page.
- Support multidimensional navigation in the database (.ref() method).
- Support to chain methods.
- Add basic query methods.
- Add Avance query methods.
- Add support to .once() method for events.
- Add support to UID in events.
- Support .goblin extension for database in order to record raw database with objects, functions...
- Support .json compatibility for database.
- Additional events to support (config changes, etc...).
- Add additional support to Backup goblin with other databases like Firebase, Mongo... in real time.
- Full documentation in JSDoc.
- Gulp Tasks Improves.
- Example Folder.
- Test support for Events using Sinon.
- Test refactor in order to separate more the test cases.
Main target:
- Ambush support
Bugs Fixed:
- No need to require http module, in documentation examples
Features:
- Database testing improved
- Added optional features like parameters and callbacks for Ambush (lambda) functions
- Added automatic save for Ambush
- Added .goblin extension in order to store ambush operations
- Added Testing to support ambush features
- Added goblin.ambush as container
- Added goblin.ambush.add(),
- Added goblin.ambush.remove(),
- Added goblin.ambush.update(),
- Added goblin.ambush.list(),
- Added goblin.ambush.details(),
- Added goblin.ambush.run()
- Readme improved
Features:
- Documentation improved
Bugs Fixed
Notes: Just to solve issues with NPM.
Main target:
- Develop the basics key functionalities (methods)
- Key/Value operative database
- Event support
- Database recorded as file
- Minimum config setup
Features:
- Added support to JSDoc
- Added Gulp Tasks
- Added Basic Testing with Mocha, Chai and Istanbul
- Added .editorconfig
- Added esLint support
- Roadmap added
- Added File structure
- Added minimal validation
- Added basic documentation
- Added GoblinDB as Module
- Added GoglinDB Helpers as an independente module
- Added support to store the data on demand as JSON
- Added full support to events
- Added support to key changes in events
- Added Method on
- Added Method off
- Added Method getConfig
- Added Method setConfig
- Added Method stopStorage
- Added Method startStorage
- Added Method get
- Added Method push
- Added Method set
- Added Method update
Features:
Notes: Just a "Hello world"