removed configs from all libs and will inject them within the services themselves
This commit is contained in:
parent
fd28162811
commit
6cc5b339bc
32 changed files with 366 additions and 349 deletions
|
|
@ -1,53 +1,20 @@
|
|||
import { MongoDBClient } from './client';
|
||||
import type { MongoDBClientConfig } from './types';
|
||||
|
||||
/**
|
||||
* Get the singleton MongoDB client instance
|
||||
* Factory function to create a MongoDB client instance
|
||||
*/
|
||||
export function getMongoDBClient(): MongoDBClient {
|
||||
return MongoDBClient.getInstance();
|
||||
export function createMongoDBClient(config: MongoDBClientConfig): MongoDBClient {
|
||||
return new MongoDBClient(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to MongoDB using the singleton client
|
||||
* Create and connect a MongoDB client
|
||||
*/
|
||||
export async function connectMongoDB(): Promise<MongoDBClient> {
|
||||
const client = getMongoDBClient();
|
||||
if (!client.connected) {
|
||||
await client.connect();
|
||||
}
|
||||
export async function createAndConnectMongoDBClient(
|
||||
config: MongoDBClientConfig
|
||||
): Promise<MongoDBClient> {
|
||||
const client = createMongoDBClient(config);
|
||||
await client.connect();
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from MongoDB
|
||||
*/
|
||||
export async function disconnectMongoDB(): Promise<void> {
|
||||
const client = getMongoDBClient();
|
||||
if (client.connected) {
|
||||
await client.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default database for all operations
|
||||
*/
|
||||
export function setDefaultDatabase(databaseName: string): void {
|
||||
const client = getMongoDBClient();
|
||||
client.setDefaultDatabase(databaseName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current default database name
|
||||
*/
|
||||
export function getCurrentDatabase(): string {
|
||||
const client = getMongoDBClient();
|
||||
return client.getDefaultDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a database instance by name
|
||||
*/
|
||||
export function getDatabase(databaseName?: string) {
|
||||
const client = getMongoDBClient();
|
||||
return client.getDatabase(databaseName);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue