JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q31502F
  • License MIT

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

Package Exports

  • dev.db
  • dev.db/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dev.db) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

VirusDB

Version Downloads Dependencies Quality



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

Installation

npm install dev.db
yarn add dev.db
pnpm add dev.db

Example Usage

Database

const VirusDB = require('dev.db');
const db = new VirusDB();


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


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


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


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

Collections

const dbConfig =  {
  autoSave: false,
  encryptionKey: 'qwertyuiopasdfghjkpzxxcvbnm',
  dataFile: 'database/dev.db.json',
  collectionsFolder: 'database/collections'
}
const VirusDB = require('dev.db');
const db = new VirusDB(dbConfig);

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


Users.create({ name: 'virus', age: 19 });
Users.create({ name: 'virus24', age: 19 });


Users.update(
  user => user.age = 20,
  target => target.name === 'virus'
);
// or (dev.db@0.0.2+)
const user = Users.get(target => target.name === 'virus');
user.age = 20;
user.save();


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

With TypeScript:

import { Database, Modifiable } from 'dev.db';
const dbConfig =  {
  autoSave: false,
  encryptionKey: 'qwertyuiopasdfghjkpzxxcvbnm',
  dataFile: 'database/dev.db.json',
  collectionsFolder: 'database/collections'
}

const db = new Database(dbConfig);

type User = {
  name: string
  age: number
}

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


Users.create({ name: 'virus', age: 19 });
Users.create({ name: 'virus24', age: 19 });


Users.update(
  user => user.age = 20,
  target => target.name === 'virus'
);
// or (dev.db@0.0.2+)
const user = <Modifiable<User>> Users.get(target => target.name === 'virus');
user.age = 20;
user.save();


Users.get(user => user.name === 'virus'); // { name: 'virus', age: 20 }
Users.getMany(user => user.age > 18); // [{ name: 'virus', age: 20 }, { name: 'virus24', 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.