Skip to content

PoloDB/polodb-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PoloDB Node.js Client

npm version

PoloDB is a lightweight JSON-based database.

Features

  • Simple and Lightweight
    • Only cost ~500kb memory to serve a database
    • The database server binary is less than 2Mb
    • Store data in one file
  • Easy to learn and use
    • NoSQL
    • MongoDB-like API
  • Various language bindings
  • Standalone Process
    • Process isolation
    • Asynchronous IO
  • Cross-Platform
    • Working on common OS

Install

Npm:

npm install --save polodb

Yarn:

yarn add polodb

Open a database

import { PoloDbClient } from 'polodb';

async function main() {
  const db = await PoloDbClient.createConnection('./test.db);
}

Remember to close the database.

db.dispose();

Create a Collection

Create a collection.

await db.createCollection('students');

Insert

Insert a document to the database.

const collection = db.collection('students');

await collection.insert({
    name: 'Vincent Chan',
    age: 14,
});

Find

Find documents in the database.

const collection = db.collection('students');

const result = await collection.find({
    name: 'Vincent Chan',
});

console.log(result);

Advanced Find

PoloDB supports complex find operation like MongoDB.

Example: find all items with age is greater than 18

const collection = db.collection('students');

const result = await collection.find({
    age: {
        $gt: 18,
    },
});

Update

Update documents in the database.

const collection = db.collection('students');

await collection.update({
    name: 'Vincent Chan',
}, {
    $inc: {
        age: 1,
    },
});

Delete

Delete documents by query.

const collection = db.collection('students');

await collection.delete({
    name: 'Vincent Chan',
});

Releases

No releases published

Packages

No packages published