Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
6eb43a4b9f | |||
7f89cbeecd | |||
a042a589a0 | |||
75b5f6af08 | |||
e6a36f22ac | |||
246e3486f0 | |||
c1c4a29415 | |||
6448516aa0 |
1030
package-lock.json
generated
1030
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartdata",
|
||||
"version": "3.1.20",
|
||||
"version": "3.1.24",
|
||||
"private": false,
|
||||
"description": "do more with data",
|
||||
"main": "dist/index.js",
|
||||
@ -21,27 +21,27 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^3.0.11",
|
||||
"@pushrocks/smartlog": "^2.0.19",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@pushrocks/smartstring": "^3.0.10",
|
||||
"@pushrocks/lik": "^3.0.17",
|
||||
"@pushrocks/smartlog": "^2.0.21",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@pushrocks/smartstring": "^3.0.18",
|
||||
"@pushrocks/smartunique": "^3.0.1",
|
||||
"@types/lodash": "^4.14.138",
|
||||
"@types/mongodb": "^3.3.1",
|
||||
"@types/lodash": "^4.14.149",
|
||||
"@types/mongodb": "^3.3.15",
|
||||
"lodash": "^4.17.15",
|
||||
"mongodb": "^3.3.2",
|
||||
"mongodb": "^3.5.2",
|
||||
"runtime-type-checks": "0.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/qenv": "^4.0.4",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"@types/mongodb-memory-server": "^1.8.0",
|
||||
"@types/node": "^12.7.3",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/qenv": "^4.0.6",
|
||||
"@pushrocks/tapbundle": "^3.2.0",
|
||||
"@types/mongodb-memory-server": "^2.3.0",
|
||||
"@types/node": "^13.7.0",
|
||||
"@types/shortid": "0.0.29",
|
||||
"mongodb-memory-server": "^5.2.0",
|
||||
"tslint": "^5.19.0",
|
||||
"mongodb-memory-server": "^6.2.4",
|
||||
"tslint": "^6.0.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"files": [
|
||||
|
43
test/test.ts
43
test/test.ts
@ -29,14 +29,6 @@ tap.test('should create a testinstance as database', async () => {
|
||||
testDb = new smartdata.SmartdataDb(smartdataOptions);
|
||||
});
|
||||
|
||||
tap.skip.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 () => {
|
||||
await testDb.init();
|
||||
});
|
||||
@ -109,6 +101,41 @@ tap.test('should be able to delete an instance of car', async () => {
|
||||
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);
|
||||
|
||||
});
|
||||
|
||||
|
||||
// =======================================
|
||||
// close the database connection
|
||||
// =======================================
|
||||
|
@ -120,8 +120,6 @@ export class SmartdataCollection<T> {
|
||||
await this.checkDoc(dbDocArg);
|
||||
const identifiableObject = await dbDocArg.createIdentifiableObject();
|
||||
const saveableObject = await dbDocArg.createSavableObject();
|
||||
console.log(identifiableObject);
|
||||
console.log(saveableObject);
|
||||
const updateableObject: any = {};
|
||||
for (const key of Object.keys(saveableObject)) {
|
||||
if (identifiableObject[key]) {
|
||||
@ -129,7 +127,6 @@ export class SmartdataCollection<T> {
|
||||
}
|
||||
updateableObject[key] = saveableObject[key];
|
||||
}
|
||||
console.log(updateableObject);
|
||||
this.mongoDbCollection.updateOne(
|
||||
identifiableObject,
|
||||
{ $set: updateableObject },
|
||||
@ -141,7 +138,9 @@ export class SmartdataCollection<T> {
|
||||
await this.init();
|
||||
await this.checkDoc(dbDocArg);
|
||||
const identifiableObject = await dbDocArg.createIdentifiableObject();
|
||||
this.mongoDbCollection.deleteOne(identifiableObject);
|
||||
await this.mongoDbCollection.deleteOne(identifiableObject, {
|
||||
w: 1
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,17 +103,15 @@ export class SmartDataDbDoc<T> {
|
||||
for (const item of foundDocs) {
|
||||
const newInstance = new this();
|
||||
newInstance.creationStatus = 'db';
|
||||
for (const key in item) {
|
||||
if (key !== 'id') {
|
||||
newInstance[key] = item[key];
|
||||
}
|
||||
for (const key of Object.keys(item)) {
|
||||
newInstance[key] = item[key];
|
||||
}
|
||||
returnArray.push(newInstance);
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
static async getInstance<T>(filterArg): Promise<T> {
|
||||
public static async getInstance<T>(filterArg): Promise<T> {
|
||||
const result = await this.getInstances<T>(filterArg);
|
||||
if (result && result.length > 0) {
|
||||
return result[0];
|
||||
|
Reference in New Issue
Block a user