informa-db.js
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -20,4 +20,5 @@ module.exports = { | ||
"no-param-reassign": "off", | ||
"global-require": "off", | ||
"no-underscore-dangle": "off", | ||
}, | ||
}; |
21
index.js
const fs = require('fs'); | ||
let mongo; | ||
let MongoClient; | ||
let mongo; | ||
try { | ||
mongo = require('mongodb'); | ||
MongoClient = mongo.MongoClient; | ||
} catch (err) { | ||
mongo = null; | ||
MongoClient = null; | ||
} | ||
class Db { | ||
@@ -39,4 +46,5 @@ constructor(file, defaultStr, isMongo, db, collection) { | ||
if (dis.isMongo) { | ||
mongo = (await import('mongodb')).default; | ||
MongoClient = mongo.MongoClient; | ||
if (!mongo) { | ||
throw new Error('Mongodb is not installed. Please install it.'); | ||
} | ||
dis.client = await MongoClient.connect(file, { | ||
@@ -78,6 +86,5 @@ useNewUrlParser: true, | ||
process.on('exit', dis.client.close); | ||
// dis.value = dis.genProxy(dis.readOnlyValue); | ||
} else { | ||
if (!fs.existsSync(file)) { | ||
fs.writeFileSync(file, defaultStr ?? '{}', (err) => { | ||
fs.writeFileSync(file, defaultStr || '{}', (err) => { | ||
if (err) { | ||
@@ -89,3 +96,2 @@ throw err; | ||
dis.readOnlyValue = JSON.parse(fs.readFileSync(file, 'utf8')); | ||
// dis.value = dis.genProxy(dis.readOnlyValue); | ||
} | ||
@@ -119,3 +125,2 @@ dis.saveOnChange = true; | ||
).map((val) => { const v = val; delete v._id; return v; }); | ||
// this.value = this.genProxy(this.readOnlyValue); | ||
return this.readOnlyValue; | ||
@@ -163,3 +168,1 @@ } | ||
module.exports = Db; | ||
// Hey u still here? | ||
// |
{ | ||
"name": "informa-db.js", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "DataBases made easier", | ||
@@ -10,2 +10,4 @@ "main": "index.js", | ||
"devDependencies": { | ||
"mongodb": "^3.5.8", | ||
"dotenv": "^8.2.0", | ||
"eslint": "^6.8.0", | ||
@@ -18,6 +20,3 @@ "eslint-config-airbnb": "^18.1.0", | ||
"eslint-plugin-react-hooks": "^2.5.0" | ||
}, | ||
"dependencies": { | ||
"mongodb": "^3.5.8" | ||
} | ||
} |
@@ -54,3 +54,3 @@ # Informa-Db.js | ||
Collection name, defaulting to "db" | ||
### Db function and properties | ||
### Db class | ||
#### Db.readOnlyValue<Any> | ||
@@ -57,0 +57,0 @@ File/collection content |
@@ -0,1 +1,2 @@ | ||
require('dotenv').config(); | ||
const Db = require('./index.js'); | ||
@@ -6,5 +7,5 @@ | ||
// const ee = test.value.length; | ||
// test.value = []; | ||
test.value[test.value.length] = { ee: 'eeeeee' }; | ||
test.value = []; | ||
test.value.push({ ee: 'eeeeee' }); | ||
console.log(test.value); | ||
})(); |
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
8707
0
6
186
9
- Removedmongodb@^3.5.8
- Removedbl@2.2.1(transitive)
- Removedbson@1.1.6(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddenque@1.5.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedmemory-pager@1.5.0(transitive)
- Removedmongodb@3.7.4(transitive)
- Removedoptional-require@1.1.8(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedrequire-at@1.0.6(transitive)
- Removedsafe-buffer@5.1.25.2.1(transitive)
- Removedsaslprep@1.0.3(transitive)
- Removedsparse-bitfield@3.0.3(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)