Last active
November 5, 2016 13:14
-
-
Save nielsvanvelzen/e76536d375783d818990a4409f07fa75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Benchmark results:
the remove function is pretty slow