| 44 | * @inheritDoc |
| 45 | */ |
| 46 | export class SqlEntityManager<Driver extends AbstractSqlDriver = AbstractSqlDriver> extends EntityManager<Driver> { |
| 47 | /** |
| 48 | * Creates a QueryBuilder instance |
| 49 | */ |
| 50 | createQueryBuilder<Entity extends object, RootAlias extends string = never>( |
| 51 | entityName: EntityName<Entity> | QueryBuilder<Entity>, |
| 52 | alias?: RootAlias, |
| 53 | type?: ConnectionType, |
| 54 | loggerContext?: LoggingOptions, |
| 55 | ): QueryBuilder<Entity, RootAlias> { |
| 56 | const context = this.getContext(false); |
| 57 | const qb = this.driver.createQueryBuilder( |
| 58 | entityName as EntityName<Entity>, |
| 59 | context.getTransactionContext(), |
| 60 | type, |
| 61 | true, |
| 62 | loggerContext ?? context.loggerContext, |
| 63 | alias, |
| 64 | this, |
| 65 | ); |
| 66 | qb.setAbortOptions(context.getAbortOptions()); |
| 67 | return qb as any; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Shortcut for `createQueryBuilder()` |
| 72 | */ |
| 73 | qb<Entity extends object, RootAlias extends string = never>( |
| 74 | entityName: EntityName<Entity>, |
| 75 | alias?: RootAlias, |
| 76 | type?: ConnectionType, |
| 77 | loggerContext?: LoggingOptions, |
| 78 | ): QueryBuilder<Entity, RootAlias> { |
| 79 | return this.createQueryBuilder(entityName, alias, type, loggerContext); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns a configured Kysely instance bound to this EntityManager. |
| 84 | * |
| 85 | * When the EntityManager is inside a transaction (e.g. within `em.transactional(...)`, or after |
| 86 | * `em.begin()`), the returned Kysely instance automatically uses the transaction context, so any |
| 87 | * queries executed via Kysely's own `.execute()` / `.executeTakeFirst*()` participate in the |
| 88 | * current transaction. |
| 89 | * |
| 90 | * If you need a Kysely instance that is **not** bound to the current transaction (e.g. to perform |
| 91 | * a side query against the pool while inside a transactional block), fork the EntityManager first: |
| 92 | * |
| 93 | * ```ts |
| 94 | * await em.transactional(async em => { |
| 95 | * // bound to the current transaction |
| 96 | * await em.getKysely().selectFrom('user').selectAll().execute(); |
| 97 | * |
| 98 | * // bound to the pool, runs outside the transaction |
| 99 | * await em.fork().getKysely().selectFrom('audit_log').selectAll().execute(); |
| 100 | * }); |
| 101 | * ``` |
| 102 | * |
| 103 | * The `options.type` (`'read'` / `'write'`) is only honored outside a transaction — inside a |
nothing calls this directly
no outgoing calls
no test coverage detected