Comparing version 1.1.0 to 1.3.0
21
index.js
@@ -15,3 +15,3 @@ const fs = require('fs'); | ||
// get the project dir path | ||
// get the ldb dir path | ||
ldb.dir = __dirname; | ||
@@ -114,3 +114,22 @@ | ||
} | ||
// backup of file data | ||
ldb.backup = (path, db, file, callback)=>{ | ||
s.writeFile(`${path}/${db}/${file}.backup.ldb`, '', (err)=>{ | ||
if(err) throw err; | ||
fs.copyFile(`${path}/${db}/${file}.ldb`, `${path}/${db}/${file}.backup.ldb`, (err)=>{ | ||
if(err) throw err; | ||
if(callback) callback(); | ||
}); | ||
} | ||
} | ||
// rollback backup to file | ||
ldb.rollback = (path, db, file, callback)=>{ | ||
fs.copyFile(`${path}/${db}/${file}.backup.ldb`, `${path}/${db}/${file}.ldb`, (err)=>{ | ||
if(err) throw err; | ||
if(callback) callback(); | ||
}); | ||
} | ||
module.exports = ldb; |
23
json.js
@@ -14,3 +14,3 @@ // json module | ||
} | ||
// parse a JS obj to JSON string notation and send | ||
json.sendData = (path, db, file, jsObj, callback)=>{ | ||
@@ -23,3 +23,3 @@ fs.writeFile(`${path}/${db}/${file}.json`, JSON.stringify(jsObj), (err)=>{ | ||
} | ||
// parse a JSON to JS obj and get data | ||
json.getData = (path, db, file, callback)=>{ | ||
@@ -32,3 +32,22 @@ fs.readFile(`${path}/${db}/${file}.json`, (err, data)=>{ | ||
} | ||
// backup of file data | ||
json.backup = (path, db, file, callback)=>{ | ||
fs.writeFile(`${path}/${db}/${file}.backup.json`, '', (err)=>{ | ||
if(err) throw err; | ||
fs.copyFile(`${path}/${db}/${file}.json`, `${path}/${db}/${file}.backup.json`, (err)=>{ | ||
if(err) throw err; | ||
if(callback) callback(); | ||
}); | ||
} | ||
} | ||
// rollback backup to file | ||
json.rollback = (path, db, file, callback)=>{ | ||
fs.copyFile(`${path}/${db}/${file}.backup.json`, `${path}/${db}/${file}.json`, (err)=>{ | ||
if(err) throw err; | ||
if(callback) callback(); | ||
}); | ||
} | ||
module.exports = json; |
{ | ||
"name": "ldbjs", | ||
"version": "1.1.0", | ||
"version": "1.3.0", | ||
"description": "Create and manage local db files and data", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -206,2 +206,18 @@ # ldbjs | ||
### Backup and rollback | ||
```javascript | ||
const ldb = require('ldbjs'); | ||
ldb.backup('.', 'dbName', 'fileName'); | ||
// create a fileName.backup.ldb file | ||
ldb.roolback('.', 'dbName', 'fileName'); | ||
// get the fileName.backup.ldb data and put in fileName.ldb | ||
// To use in json is very similar, put the json module | ||
ldb.json.backup('.', 'dbName', 'fileName'); | ||
// use the same logic | ||
``` | ||
#### To report bugs or open a inssue in [github repo](https://github.com/raisses/ldbjs) or send a email to **danilosantana456789@gmail.com** no spam pls. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11735
161
222