All Projects → Drylozu → MeowDB.js

Drylozu / MeowDB.js

Licence: MIT license
Database in JSON (Node.JS Library)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to MeowDB.js

gof
Yet another simple Go filesystem wrapper
Stars: ✭ 13 (+8.33%)
Mutual labels:  wrapper, filesystem, fs
sandboxed-fs
Sandboxed Wrapper for Node.js File System API
Stars: ✭ 41 (+241.67%)
Mutual labels:  wrapper, filesystem, fs
Zbox
Zero-details, privacy-focused in-app file system.
Stars: ✭ 1,185 (+9775%)
Mutual labels:  storage, filesystem, fs
stoor
Storage wrapper with support for namespacing, timeouts and multi get/set and remove.
Stars: ✭ 26 (+116.67%)
Mutual labels:  wrapper, storage
TLightFileStream
Implements a lightweight, high-performance, non-allocating advanced-record-based wrapper around the SysUtils file handling routines as an alternative to Classes.TFileStream.
Stars: ✭ 21 (+75%)
Mutual labels:  wrapper, filesystem
SharpPhysFS
Managed wrapper for the PhysFS library
Stars: ✭ 14 (+16.67%)
Mutual labels:  wrapper, filesystem
Autarky
Liberating disk space from 📁 node_modules
Stars: ✭ 203 (+1591.67%)
Mutual labels:  storage, filesystem
dropbox-fs
📦 Node FS wrapper for Dropbox
Stars: ✭ 35 (+191.67%)
Mutual labels:  filesystem, fs
Rxfirebase
Rxjava 2.0 wrapper on Google's Android Firebase library.
Stars: ✭ 509 (+4141.67%)
Mutual labels:  wrapper, storage
fs-fuse
Export any Node.js `fs`-like object as a FUSE filesystem
Stars: ✭ 32 (+166.67%)
Mutual labels:  filesystem, fs
tabfs-specs
Specifications for the tabfs filesystem (osdev) | Mirror of https://codeark.it/Chalk-OS/tabfs-specs
Stars: ✭ 15 (+25%)
Mutual labels:  filesystem, fs
gw
A Wrapper of a command to watch any changes in filesystem
Stars: ✭ 16 (+33.33%)
Mutual labels:  wrapper, filesystem
fu
Unix's Find, Unleashed.
Stars: ✭ 32 (+166.67%)
Mutual labels:  filesystem, fs
Jsstore
A complete IndexedDB wrapper with SQL like syntax.
Stars: ✭ 430 (+3483.33%)
Mutual labels:  wrapper, storage
Go Fastdfs
go-fastdfs 是一个简单的分布式文件系统(私有云存储),具有无中心、高性能,高可靠,免维护等优点,支持断点续传,分块上传,小文件合并,自动同步,自动修复。Go-fastdfs is a simple distributed file system (private cloud storage), with no center, high performance, high reliability, maintenance free and other advantages, support breakpoint continuation, block upload, small file merge, automatic synchronization, automatic r…
Stars: ✭ 2,923 (+24258.33%)
Mutual labels:  storage, filesystem
Bus
Bus 是一个基础框架、服务套件,它基于Java8编写,参考、借鉴了大量已有框架、组件的设计,可以作为后端服务的开发基础中间件。代码简洁,架构清晰,非常适合学习使用。
Stars: ✭ 253 (+2008.33%)
Mutual labels:  wrapper, storage
unionfs
Use multiple fs modules at once
Stars: ✭ 170 (+1316.67%)
Mutual labels:  filesystem, fs
Sharesniffer
Network share sniffer and auto-mounter for crawling remote file systems
Stars: ✭ 168 (+1300%)
Mutual labels:  storage, filesystem
Tus Ruby Server
Ruby server for tus resumable upload protocol
Stars: ✭ 172 (+1333.33%)
Mutual labels:  storage, filesystem
rxnode
Rxnode - a small and fast wrapper around the nodejs API using RxJS.
Stars: ✭ 24 (+100%)
Mutual labels:  filesystem, fs

MeowDB.js

MeowDB

Downloads Minified Size Vulnerabilities License Last Commit GitHub Repo stars

NPM

"Database" in JSON (Node.JS Library).

Released v2.2.3. See CHANGELOG.

Installation

  • npm install meowdb --save.

I recommend not using versions lower than 2.1.9 or being aware of updates to the library.

Usage

JavaScript - CommonJS require

const MeowDB = require("meowdb");

const myDatabase = new MeowDB({
    dir: __dirname,
    name: "database",
    raw: false // Defines if MeowDBObjects will be returned (optional, default: false)
});

TypeScript - ES6 import

With TypeScript you should've the esModuleInterop flag.

import MeowDB from "meowdb";
// The generic type is optional, by default it's "full" but when using the raw option, use "raw" instead of "full"
const myDatabase = new MeowDB<'full'>({
    dir: __dirname,
    name: "database",
    raw: false // Defines if MeowDBObjects will be returned (optional, default: false)
});

Example of all functions

// Creating object (it'll search property by property and if it doesn't exist, it'll create it otherwise it'll not modify the current information~)
// * where the first parameter is the ID, they're like properties of an object (same thing in most functions)
const newObject = myDatabase.create("0001", {
    name: "David",
    country: "CO",
    info: "Nothing to show"
});
console.log(newObject);

// Obtaining an object
const object = myDatabase.get("0001");
console.log(object);

// Modifying an object and saving it
object.name = "Deivid";
object.save();
console.log(object.name);

// Setting directly the value of an element
const newName = myDatabase.set("0001.info", "Just a person");
console.log(newName);

// Listing all objects
let temp = "";
Object.entries(myDatabase.all()).forEach((user) => {
    temp += `   - ${user[1].name} (ID: ${user[0]})\n`;
});
console.log(temp.trimRight());

// Finding an object
const anObject = myDatabase.find((user) => user.name === "Deivid");
console.log(anObject);

// Filtering objects
const someObjects = myDatabase.filter((user) => user.country === "CO");
console.log(someObjects);

// Deleting an object
const deletedObject = myDatabase.delete("0001");
console.log(deletedObject);

Important note while using TypeScript

You can use TypeScript Generics to create/get/update/set/find/filter the data, it doesn't matter what type you use.

const nonObjectValue = myDatabase.get<string>('0002.name');
console.log(nonObjectValue); // TS will interpret it as string

const numberValue = myDatabase.get<number>('some id here');
console.log(numberValue); // TS will interpret it as a number

const booleanValue = myDatabase.get<boolean>('some id here');
console.log(booleanValue); // TS will interpret it as a boolean

// With Objects/also works with interfaces
type Person = {
    name: string;
    country: string;
    info: string;
};

const objectValue = myDatabase.get<Person>('0002'); // This will return a MeowDBObject with the properties that you specified in the generic type
console.log(objectValue.name); // While typing '.name', you'll get *autocomplete*
// It also works when you save an MeowDBObject
objectValue.info = 'Hi!';

/// Important: Read the note in the Usage/TypeScript section.
objectValue.save(); // This will return a plain 'Person' object.

"Documentation"

  • new MeowDB(options)
    • create(id, initialValue)
    • exists(id)
    • get(id)
    • set(id, value)
    • all()
    • delete(id)
    • find(callback, id?)
    • filter(callback, id?)
  • MeowDBError

new MeowDB(options)

Creates or gets a database

  • Parameters:
    • options - An object with the options
      • options.dir - A string indicating the directory that will have the database (must be an absolute path - the folder should be created)
      • options.name - A string with the name of the database
      • options.raw? - A boolean that represents if MeowDBObjects won't returned (default: false, MeowDBObjects will be returned).
  • Throws: MeowDBError - If any option is invalid

Methods

all()

Returns all data stored in the database

  • Returns: MeowDBObject | object - All data

create(id, initialValue)

Creates an element in the database with the specified ID and sets it's value

  • Parameters:
    • id - A string representing the ID of the element to create
    • initialValue - The initial value of the element
  • Returns: object - The created element
  • Throws: MeowDBError - If the ID or initialValue is invalid

delete(id)

Deletes an element from the database

  • Parameters:
    • id - A string representing the ID of the element to delete
  • Returns: object - The deleted element
  • Throws: MeowDBError - If the ID is invalid

exists(id)

Checks if an element exists in the database

  • Parameters:
    • id - A string representing the ID of the element to check
  • Returns: boolean - If it exists
  • Throws: MeowDBError - If the ID is invalid

get(id)

Gets an element of the database

  • Parameters:
    • id - A string representing the ID of the element to get
  • Returns: MeowDBObject | object | any - The element
  • Throws: MeowDBError - If the ID is invalid

set(id, value)

Sets the value of an element in the database

  • Parameters:
    • id - A string representing the ID of the element to update
    • value - The new value of the element
  • Returns: any - The value setted
  • Throws: MeowDBError - If the ID or value is invalid

find(callback, id?)

Finds an element in the database. You should only use this function if you're finding for objects

  • Parameters:
  • callback - A function that handles all the elements and decides which one will be returned
    • id? - A string representing the ID of the root element to find another elements (optional)
  • Returns: MeowDBObject | object | any - The element
  • Throws: MeowDBError - If the ID or callback is invalid

filter(callback, id?)

Filters elements in the database. You should only use this function if you're filtering for objects

  • Parameters:
    • callback - A function that handles all the elements and decides which ones will be returned
    • id? - A string representing the ID of the root element to find another elements (optional)
  • Returns: (MeowDBObject | object | [string, any])[] - The elements (MeowDBObject[] if they're objects, array with ID and value if not)
  • Throws: MeowDBError - If the ID or callback is invalid

MeowDBError

Extends Error, only used for error reference.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].