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": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
] ]
} }

View File

@ -68,7 +68,7 @@ class Car extends smartdata.SmartDataDbDoc<Car, Car> {
@smartdata.svDb() @smartdata.svDb()
deepData = { deepData = {
sodeep: 'yes' sodeep: 'yes',
}; };
constructor(colorArg: string, brandArg: string) { 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'); const myCar2 = new Car('red', 'Volvo');
await myCar2.save(); await myCar2.save();
let counter = 0; let counter = 0;
const totalCars = 2000; const totalCars = 2000;
do { do {
const myCar3 = new Car('red', 'Renault'); const myCar3 = new Car('red', 'Renault');
await myCar3.save(); await myCar3.save();
counter++; counter++;
if (counter%100 === 0) { if (counter % 100 === 0) {
console.log(`Filled database with ${counter} of ${totalCars} Cars`); console.log(`Filled database with ${counter} of ${totalCars} Cars`);
} }
} while (counter < totalCars); } 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 () => { tap.test('should be able to delete an instance of car', async () => {
const myCars = await Car.getInstances<Car>({ const myCars = await Car.getInstances<Car>({
brand: 'Volvo', brand: 'Volvo',
color: 'blue' color: 'blue',
}); });
console.log(myCars); console.log(myCars);
expect(myCars[0].color).to.equal('blue'); 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'; import { SmartdataDb } from './smartdata.classes.db';
export class CollectionFactory { 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]) { if (!this.collections[nameArg]) {
this.collections[nameArg] = (() => { this.collections[nameArg] = (() => {
if (dbArg instanceof SmartdataDb) { if (dbArg instanceof SmartdataDb) {
@ -18,5 +21,5 @@ export class CollectionFactory {
})(); })();
} }
return this.collections[nameArg]; return this.collections[nameArg];
} };
} }

View File

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