UNPKG

dbd.db

Version:

A Lightweight Schema-Free Object-Oriented LocalDatabase for Development and Production Purpose

112 lines (92 loc) 3.9 kB
# DBD.DB [![Discord Server](https://img.shields.io/discord/773352845738115102?color=7289da&logo=discord&logoColor=white)](https://dbd.js.org/invite) [![NPM Version](https://img.shields.io/npm/v/dbd.db.svg?maxAge=3600)](https://www.npmjs.com/package/dbd.db) [![NPM Downloads](https://img.shields.io/npm/dt/dbd.db.svg?maxAge=3600)](https://www.npmjs.com/package/dbd.db) [![NPM Info](https://nodei.co/npm/dbd.db.png?downloads=true&stars=true)](https://nodei.co/npm/dbd.db) ## Table Of Contents - [About](#about) - [Examples](#about) - [Setup](#setup) - [Creating Collection](#creating-a-collection) - [Interact Collection](#interacting-with-the-collection) - [Methods](#methods) - [Core](#core) - [Database](#database) - [Collection](#collection) - [Links](#links) - [Special Thanks](#special-thanks-that-made-this-possible) ## About Lightweight Schema-Free Object-Oriented LocalDatabase for Development and Production Purpose A Object Oriented and Indexs Based Database. <br> Fast, secure, and easy to use. </br> ## Examples ### Setup ```js const BaseDB = require('dbd.db') const DB = BaseDB('database') const Collection = DB.collection({ name: "Collection", ttl: 5 //optional }) ;(async () => { await Collection.set({ myName: "Matthew", myHome: "USA" }, { myName: "Matthew" }) console.log(await Collection.find({ myName: "Matthew" })) //returns [{ myName: "Matthew", myHome: "USA" }] })() ``` ### Creating a Collection ```js const Collection = DB.collection({ name: "Collection", ttl: 60 //ttl (Time to Live) in seconds }) //Interaction with Collection ``` ### Interacting with the Collection ```js await Collection.set({ myName:"Matthew" }) const data = await Collection.findOne({ myName:"Matthew" }) console.log(data) //returns { myName:"Matthew" } ``` ## Methods ### Core - Core(name) - The constructor of Database - Core.deprecated(db, collection) - Transfer old chson into new bison encrypted - Core.version - Return current version of dbd.db ### 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.set(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 ## Links DBD.DB was made by [DBD.JS Team](https://discord.gg/HMUfMXDQsV) - [Website](https://dbd.js.org) - [Discord Server](https://dbd.js.org/invite) - [DBD.JS](https://www.npmjs.com/package/dbd.js) - [DBD.DB](https://www.npmjs.com/package/dbd.db) ## Special Thanks that made this possible - Leref - The developer of [dbd.js](https://npmjs.com/package/dbd.js) - Xzusfin - Helping maintain the db - Kino - Helping at development