Compare commits

..

6 Commits

Author SHA1 Message Date
9a5864656e 5.2.1 2024-04-16 07:47:25 +02:00
307f0c7277 fix(core): update 2024-04-16 07:47:24 +02:00
62dc897e73 5.2.0 2024-04-15 18:34:14 +02:00
552b344914 feat(SmartDataDbDoc): add static .getCount({}) method 2024-04-15 18:34:13 +02:00
5a2cc2406c 5.1.2 2024-04-15 14:26:22 +02:00
73a11370b6 fix(_createdAt/_updatedAt): fields are now ISO format 2024-04-15 14:26:21 +02:00
5 changed files with 28 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartdata",
"version": "5.1.1",
"version": "5.2.1",
"private": false,
"description": "An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.",
"main": "dist_ts/index.js",

View File

@ -199,12 +199,18 @@ tap.test('should store a new Truck', async () => {
const truck = new Truck('blue', 'MAN');
await truck.save();
const myTruck2 = await Truck.getInstance({ color: 'blue' });
expect(myTruck2.color).toEqual('blue');
myTruck2.color = 'red';
await myTruck2.save();
const myTruck3 = await Truck.getInstance({ color: 'blue' });
console.log(myTruck3);
expect(myTruck3).toBeNull();
});
tap.test('should return a count', async () => {
const truckCount = await Truck.getCount();
expect(truckCount).toEqual(1);
})
tap.test('should use a cursor', async () => {
const cursor = await Car.getCursor({});
let counter = 0;

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartdata',
version: '5.1.1',
version: '5.2.1',
description: 'An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.'
}

View File

@ -273,6 +273,11 @@ export class SmartdataCollection<T> {
await this.mongoDbCollection.deleteOne(identifiableObject);
}
public async getCount(filterObject: any) {
await this.init();
return this.mongoDbCollection.countDocuments(filterObject);
}
/**
* checks a Doc for constraints
* if this.objectValidation is not set it passes.

View File

@ -181,6 +181,17 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
await cursor.forEach(forEachFunction);
}
/**
* returns a count of the documents in the collection
*/
public static async getCount<T>(
this: plugins.tsclass.typeFest.Class<T>,
filterArg: plugins.tsclass.typeFest.PartialDeep<T> = ({} as any)
) {
const collection: SmartdataCollection<T> = (this as any).collection;
return await collection.getCount(filterArg);
}
// INSTANCE
/**
@ -192,13 +203,13 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
* updated from db in any case where doc comes from db
*/
@svDb()
_createdAt: number = Date.now();
_createdAt: string = (new Date()).toISOString();
/**
* will be updated everytime the doc is saved
*/
@svDb()
_updatedAt: number = Date.now();
_updatedAt: string = (new Date()).toISOString();
/**
* unique indexes
@ -234,7 +245,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
const self: any = this;
let dbResult: any;
this._updatedAt = Date.now();
this._updatedAt = (new Date()).toISOString();
switch (this.creationStatus) {
case 'db':