Giter Club home page Giter Club logo

cookiedb's Introduction

Cookie:cookie:DB

CookieDB is a database for the browser. It can store data as documents in collections like any noSQL database. It allows for very organized and structured data by using nothing other than javascript on the browser.

Setup

Simply include the cookiedb.js file into your project and link to it through script tags.

<script src="cookiedb.js"></script>

In your javascript file, create a new cookiedb database.

const db = new CookieDB()

Now, you can organize your data into collections and insert, update, find, and remove that data from your web application.

Documentation

Create Collection

CookieDB, much like all noSQL databases stores your data into collections for better organization. To begin using the features of CookieDB create a collection.

db.createCollection('books')

Insert

Store an object on the browser in a collection. This information will be available even after the user has closed their tab or browser. Call the insert function on the CookieDB object and pass the collection in which you want to store data, followed by object that you want to store. Let's populate our database books collection with books

db.insert('books', { title: 'The Great Gatsby', year: 1925, author: 'F. Scott Fitzgerald' })
db.insert('books', { title: 'Nineteen Eighty-Four', year: 1949, author: 'George Orwell' })
db.insert('books', { title: 'To Kill a Mockingbird', year: 1960, author: 'Harper Lee' })
db.insert('books', { title: 'Animal Farm', year: 1945, author: 'George Orwell' })

Update

Update a value that is pre-existing in the database, by passing the collection, the _id, and the values you want to update in the old value. The _id is just the unique identifier that represents the order in which the items were inserted. Let's update the two George Orwell books to reflect the authors real name which is Eric Blair. A multiple-update feature will be added soon.

/* Since we know the _id's of the George Orwell books
   are 1 and 3 we can update them directly. If you don't 
   know the _id's simply query for the object you are 
   looking for and obtain the _id. */
db.update('books', 1, { author: 'Eric Blair' })
db.update('books', 3, { author: 'Eric Blair' })

Find

Find the value of the data you are looking for in a collection by referencing a subset of its properties, passing an empty object will return all documents in the specified collection. The find function returns an array of all items in the database that match the query. The function can return an empty array or array of length 1. Let's query for The Great Gatsby book.

db.find('books' { title: 'The Great Gatsby' })
// returns [{_id: 0, title: 'The Great Gatsby', year: 1925, author: 'F. Scott Fitzgerald'}] 

Remove

Remove some value(s) that exists in the database by a subset of its properties. Let's remove all books published in 1960.

db.remove('books', { year: 1960 })
// removes to kill a mockingbird from the database

Count

Returns the number of items that are in the database. Since we have 4 books in our database, it will return 4.

db.count()
// returns 4

Drop

Deletes all the content of the database.

db.drop()

Features

  • Familiar database syntax
  • Ability to store javascript objects, unlike native localStorage which only supports strings.
  • Querying for an object by one or multiple known properties.
  • Each document is assigned its own unique _id similar to MongoDB.
  • Written completely in javascript and for front-end use.
  • Sped up search times and better organization due to collections

Todo

  • Ability to make collections and other ways of organizing data, to speed up search times.
  • Advanced querying options.
  • Functionality to perform multiple inserts, updates, and removes at once.
  • Feedback for operations such as error / success codes.

cookiedb's People

Contributors

maaslalaniii avatar

Stargazers

Vinicius Meneses avatar  avatar Paarth Madan avatar Darshil Patel avatar Jicking Bebiro avatar Ricardo Goldstein avatar Shehryar avatar Philip Curley avatar  avatar Tuğcan Karabörk avatar Misha Vyrtsev avatar Quang Liem avatar Alexander Zizzo avatar Tom Bazarnik avatar  avatar Fabio Albertin avatar Aaron Dancer 傅子威 avatar Karl Herrick avatar Darius avatar

Watchers

James Cloos avatar  avatar

Forkers

alfmoh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.