**What**
> [!NOTE]
> I can see this pr becoming huge, so I d like to get this partial one merged 👍
- Fixes shared connection usage (mikro orm compare the instance to its own package and therefore was resulting in not trully reusing the provided connection leading to exhausting the connection pool as multiple connections was created and end up not being all destroyed properly under the hood, discovered in my integration tests)
- Create shipping options method implementation
- DTO's definition and service interface update
- integration tests
- Re work of the indexes with new util update
- Test runner utils to remove a big chunk of the boilerplate of the packages integrations
FIXES CORE-1742
31 lines
882 B
TypeScript
31 lines
882 B
TypeScript
import { knex } from "@mikro-orm/knex"
|
|
import { ModuleServiceInitializeOptions } from "@medusajs/types"
|
|
|
|
type Options = ModuleServiceInitializeOptions["database"]
|
|
|
|
/**
|
|
* Create a new knex (pg in the future) connection which can be reused and shared
|
|
* @param options
|
|
*/
|
|
export function createPgConnection(options: Options) {
|
|
const { pool, schema = "public", clientUrl, driverOptions } = options
|
|
const ssl = options.driverOptions?.ssl ?? false
|
|
|
|
return knex<any, any>({
|
|
client: "pg",
|
|
searchPath: schema,
|
|
connection: {
|
|
connectionString: clientUrl,
|
|
ssl,
|
|
idle_in_transaction_session_timeout:
|
|
(driverOptions?.idle_in_transaction_session_timeout as number) ??
|
|
undefined, // prevent null to be passed
|
|
},
|
|
pool: {
|
|
// https://knexjs.org/guide/#pool
|
|
...(pool ?? {}),
|
|
min: (pool?.min as number) ?? 0,
|
|
},
|
|
})
|
|
}
|