Giter Site home page Giter Site logo

hbenormous / simpl.db Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 5antos/simpl.db

0.0 0.0 0.0 518 KB

A lightweight, 0 dependency, easy-to-use local database using JSON to store data

Home Page: https://simpldb.js.org

License: MIT License

Shell 0.12% JavaScript 99.88%

simpl.db's Introduction

Simpl.DB

Version Downloads Dependencies Quality



A lightweight, 0 dependency, easy-to-use local database using JSON to store data.

Installation

npm install simpl.db
yarn add simpl.db
pnpm add simpl.db

Example Usage

Database

const SimplDB = require('simpl.db');
const db = new SimplDB();


db.set('money', 100);
db.set('person.name', 'Peter');


db.has('money'); // true
db.has('person.name'); // true
db.has('person.age'); // false


db.get('person.name'); // 'Peter'
db.get('person.job'); // undefined


db.toJSON(); // { money: 100, person: { name: 'Peter' } }

Collections

const SimplDB = require('simpl.db');
const db = new SimplDB();

const Users = db.createCollection('users');


Users.create({ name: 'Peter', age: 19 });
Users.create({ name: 'John', age: 19 });


Users.update(
  user => user.age = 20,
  target => target.name === 'Peter'
);
// or ([email protected]+)
const user = Users.get(target => target.name === 'Peter');
user.age = 20;
user.save();


Users.get(user => user.name === 'Peter'); // { name: 'Peter', age: 20 }
Users.getMany(user => user.age > 18); // [{ name: 'Peter', age: 20 }, { name: 'John', age: 19 }]

With TypeScript:

import { Database, Modifiable } from 'simpl.db';
const db = new Database();

type User = {
  name: string
  age: number
}

const Users = db.createCollection<User>('users');


Users.create({ name: 'Peter', age: 19 });
Users.create({ name: 'John', age: 19 });


Users.update(
  user => user.age = 20,
  target => target.name === 'Peter'
);
// or ([email protected]+)
const user = <Modifiable<User>> Users.get(target => target.name === 'Peter');
user.age = 20;
user.save();


Users.get(user => user.name === 'Peter'); // { name: 'Peter', age: 20 }
Users.getMany(user => user.age > 18); // [{ name: 'Peter', age: 20 }, { name: 'John', age: 19 }]

Contributing

Before creating an issue, please ensure that it hasn't already been reported or suggested.

When submitting a new pull request, please make sure the code style/format used is the same as the one used in the original code.

License

Refer to the LICENSE file.

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.