fix(core): update

This commit is contained in:
Philipp Kunz 2020-10-19 16:44:28 +00:00
parent 8b6c26f45a
commit fbdde2268c
4 changed files with 12 additions and 11 deletions

View File

@ -60,4 +60,4 @@
"browserslist": [
"last 1 chrome versions"
]
}
}

View File

@ -68,7 +68,7 @@ class Car extends smartdata.SmartDataDbDoc<Car, Car> {
@smartdata.svDb()
deepData = {
sodeep: 'yes'
sodeep: 'yes',
};
constructor(colorArg: string, brandArg: string) {
@ -85,15 +85,13 @@ tap.test('should save the car to the db', async () => {
const myCar2 = new Car('red', 'Volvo');
await myCar2.save();
let counter = 0;
const totalCars = 2000;
do {
const myCar3 = new Car('red', 'Renault');
await myCar3.save();
counter++;
if (counter%100 === 0) {
if (counter % 100 === 0) {
console.log(`Filled database with ${counter} of ${totalCars} Cars`);
}
} while (counter < totalCars);
@ -139,7 +137,7 @@ tap.test('expect to get instance of Car and update it', async () => {
tap.test('should be able to delete an instance of car', async () => {
const myCars = await Car.getInstances<Car>({
brand: 'Volvo',
color: 'blue'
color: 'blue',
});
console.log(myCars);
expect(myCars[0].color).to.equal('blue');

View File

@ -3,9 +3,12 @@ import { SmartdataCollection } from './smartdata.classes.collection';
import { SmartdataDb } from './smartdata.classes.db';
export class CollectionFactory {
public collections: {[key: string]: SmartdataCollection<any>} = {};
public collections: { [key: string]: SmartdataCollection<any> } = {};
public getCollection = (nameArg: string, dbArg: SmartdataDb | (() => SmartdataDb)): SmartdataCollection<any> => {
public getCollection = (
nameArg: string,
dbArg: SmartdataDb | (() => SmartdataDb)
): SmartdataCollection<any> => {
if (!this.collections[nameArg]) {
this.collections[nameArg] = (() => {
if (dbArg instanceof SmartdataDb) {
@ -18,5 +21,5 @@ export class CollectionFactory {
})();
}
return this.collections[nameArg];
}
}
};
}

View File

@ -43,7 +43,7 @@ export class SmartdataDb {
useNewUrlParser: true,
useUnifiedTopology: true,
maxPoolSize: 100,
maxIdleTimeMS: 10
maxIdleTimeMS: 10,
});
this.mongoDb = this.mongoDbClient.db(this.smartdataOptions.mongoDbName);
this.status = 'connected';