Skip to content

Instantly share code, notes, and snippets.

@theusindabike
Last active May 23, 2023 19:45
Show Gist options
  • Save theusindabike/fe84028cdeb9819446a93fb62e348efc to your computer and use it in GitHub Desktop.
Save theusindabike/fe84028cdeb9819446a93fb62e348efc to your computer and use it in GitHub Desktop.
peg-mem datasource configuration
import { newDb } from 'pg-mem';
export const setupDatabase = async () => {
const db = newDb();
db.public.registerFunction({
implementation: () => 'test',
name: 'current_database',
});
db.public.registerFunction({
name: 'version',
implementation: () => 'Im not sure about PostgreSQL version',
});
const dataSource = await db.adapters.createTypeormDataSource({
type: 'postgres',
entities: [__dirname + '../../src/**/*.entity{.ts,.js}'],
migrationsRun: false,
migrationsTransactionMode: 'each',
synchronize: false,
});
await dataSource.initialize();
await dataSource.synchronize();
return dataSource;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment