PoloDB is a lightweight JSON-based database.
- 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
Npm:
npm install --save polodb
Yarn:
yarn add polodb
import { PoloDbClient } from 'polodb';
async function main() {
const db = await PoloDbClient.createConnection('./test.db);
}
Remember to close the database.
db.dispose();
Create a collection.
await db.createCollection('students');
Insert a document to the database.
const collection = db.collection('students');
await collection.insert({
name: 'Vincent Chan',
age: 14,
});
Find documents in the database.
const collection = db.collection('students');
const result = await collection.find({
name: 'Vincent Chan',
});
console.log(result);
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 documents in the database.
const collection = db.collection('students');
await collection.update({
name: 'Vincent Chan',
}, {
$inc: {
age: 1,
},
});
Delete documents by query.
const collection = db.collection('students');
await collection.delete({
name: 'Vincent Chan',
});