Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
8e7ad5210f | |||
cea6c662ac | |||
6eb43a4b9f | |||
7f89cbeecd | |||
a042a589a0 | |||
75b5f6af08 | |||
e6a36f22ac | |||
246e3486f0 | |||
c1c4a29415 | |||
6448516aa0 | |||
24a7b2dbd3 | |||
afa7c2fe61 | |||
b768896fbe | |||
8d7d9adef1 | |||
ca6d3c60c0 | |||
38c1fcd53a | |||
e433b9e212 | |||
bf3656f792 | |||
7e9fc62ce7 | |||
670a0c63fb |
24
.gitignore
vendored
24
.gitignore
vendored
@ -1,4 +1,22 @@
|
|||||||
node_modules/
|
|
||||||
public/
|
|
||||||
coverage/
|
|
||||||
.nogit/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
|
coverage/
|
||||||
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
@ -1,5 +1,5 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
@ -34,48 +34,11 @@ snyk:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
sast:
|
|
||||||
stage: security
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
|
||||||
variables:
|
|
||||||
DOCKER_DRIVER: overlay2
|
|
||||||
allow_failure: true
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
|
||||||
- docker run
|
|
||||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
|
||||||
--volume "$PWD:/code"
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
|
||||||
artifacts:
|
|
||||||
reports:
|
|
||||||
sast: gl-sast-report.json
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
@ -85,12 +48,24 @@ testSTABLE:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install lts
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
@ -103,19 +78,11 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm install
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
@ -131,13 +98,15 @@ trigger:
|
|||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
44
README.md
44
README.md
@ -14,7 +14,7 @@ do more with data
|
|||||||
[](https://snyk.io/test/npm/@pushrocks/smartdata)
|
[](https://snyk.io/test/npm/@pushrocks/smartdata)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](http://standardjs.com/)
|
[](https://prettier.io/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -66,16 +66,19 @@ So to get to get access to a specific collection you document
|
|||||||
@smartdata.Collection(smartdataDb)
|
@smartdata.Collection(smartdataDb)
|
||||||
class MyObject extends smartdata.DbDoc<MyObject> {
|
class MyObject extends smartdata.DbDoc<MyObject> {
|
||||||
// read the next block about DbDoc
|
// read the next block about DbDoc
|
||||||
@smartdata.svDb() property1: string; // @smartdata.svDb() marks the property for db save
|
@smartdata.svDb()
|
||||||
|
property1: string; // @smartdata.svDb() marks the property for db save
|
||||||
|
|
||||||
property2: number; // this one is not marked, so it won't be save upon calling this.save()
|
property2: number; // this one is not marked, so it won't be save upon calling this.save()
|
||||||
constructor(optionsArg: { property1: string; property2: number }) {
|
|
||||||
super();
|
constructor() {
|
||||||
|
super(); // the super call is important ;) But you probably know that.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// start to instantiate instances of classes from scratch or database
|
// start to instantiate instances of classes from scratch or database
|
||||||
|
|
||||||
let localObject = new MyObject({
|
const localObject = new MyObject({
|
||||||
property1: 'hi',
|
property1: 'hi',
|
||||||
property2: 2
|
property2: 2
|
||||||
});
|
});
|
||||||
@ -93,31 +96,42 @@ MyObject.getInstance<MyObject>({
|
|||||||
represents a individual document in a collection
|
represents a individual document in a collection
|
||||||
and thereby is ideally suited to extend the class you want to actually store.
|
and thereby is ideally suited to extend the class you want to actually store.
|
||||||
|
|
||||||
**sStore** instances of classes to Db:
|
### CRUD operations
|
||||||
|
smartdata supports full CRUD operations
|
||||||
|
|
||||||
|
**Store** or **Update** instances of classes to MongoDB:
|
||||||
DbDoc extends your class with the following methods:
|
DbDoc extends your class with the following methods:
|
||||||
|
|
||||||
- `.save()` will save (or update) the object you call it on only. Any referenced non-savable objects will not get stored.
|
- async `.save()` will save (or update) the object you call it on only. Any referenced non-savable objects will not get stored.
|
||||||
- `.saveDeep()` does the same like `.save()`.
|
- async `.saveDeep()` does the same like `.save()`.
|
||||||
In addition it will look for properties that reference an object
|
In addition it will look for properties that reference an object
|
||||||
that extends DbDoc as well and call .saveDeep() on them as well.
|
that extends DbDoc as well and call .saveDeep() on them as well.
|
||||||
Loops are prevented
|
Loops are prevented
|
||||||
|
|
||||||
**Get** a new class instance from a Doc in the DB:
|
**Get** a new class instance from MongoDB:
|
||||||
DbDoc exposes a static method that allows you specify a filter to retrieve a cloned class of the one you used to that doc at some point later in time. Yes, let that sink in a minute :)
|
DbDoc exposes a static method that allows you specify a filter to retrieve a cloned class of the one you used to that doc at some point later in time:
|
||||||
|
|
||||||
|
* static async `.getInstance({ /* filter props here */ })` gets you an instance that has the data of the first matched document as properties.
|
||||||
|
* static async `getInstances({ /* filter props here */ })` get you an array instances (one instance for every matched document).
|
||||||
|
|
||||||
|
**Delete** instances from MongoDb:
|
||||||
|
smartdata extends your class with a method to easily delete the doucment from DB:
|
||||||
|
|
||||||
|
* async `.delete()`will delete the document from DB.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
So you can just call `.getInstance({ /* filter props here */ })`.
|
|
||||||
|
|
||||||
## TypeScript
|
## TypeScript
|
||||||
|
|
||||||
How does TypeScript play into this?
|
How does TypeScript play into this?
|
||||||
Since you define your classes in TypeScript and types flow through smartdata in a generic way
|
Since you define your classes in TypeScript and types flow through smartdata in a generic way
|
||||||
you should get all the Intellisense and type checking you love when using smartdata.
|
you should get all the Intellisense and type checking you love when using smartdata.
|
||||||
smartdata itself also bundles typings.
|
smartdata itself also bundles typings. You don't need to install any additional types for smartdata.
|
||||||
So you don't need to install any additional types when importing smartdata.
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
[](https://maintainedby.lossless.com)
|
||||||
|
1030
package-lock.json
generated
1030
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
43
package.json
43
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdata",
|
"name": "@pushrocks/smartdata",
|
||||||
"version": "3.1.15",
|
"version": "3.1.25",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "do more with data",
|
"description": "do more with data",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -21,27 +21,38 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
|
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.11",
|
"@pushrocks/lik": "^3.0.17",
|
||||||
"@pushrocks/smartlog": "^2.0.19",
|
"@pushrocks/smartlog": "^2.0.21",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smartstring": "^3.0.10",
|
"@pushrocks/smartstring": "^3.0.18",
|
||||||
"@pushrocks/smartunique": "^3.0.1",
|
"@pushrocks/smartunique": "^3.0.1",
|
||||||
"@types/lodash": "^4.14.138",
|
"@types/lodash": "^4.14.149",
|
||||||
"@types/mongodb": "^3.3.1",
|
"@types/mongodb": "^3.3.15",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
"mongodb": "^3.3.2",
|
"mongodb": "^3.5.2",
|
||||||
"runtime-type-checks": "0.0.4"
|
"runtime-type-checks": "0.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@pushrocks/qenv": "^4.0.4",
|
"@pushrocks/qenv": "^4.0.6",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
"@types/mongodb-memory-server": "^1.8.0",
|
"@types/mongodb-memory-server": "^2.3.0",
|
||||||
"@types/node": "^12.7.3",
|
"@types/node": "^13.7.0",
|
||||||
"@types/shortid": "0.0.29",
|
"@types/shortid": "0.0.29",
|
||||||
"mongodb-memory-server": "^5.2.0",
|
"mongodb-memory-server": "^6.2.4",
|
||||||
"tslint": "^5.19.0",
|
"tslint": "^6.0.0",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/*",
|
||||||
|
"ts_web/*",
|
||||||
|
"dist/*",
|
||||||
|
"dist_web/*",
|
||||||
|
"dist_ts_web/*",
|
||||||
|
"assets/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
67
test/test.ts
67
test/test.ts
@ -26,14 +26,7 @@ tap.test('should create a testinstance as database', async () => {
|
|||||||
mongoDbUrl: await mongod.getConnectionString()
|
mongoDbUrl: await mongod.getConnectionString()
|
||||||
};
|
};
|
||||||
console.log(smartdataOptions);
|
console.log(smartdataOptions);
|
||||||
});
|
testDb = new smartdata.SmartdataDb(smartdataOptions);
|
||||||
|
|
||||||
tap.test('should create a smartdb', async () => {
|
|
||||||
testDb = new smartdata.SmartdataDb({
|
|
||||||
mongoDbName: testQenv.getEnvVarOnDemand('MONGO_DBNAME'),
|
|
||||||
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGO_URL'),
|
|
||||||
mongoDbPass: testQenv.getEnvVarOnDemand('MONGO_PASS')
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should establish a connection to the rethink Db cluster', async () => {
|
tap.test('should establish a connection to the rethink Db cluster', async () => {
|
||||||
@ -54,10 +47,10 @@ tap.test('should establish a connection to the rethink Db cluster', async () =>
|
|||||||
class Car extends smartdata.SmartDataDbDoc<Car> {
|
class Car extends smartdata.SmartDataDbDoc<Car> {
|
||||||
@smartdata.unI()
|
@smartdata.unI()
|
||||||
public index: string = smartunique.shortId();
|
public index: string = smartunique.shortId();
|
||||||
|
|
||||||
@smartdata.svDb()
|
@smartdata.svDb()
|
||||||
public color: string;
|
public color: string;
|
||||||
|
|
||||||
@smartdata.svDb()
|
@smartdata.svDb()
|
||||||
public brand: string;
|
public brand: string;
|
||||||
|
|
||||||
@ -72,8 +65,11 @@ tap.test('should save the car to the db', async () => {
|
|||||||
const myCar = new Car('red', 'Volvo');
|
const myCar = new Car('red', 'Volvo');
|
||||||
await myCar.save();
|
await myCar.save();
|
||||||
|
|
||||||
const myCar2 = new Car('red', 'Renault');
|
const myCar2 = new Car('red', 'Volvo');
|
||||||
await myCar2.save();
|
await myCar2.save();
|
||||||
|
|
||||||
|
const myCar3 = new Car('red', 'Renault');
|
||||||
|
await myCar3.save();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('expect to get instance of Car', async () => {
|
tap.test('expect to get instance of Car', async () => {
|
||||||
@ -90,12 +86,55 @@ tap.test('expect to get instance of Car and update it', async () => {
|
|||||||
expect(myCar.color).to.equal('red');
|
expect(myCar.color).to.equal('red');
|
||||||
myCar.color = 'blue';
|
myCar.color = 'blue';
|
||||||
await myCar.save();
|
await myCar.save();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should be able to delete an instance of car', async () => {
|
||||||
|
const myCar = await Car.getInstance<Car>({
|
||||||
|
brand: 'Volvo'
|
||||||
|
});
|
||||||
|
expect(myCar.color).to.equal('blue');
|
||||||
|
await myCar.delete();
|
||||||
|
|
||||||
|
const myCar2 = await Car.getInstance<Car>({
|
||||||
|
brand: 'Volvo'
|
||||||
|
});
|
||||||
|
expect(myCar2.color).to.equal('red');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// tslint:disable-next-line: max-classes-per-file
|
||||||
|
@smartdata.Collection(() => {
|
||||||
|
return testDb;
|
||||||
|
})
|
||||||
|
class Truck extends smartdata.SmartDataDbDoc<Car> {
|
||||||
|
@smartdata.unI()
|
||||||
|
public id: string = smartunique.shortId();
|
||||||
|
|
||||||
|
@smartdata.svDb()
|
||||||
|
public color: string;
|
||||||
|
|
||||||
|
@smartdata.svDb()
|
||||||
|
public brand: string;
|
||||||
|
|
||||||
|
constructor(colorArg: string, brandArg: string) {
|
||||||
|
super();
|
||||||
|
this.color = colorArg;
|
||||||
|
this.brand = brandArg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tap.test('should store a new Truck', async () => {
|
||||||
|
const truck = new Truck('blue', 'MAN');
|
||||||
|
await truck.save();
|
||||||
|
const myTruck = await Truck.getInstance<Truck>({color: 'blue'});
|
||||||
|
myTruck.id = 'foo';
|
||||||
|
await myTruck.save();
|
||||||
|
const myTruck2 = await Truck.getInstance<Truck>({color: 'blue'});
|
||||||
|
console.log(myTruck2);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should be able to update an instance of car', async () => {});
|
|
||||||
|
|
||||||
tap.test('should be able to delete an instance of car', async () => {});
|
|
||||||
|
|
||||||
// =======================================
|
// =======================================
|
||||||
// close the database connection
|
// close the database connection
|
||||||
|
@ -120,8 +120,6 @@ export class SmartdataCollection<T> {
|
|||||||
await this.checkDoc(dbDocArg);
|
await this.checkDoc(dbDocArg);
|
||||||
const identifiableObject = await dbDocArg.createIdentifiableObject();
|
const identifiableObject = await dbDocArg.createIdentifiableObject();
|
||||||
const saveableObject = await dbDocArg.createSavableObject();
|
const saveableObject = await dbDocArg.createSavableObject();
|
||||||
console.log(identifiableObject);
|
|
||||||
console.log(saveableObject);
|
|
||||||
const updateableObject: any = {};
|
const updateableObject: any = {};
|
||||||
for (const key of Object.keys(saveableObject)) {
|
for (const key of Object.keys(saveableObject)) {
|
||||||
if (identifiableObject[key]) {
|
if (identifiableObject[key]) {
|
||||||
@ -129,15 +127,20 @@ export class SmartdataCollection<T> {
|
|||||||
}
|
}
|
||||||
updateableObject[key] = saveableObject[key];
|
updateableObject[key] = saveableObject[key];
|
||||||
}
|
}
|
||||||
console.log(updateableObject);
|
this.mongoDbCollection.updateOne(
|
||||||
this.mongoDbCollection.updateOne(identifiableObject, { $set: updateableObject }, {upsert: true});
|
identifiableObject,
|
||||||
|
{ $set: updateableObject },
|
||||||
|
{ upsert: true }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async delete(dbDocArg: T & SmartDataDbDoc<T>): Promise<any> {
|
public async delete(dbDocArg: T & SmartDataDbDoc<T>): Promise<any> {
|
||||||
await this.init();
|
await this.init();
|
||||||
await this.checkDoc(dbDocArg);
|
await this.checkDoc(dbDocArg);
|
||||||
const identifiableObject = await dbDocArg.createIdentifiableObject();
|
const identifiableObject = await dbDocArg.createIdentifiableObject();
|
||||||
this.mongoDbCollection.deleteOne(identifiableObject);
|
await this.mongoDbCollection.deleteOne(identifiableObject, {
|
||||||
|
w: 1
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,7 +54,8 @@ export class SmartdataDb {
|
|||||||
}
|
}
|
||||||
console.log(`connection Url: ${finalConnectionUrl}`);
|
console.log(`connection Url: ${finalConnectionUrl}`);
|
||||||
this.mongoDbClient = await plugins.mongodb.MongoClient.connect(finalConnectionUrl, {
|
this.mongoDbClient = await plugins.mongodb.MongoClient.connect(finalConnectionUrl, {
|
||||||
useNewUrlParser: true
|
useNewUrlParser: true,
|
||||||
|
useUnifiedTopology: true
|
||||||
});
|
});
|
||||||
this.mongoDb = this.mongoDbClient.db(this.smartdataOptions.mongoDbName);
|
this.mongoDb = this.mongoDbClient.db(this.smartdataOptions.mongoDbName);
|
||||||
this.status = 'connected';
|
this.status = 'connected';
|
||||||
|
@ -103,17 +103,15 @@ export class SmartDataDbDoc<T> {
|
|||||||
for (const item of foundDocs) {
|
for (const item of foundDocs) {
|
||||||
const newInstance = new this();
|
const newInstance = new this();
|
||||||
newInstance.creationStatus = 'db';
|
newInstance.creationStatus = 'db';
|
||||||
for (const key in item) {
|
for (const key of Object.keys(item)) {
|
||||||
if (key !== 'id') {
|
newInstance[key] = item[key];
|
||||||
newInstance[key] = item[key];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
returnArray.push(newInstance);
|
returnArray.push(newInstance);
|
||||||
}
|
}
|
||||||
return returnArray;
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getInstance<T>(filterArg): Promise<T> {
|
public static async getInstance<T>(filterArg): Promise<T> {
|
||||||
const result = await this.getInstances<T>(filterArg);
|
const result = await this.getInstances<T>(filterArg);
|
||||||
if (result && result.length > 0) {
|
if (result && result.length > 0) {
|
||||||
return result[0];
|
return result[0];
|
||||||
@ -143,7 +141,10 @@ export class SmartDataDbDoc<T> {
|
|||||||
/**
|
/**
|
||||||
* deletes a document from the database
|
* deletes a document from the database
|
||||||
*/
|
*/
|
||||||
public async delete() {}
|
public async delete() {
|
||||||
|
const self: any = this;
|
||||||
|
await this.collection.delete(self);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* also store any referenced objects to DB
|
* also store any referenced objects to DB
|
||||||
|
Reference in New Issue
Block a user