firestorm-db
Advanced tools
Comparing version 1.1.0 to 1.2.0
71
index.js
@@ -121,2 +121,32 @@ const { default: axios } = require("axios") | ||
/** | ||
* Search specific keys through collection | ||
* @param {String[]|Number[]} keys Wanted keys | ||
* @returns {Promise<T[]>} Search results | ||
*/ | ||
searchKeys(keys) { | ||
if(!Array.isArray(keys)) | ||
return Promise.reject('Incorrect keys') | ||
return new Promise((resolve, reject) => { | ||
this.__extract_data(axios.get(readAddress(), { | ||
data: { | ||
"collection": this.collectionName, | ||
"command": "searchKeys", | ||
"search": keys | ||
} | ||
})).then(res => { | ||
const arr = [] | ||
Object.keys(res).forEach(contribID => { | ||
const tmp = res[contribID] | ||
tmp[ID_FIELD_NAME] = contribID | ||
arr.push(tmp) | ||
}) | ||
resolve(this.__add_methods(Promise.resolve(arr))) | ||
}).catch(err => reject(err)) | ||
}) | ||
} | ||
/** | ||
* Returns the whole content of the file | ||
@@ -126,14 +156,19 @@ * @returns {Promise} // the get promise of the collection raw file content | ||
read_raw() { | ||
let data = this.__extract_data(axios.get(readAddress(), { | ||
data: { | ||
"collection": this.collectionName, | ||
"command": "read_raw" | ||
} | ||
})) | ||
return new Promise((resolve, reject) => { | ||
this.__extract_data(axios.get(readAddress(), { | ||
data: { | ||
"collection": this.collectionName, | ||
"command": "read_raw" | ||
} | ||
})) | ||
.then(data => { | ||
Object.keys(data).forEach(key => { | ||
data[key][ID_FIELD_NAME] = key | ||
this.addMethods(data[key]) | ||
}) | ||
Object.keys(data).forEach(key => { | ||
this.addMethods(data[key]) | ||
resolve(data) | ||
}) | ||
.catch(reject) | ||
}) | ||
return data | ||
} | ||
@@ -153,2 +188,10 @@ | ||
} | ||
if(multiple) { | ||
value.forEach(v => { | ||
delete v[ID_FIELD_NAME] | ||
}) | ||
} else { | ||
delete value[ID_FIELD_NAME] | ||
} | ||
if(value) { | ||
@@ -188,3 +231,9 @@ if(multiple) | ||
addBulk(values) { | ||
return this.__extract_data(axios.post(writeAddress(), this.__write_data('addBulk', values, true))) | ||
return new Promise((resolve, reject) => { | ||
this.__extract_data(axios.post(writeAddress(), this.__write_data('addBulk', values, true))) | ||
.then(res => { | ||
resolve(res.ids) | ||
}) | ||
.catch(reject) | ||
}) | ||
} | ||
@@ -191,0 +240,0 @@ |
{ | ||
"name": "firestorm-db", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Self hosted Firestore-like database with API endpoints based on micro bulk operations", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
16128
275