fix(core): update
This commit is contained in:
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/mongodump',
|
||||
version: '1.0.2',
|
||||
description: 'a tool to handle dumps of mongodb databases'
|
||||
}
|
2
ts/index.ts
Normal file
2
ts/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './mongodb.classes.mongodump.js';
|
||||
export * from './mongodb.classes.mongodumptarget.js';
|
10
ts/mongocompresseddump.ts
Normal file
10
ts/mongocompresseddump.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import * as plugins from './mongodump.plugins.js';
|
||||
|
||||
/**
|
||||
* a mongo compressed dump
|
||||
* this can be used to create, psersistently store and restore dumps
|
||||
*
|
||||
*/
|
||||
export class MongoCompressedDump {
|
||||
|
||||
}
|
22
ts/mongodb.classes.mongodump.ts
Normal file
22
ts/mongodb.classes.mongodump.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import * as plugins from './mongodump.plugins.js';
|
||||
import { MongoDumpTarget } from './mongodb.classes.mongodumptarget.js';
|
||||
|
||||
export class MongoDump {
|
||||
public mongoTargetObjectMap = new plugins.lik.ObjectMap<MongoDumpTarget>();
|
||||
|
||||
constructor() {}
|
||||
|
||||
public async addMongoTargetByMongoDescriptor(
|
||||
descriptorArg: plugins.tsclass.database.IMongoDescriptor
|
||||
) {
|
||||
const mongoDumpTarget = await MongoDumpTarget.createAndInit(descriptorArg);
|
||||
this.mongoTargetObjectMap.add(mongoDumpTarget);
|
||||
return mongoDumpTarget;
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
await this.mongoTargetObjectMap.forEach(async (mongoTargetArg) => {
|
||||
await mongoTargetArg.mongoDbClient.close();
|
||||
})
|
||||
}
|
||||
}
|
71
ts/mongodb.classes.mongodumptarget.ts
Normal file
71
ts/mongodb.classes.mongodumptarget.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import * as plugins from './mongodump.plugins.js';
|
||||
|
||||
/**
|
||||
* a MongoDump Target is a pointer to a database
|
||||
* + exposes functions to interact with the dump target
|
||||
*/
|
||||
export class MongoDumpTarget {
|
||||
public static async createAndInit(
|
||||
mongoDescriptorArg: plugins.tsclass.database.IMongoDescriptor
|
||||
) {
|
||||
const mongoDumpTarget = new MongoDumpTarget(mongoDescriptorArg);
|
||||
await mongoDumpTarget.init();
|
||||
return mongoDumpTarget;
|
||||
}
|
||||
|
||||
public readyDeferred = plugins.smartpromise.defer();
|
||||
public mongoDescriptor: plugins.tsclass.database.IMongoDescriptor;
|
||||
public mongoDbClient: plugins.mongodb.MongoClient;
|
||||
public mongoDb: plugins.mongodb.Db;
|
||||
constructor(mongoDescriptorArg: plugins.tsclass.database.IMongoDescriptor) {
|
||||
this.mongoDescriptor = mongoDescriptorArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* connects to the database that was specified during instance creation
|
||||
*/
|
||||
public async init(): Promise<any> {
|
||||
const finalConnectionUrl = this.mongoDescriptor.mongoDbUrl
|
||||
.replace('<USERNAME>', this.mongoDescriptor.mongoDbUser)
|
||||
.replace('<username>', this.mongoDescriptor.mongoDbUser)
|
||||
.replace('<USER>', this.mongoDescriptor.mongoDbUser)
|
||||
.replace('<user>', this.mongoDescriptor.mongoDbUser)
|
||||
.replace('<PASSWORD>', this.mongoDescriptor.mongoDbPass)
|
||||
.replace('<password>', this.mongoDescriptor.mongoDbPass)
|
||||
.replace('<DBNAME>', this.mongoDescriptor.mongoDbName)
|
||||
.replace('<dbname>', this.mongoDescriptor.mongoDbName);
|
||||
|
||||
this.mongoDbClient = await plugins.mongodb.MongoClient.connect(finalConnectionUrl, {
|
||||
maxPoolSize: 100,
|
||||
maxIdleTimeMS: 10,
|
||||
});
|
||||
this.mongoDb = this.mongoDbClient.db(this.mongoDescriptor.mongoDbName);
|
||||
console.log(`Connected to database ${this.mongoDescriptor.mongoDbName}`);
|
||||
this.readyDeferred.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all collections
|
||||
*/
|
||||
public async getCollections() {
|
||||
await this.readyDeferred.promise;
|
||||
const collections = await this.mongoDb.collections();
|
||||
console.log(`The follwing collections have been found:`);
|
||||
for (const collection of collections) {
|
||||
console.log(collection.collectionName);
|
||||
}
|
||||
|
||||
return collections;
|
||||
}
|
||||
|
||||
/**
|
||||
* dumps a collection to a directory
|
||||
*/
|
||||
public async dumpCollectionToDir(collectionArg: plugins.mongodb.Collection, dirArg: string) {
|
||||
|
||||
}
|
||||
|
||||
public async dumpCollectionToTarArchive(collectionArg: plugins.mongodb.Collection) {}
|
||||
|
||||
public async dumpAllCollectionsToDir() {}
|
||||
}
|
24
ts/mongodump.plugins.ts
Normal file
24
ts/mongodump.plugins.ts
Normal file
@ -0,0 +1,24 @@
|
||||
// pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export {
|
||||
lik,
|
||||
smartfile,
|
||||
smartpromise
|
||||
}
|
||||
|
||||
// tsclass
|
||||
import type * as tsclass from '@tsclass/tsclass';
|
||||
|
||||
export {
|
||||
tsclass
|
||||
}
|
||||
|
||||
// third party scope
|
||||
import * as mongodb from 'mongodb';
|
||||
|
||||
export {
|
||||
mongodb
|
||||
}
|
Reference in New Issue
Block a user