Last active
November 9, 2024 04:06
-
-
Save theusindabike/fe84028cdeb9819446a93fb62e348efc to your computer and use it in GitHub Desktop.
peg-mem datasource configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Thanks for sharing this. pg-mem docs on typeorm are pretty outdated!