Skip to content

Commit

Permalink
docs(transactional): fix mistakes and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Papooch committed Jul 1, 2024
1 parent 90f2df4 commit 4727c7c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ClsModule.forRoot({

:::important

The `prismaInjectionToken` is the token under which an instance of `PrismaClient` provided. Usually, in Nest, this the custom `PrismaService` class which `extends PrismaClient` and is exported from a custom module.
The `prismaInjectionToken` is the token under which an instance of [`PrismaClient`](https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/introduction) provided. Usually, in Nest, this the custom `PrismaService` class which `extends PrismaClient` and is exported from a custom module.

:::

Expand All @@ -72,7 +72,7 @@ class UserService {
// highlight-start
// both methods are executed in the same transaction
const user = await this.userRepository.createUser('John');
const foundUser = await this.userRepository.getUserById(r1.id);
const foundUser = await this.userRepository.getUserById(user.id);
// highlight-end
assert(foundUser.id === user.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ ClsModule.forRoot({
plugins: [
new ClsPluginTransactional({
imports: [
// module in which the Knex is provided
// module in which Knex is provided
KnexModule
],
adapter: new TransactionalAdapterKnex({
// the injection token of the Knex client
// the injection token of the Knex client instance
knexInstanceToken: KNEX,
}),
}),
Expand All @@ -50,7 +50,7 @@ ClsModule.forRoot({

## Typing & usage

The `tx` property on the `TransactionHost<TransactionalAdapterKnex>` is typed as `Knex`.
The `tx` property on the `TransactionHost<TransactionalAdapterKnex>` is typed as [`Knex`](https://knexjs.org/guide/query-builder.html#knex).

## Example

Expand All @@ -64,7 +64,7 @@ class UserService {
// highlight-start
// both methods are executed in the same transaction
const user = await this.userRepository.createUser('John');
const foundUser = await this.userRepository.getUserById(r1.id);
const foundUser = await this.userRepository.getUserById(user.id);
// highlight-end
assert(foundUser.id === user.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ ClsModule.forRoot({
plugins: [
new ClsPluginTransactional({
imports: [
// module in which the Kysely is provided
// module in which Kysely is provided
KyselyModule
],
adapter: new TransactionalAdapterKysely({
// the injection token of the Kysely client
// the injection token of the Kysely client instance
kyselyInstanceToken: KYSELY,
}),
}),
Expand All @@ -50,7 +50,7 @@ ClsModule.forRoot({

## Typing & usage

The `tx` property on the `TransactionHost<TransactionalAdapterKysely>` is typed as `Kysely<any>` by default. To get the full typing, you need to supply your database type as the type parameter for the `TransactionalAdapterKysely` when injecting it:
The `tx` property on the `TransactionHost<TransactionalAdapterKysely>` is typed as [`Kysely<any>`](https://kysely-org.github.io/kysely-apidoc/classes/Kysely.html) by default. To get the full typing, you need to supply your database type as the type parameter for the `TransactionalAdapterKysely` when injecting it:

```ts
constructor(
Expand Down Expand Up @@ -102,7 +102,7 @@ class UserService {
// highlight-start
// both methods are executed in the same transaction
const user = await this.userRepository.createUser('John');
const foundUser = await this.userRepository.getUserById(r1.id);
const foundUser = await this.userRepository.getUserById(user.id);
// highlight-end
assert(foundUser.id === user.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class UserService {
'John',
'john@acme.com',
);
const foundUser = await this.userRepository.getUserById(r1.id);
const foundUser = await this.userRepository.getUserById(user.id);
// highlight-end
assert(foundUser.id === user.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ When using with `@nestjs/typeorm`, the data source token needs to be retrieved w
```ts
import { getDataSourceToken } from '@nestjs/typeorm';
// ...
dataSourceToken: getDataSourceToken(),
new TransactionalAdapterTypeOrm({
dataSourceToken: getDataSourceToken(),
});
```

:::
Expand All @@ -85,7 +87,7 @@ class UserService {
// highlight-start
// both methods are executed in the same transaction
const user = await this.userRepository.createUser('John');
const foundUser = await this.userRepository.getUserById(r1.id);
const foundUser = await this.userRepository.getUserById(user.id);
// highlight-end
assert(foundUser.id === user.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class UserService {
// highlight-start
// both methods are executed in the same transaction
const user = await this.userRepository.createUser('John');
const foundUser = await this.userRepository.getUserById(r1.id);
const foundUser = await this.userRepository.getUserById(user._id);
// highlight-end
assert(foundUser.id === user.id);
assert(foundUser._id === user._id);
}
}
```
Expand All @@ -93,7 +93,7 @@ class UserRepository {
) {}

async getUserById(id: ObjectId) {
// txHost.tx is typed as Knex
// txHost.tx is typed as ClientSession
return this.mongoClient.db('default').collection('user').findOne(
{ _id: id },
// highlight-start
Expand Down

0 comments on commit 4727c7c

Please sign in to comment.