GET STARTED WITH THE MERLINDB
  • Making it easier
  • to store data in the browser.

    Introduction

    MerlinDB
  • is a database based on IndexedDB, a web browser storage API that allows developers to create complex applications that can store large amounts of data. Unlike local storage and cookies, IndexedDB stores data in a structured way, allowing for advanced queries and transactions. It supports storage of different types of data, including binary files, and works asynchronously, ensuring that read and write operations do not block the user interface. With IndexedDB, you can create web applications that work offline and offer robust performance, similar to traditional databases.



    Knowing this, I decided to create an efficient and familiar way for developers working with MongoDB and Mongoose. Getting to grips with IndexedDB can sometimes seem challenging and tiring, so this tool is a way to bring your MongoDB skills to IndexedDB. Have fun with the process and mahalo!

    Getting started

    Working with MerlinDB is as simple as taking candy from a child, by the way, never take candy from a child!!!. Besides, why would you do that? 🍭.

    1*: Download the merlindb.min.js right here or:
    2 (script)*: Insert the script into your project, like this:
    1
  • //Call the script preferably in the (head) tag of your project.
  • 2<script
  • src=
  • "merlindb.min.js"></script>
  • //42,7 kB
  • 2 (npm)*: Or try npm:
    1
  • npm
  • install
  • @chrisaxxwell/merlin-db;
    2
  • import
  • MerlinDB,
  • {
  • Schema
  • }
  • from
  • "@chrisaxxwell/merlin-db";
    3*: Call the new MerlinDB():
    1
  • const
  • merlin =
  • new
  • MerlinDB(
  • )
  • ;
    4*: Connect to database:
    1merlin
  • .connect(
  • <YOUR-DATABASE-NAME>
  • )
  • ;
    5*: Create an Schema:
    1
  • var
  • usersSchema =
  • Schema(
  • {
  • 2  
  • email:
  • {
  • 3      
  • type:
  • String
  • ,
    4      
  • unique:
  • true
  • 5  
  • }
  • ,
    6  
  • name:
  • {
  • type:
  • [
  • String
  • ],
  • required:
  • true
  • }
  • ,
    7  
  • age:
  • [
  • Number
  • ,
  • String
  • ],
    8  
  • city:
  • String
  • ,
    9
  • }
  • )
  • ;
    6*: Initialize your new model:
    1
  • const
  • Users = merlin
  • .model(
  • 'Users', usersSchema
  • )
  • ;
    7*: CRUD (Insert, Update and Remove):
    1
  • //Insert
  • 2Users
  • .insert(
  • {
  • name:
  • "Chris",
  • age:
  • 27
  • }
  • )
  • .then(
  • e => console
  • .log(
  • e
  • )
  • )
  • ;
    3
    4
  • //Find
  • 5Users
  • .find(
  • {
  • age:
  • 27
  • }
  • )
  • .then(
  • e => console
  • .log(
  • e
  • )
  • )
  • ;
    6
    7
  • //Update
  • 8Users
  • .updateOne(
  • {
  • 9  
  • //Every name = Sophie
  • 10  
  • name:
  • {
  • $regex:
  • ["Sophie", "i"]
  • }
  • }
  • ,
    11  
  • {
  • $set:
  • {
  • name:
  • "Lady Sophie"
  • }
  • 12
  • }
  • )
  • ;
    13
    14
  • //Delete
  • 15Users
  • .deleteOne(
  • {
  • name:
  • "Chris"
  • }
  • )
  • .then(
  • e => console
  • .log(
  • e
  • )
  • )
  • ;

    Congratulations

    You have completed our quickstart, we have started our database, created a schema for validations and commits, started our model, inserted, updated, found and removed data, for our complete guide go guides. See our documentation on github if you want GuitHub Docs.