MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / initORMMySql

Function initORMMySql

tests/bootstrap.ts:88–168  ·  view source on GitHub ↗
(
  type: 'mysql' | 'mariadb' = 'mysql',
  additionalOptions: Partial<Options> = {},
  simple?: boolean,
  createSchema = true,
)

Source from the content-addressed store, hash-verified

86}
87
88export async function initORMMySql<D extends MySqlDriver | MariaDbDriver = MySqlDriver>(
89 type: 'mysql' | 'mariadb' = 'mysql',
90 additionalOptions: Partial<Options> = {},
91 simple?: boolean,
92 createSchema = true,
93) {
94 const dbName = `mikro_orm_test_${(Math.random() + 1).toString(36).substring(2)}`;
95 let orm = new MikroORM<AbstractSqlDriver>(
96 Utils.merge(
97 {
98 entities: [
99 Author2,
100 Address2,
101 Book2,
102 BookTag2,
103 Publisher2,
104 Test2,
105 FooBar2,
106 FooBaz2,
107 FooParam2,
108 Configuration2,
109 User2,
110 CarOwner2,
111 CompanyOwner2,
112 Employee2,
113 Manager2,
114 BaseUser2,
115 Dummy2,
116 ],
117 clientUrl: `mysql://root@127.0.0.1:3306/${dbName}`,
118 port: type === 'mysql' ? 3308 : 3309,
119 baseDir: BASE_DIR,
120 debug: ['query', 'query-params'],
121 timezone: 'Z',
122 charset: 'utf8mb4',
123 logger: (i: any) => i,
124 metadataProvider: ReflectMetadataProvider,
125 multipleStatements: true,
126 autoJoinRefsForFilters: false,
127 loadStrategy: LoadStrategy.BALANCED,
128 populateAfterFlush: false,
129 entityRepository: SqlEntityRepository,
130 driver: type === 'mysql' ? MySqlDriver : MariaDbDriver,
131 replicas: [
132 { name: 'read-1', driverOptions: { enableKeepAlive: true } },
133 { name: 'read-2', driverOptions: { enableKeepAlive: false } },
134 ],
135 migrations: { path: BASE_DIR + '/../temp/migrations', snapshot: false },
136 extensions: [Migrator, SeedManager, EntityGenerator],
137 subscribers: new Set([new Test2Subscriber()]),
138 },
139 additionalOptions,
140 ),
141 );
142 const buf = await readFile(import.meta.dirname + '/mysql-schema.sql');
143
144 if (createSchema) {
145 await orm.em.getConnection().executeDump(buf.toString());

Calls 10

reconnectMethod · 0.95
closeMethod · 0.95
readFileFunction · 0.85
getConnectionMethod · 0.65
setMethod · 0.65
ensureDatabaseMethod · 0.65
getAllMethod · 0.65
toStringMethod · 0.45
mergeMethod · 0.45
executeDumpMethod · 0.45

Tested by

no test coverage detected