Skip to content

Instantly share code, notes, and snippets.

@nielsvanvelzen
Last active November 5, 2016 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nielsvanvelzen/e76536d375783d818990a4409f07fa75 to your computer and use it in GitHub Desktop.
Save nielsvanvelzen/e76536d375783d818990a4409f07fa75 to your computer and use it in GitHub Desktop.
'use strict';
const Database = require('../src/Database');
//let database = new Database(__dirname + '/example.db'); // Use file "example.db"
let database = new Database(null); // Use memory
database.define('user', {
id: {type: Number, index: true},
name: String,
});
// Insert into table "user" with values id & name
database.insert('user', {id: 1, name: 'Bob'});
database.insert('user', {id: 2, name: 'Henk'});
database.insert('user', {id: 3, name: 'Bob'});
// Get the first result for the table 'user' where the column `id` equals to 1
database.get('user', {id: 1}, user => {
console.log(`User 1 has the name: ${user.name}`);
});
// Find all results in table 'user' where the column `name` equals to 'Bob'
database.find('user', {name: 'Bob'}, users => {
console.log(`Amount of Bob's: ${users.length}`);
});
// Remove all all entries in the table 'user' where the column 'id' equals to 1
database.remove('user', {id: 1});
@nielsvanvelzen
Copy link
Author

Benchmark results:

insert-10k: 41.122ms
find-no-index: 3.519ms
find-index: 0.200ms
remove: 5434.659ms

the remove function is pretty slow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment