mongodump/test/sampledata.ts

50 lines
1006 B
TypeScript
Raw Normal View History

2022-06-05 19:04:16 +00:00
import * as smartdata from '@pushrocks/smartdata';
let db: smartdata.SmartdataDb;
export const stop = async () => {
await db.close();
}
export const generateTestData = async (mongoDescriptorArg: smartdata.IMongoDescriptor) => {
db = new smartdata.SmartdataDb(mongoDescriptorArg);
await db.init();
let counter = 0;
@smartdata.Collection(db)
class House extends smartdata.SmartDataDbDoc<House, House> {
@smartdata.unI()
id = `hello-${counter}`;
@smartdata.svDb()
data = {
'some' : {
2022-06-06 11:08:45 +00:00
'complex': 'structure',
more: 4
2022-06-05 19:04:16 +00:00
}
}
}
2022-06-06 11:04:30 +00:00
@smartdata.Collection(db)
class Truck extends smartdata.SmartDataDbDoc<Truck, Truck> {
@smartdata.unI()
id = `hello-${counter}`;
@smartdata.svDb()
data = {
'some' : {
2022-06-06 11:08:45 +00:00
'complex': 'structure',
more: 2
2022-06-06 11:04:30 +00:00
}
}
}
2022-06-05 19:04:16 +00:00
while (counter < 100) {
const house = new House();
await house.save();
2022-06-06 11:04:30 +00:00
const truck = new Truck();
await truck.save();
2022-06-05 19:04:16 +00:00
counter++;
}
}