A database system
So, yeah, it's not complete yet, but it can support simple queries and has an API similar to
var db = ;dbcreateCollection"Books";var esums = dbcollection"Books";esumsinsert'DOC': 1'Principal':'Blue''Dean of Strapping':'Newlyn Joseph''IPs':5234 7432;esumsinsert'DOC': 2'Harry Potter':'JK Rowling''Swag':'Newlyn Joseph';esumsinsert'DOC': 3'Principal':'Blue''Dean of Strapping':'Newlyn Joseph''IPs':5234 7432;var queryresults = esumsfind'Principal':'Blue';console.log"Matching documents";console.logqueryresults;
##How To Install
If you're working on the client side, just include the script
higgle.js. This will provide you with the
Higgle object attached to the
On Node.js just require the module after installing it via NPM.
$ npm install higgle
// On Node.js you must require the module in order to use the Higgle objectvar Higgle = require'higgle';
###Creating a Database
Higgle is super simple. The
Higgle object represents your entire database. You can create an instance of one as follows:
var db = ; // It is common convention to name your database object 'db'
###Creating a Collection Within a database you can have one or more collections. Collections are a group of JSON documents. You can create a collection by calling the following method on your database object.
All you must specify as an argument is a string which will be the name of the collection. You can now grab a handle to the collection by calling the following method on your database object.
var people = dbcollection"People";
All you must specify as an argument is the name of the collection (the same name you used to create the collection). The variable
people is a collection object which you can utilize to modify your database.
Adding data is super simple. Just call the following method on the collection object and specify the JSON document you want to add to the collection.
peopleinsert'name': 'wiley''age': 35;peopleinsert'name': 'smith''age': 16;
The above code adds two JSON documents to the collection known as
Querying data is also super simple. Every query returns an array full of documents that matched the query. To perform a query call the following method on the collection object:
// This query will find all documents in the collection known as// 'people' that have the string 'wiley' paired with the key 'name'var queryresults = peoplefind'name':'wiley';// You can also query with multiple JSON keysvar queryresults = peoplefind'name':'wiley''age': 13;
queryresults object is an array with all the JSON documents that matched the query.
Say for example we want to know all the people who can legally drink. To perform such a query we would do the following:
// Find all documents where the key of 'age' has a value greater than 21var queryresults = peoplefind 'age': great21 ;
Similarly, if we want to find all the documents in which the key of
age has a value that is less than 21 we could perform the following query:
// Find all documents where the key of 'age' has a value less than 21var queryresults = peoplefind 'age': less21 ;
Similarly, if we want to find documents with a key of
age that takes on a certain range of values, we can do so:
// Find all documents where the key of 'age' has a value in between 6 and 24var queryresults = peoplefind 'age': range6 24 ;