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

Method getKysely

packages/sql/src/SqlEntityManager.ts:106–126  ·  view source on GitHub ↗

* Returns a configured Kysely instance bound to this EntityManager. * * When the EntityManager is inside a transaction (e.g. within `em.transactional(...)`, or after * `em.begin()`), the returned Kysely instance automatically uses the transaction context, so any * queries executed via Ky

(
    options: TOptions = {} as TOptions,
  )

Source from the content-addressed store, hash-verified

104 * transaction the connection is already pinned.
105 */
106 getKysely<TDB = undefined, TOptions extends GetKyselyOptions = GetKyselyOptions>(
107 options: TOptions = {} as TOptions,
108 ): Kysely<
109 TDB extends undefined
110 ? InferKyselyDB<EntitiesFromManager<this>, TOptions> & InferClassEntityDB<AllEntitiesFromManager<this>, TOptions>
111 : TDB
112 > {
113 const context = this.getContext(false);
114 const ctx = context.getTransactionContext<Kysely<any>>();
115 let kysely: Kysely<any> = ctx ?? this.getConnection(options.type).getClient();
116 if (
117 options.columnNamingStrategy != null ||
118 options.tableNamingStrategy != null ||
119 options.processOnCreateHooks != null ||
120 options.processOnUpdateHooks != null ||
121 options.convertValues != null
122 ) {
123 kysely = kysely.withPlugin(new MikroKyselyPlugin(this, options));
124 }
125 return kysely;
126 }
127
128 /**
129 * Executes a raw SQL query, using the current transaction context if available. The fork-level

Calls 4

getContextMethod · 0.80
getTransactionContextMethod · 0.80
getClientMethod · 0.80
getConnectionMethod · 0.65

Tested by

no test coverage detected