flatdriver
v1.0.1
Published
JSON Database with support for implementing schema's.
Downloads
6
Readme
FlatDriver - A Lazy Man's Database
JSON Database with support for schema's.
Easy to install:
npm install --save-dev flatdriver
Easy to import into your project:
import { FlatDriver } from 'flatdriver';
Already have a JSON file somewhere?
let flatDriver;
FlatDriver.attach('./myFile.json')
.then((fd)=>{
flatDriver = fd;
flatDriver.get()
.then((data)=>{
console.log('Data: ', data);
})
})
How about synchronously?
let flatDriver = FlatDriver.attachSync('./myFile.json');
flatDriver.get()
.then((data)=>{
console.log('Data: ', data);
})
Generate a schema with a blueprint:
If a JSON file does not exist, when supplied with a schema FlatDriver will generate one.
private flatDriver: FlatDriver;
private initFlatDriver(){
let path = './database.json';
let schema = {
Users: {
User: {
userName: '',
roles: [],
skyApps: []
}
},
SkyApps: {
SkyApp: {
name: '',
path: '',
roles: []
}
}
};
this.flatDriver = FlatDriver.attachSync(path, schema);
this.flatDriver.set('Users', '[email protected]', {
userName: '[email protected]',
roles: ['admin']
})
.then(()=>{
console.log('We did it, boys.');
})
}
The particulars:
Install:
npm install --save-dev flatdriver
Import:
import { FlatDriver } from 'flatdriver';
Initialize Asynchronously:
FlatDriver.attach(filePath, schema)
.then((fdInstance)=>{
// Returns in a promise
});
Initialize Synchronously:
let flatDriver = flatDriver.attachSync(filePath, schema);
flatDriver.get()
.then((data)=>{
// Gets all the data
});
Store Data:
flatDriver.set(collection, key, data)
.then(()=>{
// Returns a promise
});
Get Data:
Select and collection are optional.
Select currently only takes key
If you use get
without any arguments it will return the entire data set.
More things coming soon.
let select = {key: '[email protected]'};
flatDriver.get(collection, select)
.then((data)=>{
// Returns a promise
});
Delete an entry:
flatDriver.del(collection, key)
.then(()=>{
// Returns a promise when finished
});
Add a collection and schema on the fly:
let newSchema = {
NewCollection: {
New: {
another: [],
thing: ''
}
}
};
flatDriver.addCollection(newSchema)
.then(()=>{
// Returns a promise when finished
});