Skip to content

Commit

Permalink
feat(database): removed database connection from the library itself b…
Browse files Browse the repository at this point in the history
…ut instead we let people connect to their favorite connection
  • Loading branch information
Stradivario committed Apr 23, 2024
1 parent 30ce4a8 commit de27408
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 500 deletions.
40 changes: 22 additions & 18 deletions examples/api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Container, setup } from '@rxdi/core';
import { MongoClient } from 'mongodb';
import { connect } from 'mongoose';

import {
MigrationService,
Config,
ConfigService,
GenericRunner,
LogFactory,
ConfigService,
LoggerConfig,
Config
MigrationService,
} from '../src/index'; // equivalent to '@rxdi/xmigrate'

const config = {
Expand All @@ -19,20 +21,22 @@ const config = {
folder: './migrations-log',
up: {
success: 'up.success.log',
error: 'up.error.log'
error: 'up.error.log',
},
down: {
success: 'down.success.log',
error: 'down.error.log'
}
error: 'down.error.log',
},
},
database: {
async connect() {
const url = 'mongodb://localhost:27017';

await connect(url);
const client = await MongoClient.connect(url);
return client;
},
},
mongodb: {
url: 'mongodb://localhost:27017',
databaseName: 'test',
options: {
useNewUrlParser: true
}
}
};

setup({
Expand All @@ -42,13 +46,13 @@ setup({
ConfigService,
{
provide: Config,
useValue: config
useValue: config,
},
{
provide: LoggerConfig,
useValue: config.logger
}
]
useValue: config.logger,
},
],
}).subscribe(async () => {
const template = `
import { MongoClient } from 'mongodb';
Expand All @@ -67,7 +71,7 @@ export async function down(client: MongoClient) {
const filePath = await migrationService.createWithTemplate(
template as 'typescript',
'pesho1234',
{ raw: true, typescript: true }
{ raw: true, typescript: true },
);
console.log(filePath);

Expand Down
Loading

0 comments on commit de27408

Please sign in to comment.