Skip to content

Commit a33d2be

Browse files
authored
Merge pull request #2219 from undb-io/release/v1.0.0-143
Release version v1.0.0-143
2 parents 1c375e6 + ae918c5 commit a33d2be

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## v1.0.0-143
4+
5+
6+
### 🩹 Fixes
7+
8+
- Fix sqlite database tx ([61b124c](https://github.com/undb-io/undb/commit/61b124c))
9+
10+
### ❤️ Contributors
11+
12+
- Nichenqin ([@nichenqin](https://github.com/nichenqin))
13+
314
## v1.0.0-142
415

516

apps/backend/src/modules/auth/auth.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import {
77
} from "@undb/authz"
88
import { AcceptInvitationCommand } from "@undb/commands"
99
import type { ContextMember } from "@undb/context"
10-
import { type IContext, injectContext } from "@undb/context"
11-
import { executionContext, setContextValue } from "@undb/context/server"
10+
import { type IContext,injectContext } from "@undb/context"
11+
import { executionContext,setContextValue } from "@undb/context/server"
1212
import { CommandBus } from "@undb/cqrs"
13-
import { container, inject, singleton } from "@undb/di"
14-
import { None, Option, Some } from "@undb/domain"
13+
import { container,inject,singleton } from "@undb/di"
14+
import { None,Option,Some } from "@undb/domain"
1515
import { env } from "@undb/env"
1616
import { createLogger } from "@undb/logger"
17-
import { type IMailService, injectMailService } from "@undb/mail"
18-
import { type IQueryBuilder, type ITxContext, injectQueryBuilder, injectTxCTX } from "@undb/persistence/server"
19-
import { type ISpaceService, injectSpaceService } from "@undb/space"
20-
import { Context, Elysia, t } from "elysia"
21-
import type { Session, User } from "lucia"
22-
import { Lucia, generateIdFromEntropySize } from "lucia"
23-
import { TimeSpan, createDate, isWithinExpirationDate } from "oslo"
17+
import { type IMailService,injectMailService } from "@undb/mail"
18+
import { type IQueryBuilder,type ITxContext,injectQueryBuilder,injectTxCTX } from "@undb/persistence/server"
19+
import { type ISpaceService,injectSpaceService } from "@undb/space"
20+
import { Context,Elysia,t } from "elysia"
21+
import type { Session,User } from "lucia"
22+
import { Lucia,generateIdFromEntropySize } from "lucia"
23+
import { TimeSpan,createDate,isWithinExpirationDate } from "oslo"
2424
import { Cookie } from "oslo/cookie"
25-
import { alphabet, generateRandomString, sha256 } from "oslo/crypto"
25+
import { alphabet,generateRandomString,sha256 } from "oslo/crypto"
2626
import { encodeHex } from "oslo/encoding"
2727
import { omit } from "radash"
2828
import { v7 } from "uuid"
@@ -632,7 +632,6 @@ export class Auth {
632632
.get(
633633
"/invitation/:invitationId/accept",
634634
async (ctx) => {
635-
return this.txContext.withTransaction(async () => {
636635
const { invitationId } = ctx.params
637636
await this.commandBus.execute(new AcceptInvitationCommand({ id: invitationId }))
638637

@@ -673,7 +672,6 @@ export class Auth {
673672
const sessionCookie = this.lucia.createSessionCookie(session.id)
674673
return redirectToSignupOrLogin("login", email, sessionCookie)
675674
}
676-
})
677675
},
678676
{
679677
params: t.Object({

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "undb",
3-
"version": "1.0.0-142",
3+
"version": "1.0.0-143",
44
"private": true,
55
"scripts": {
66
"build": "NODE_ENV=production bun --bun turbo build",

packages/persistence/src/ctx.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { inject, singleton } from "@undb/di"
1+
import { inject,singleton } from "@undb/di"
22
import { AsyncLocalStorage } from "node:async_hooks"
33
import type { ITxContext } from "./ctx.interface"
44
import { injectQueryBuilder } from "./qb.provider"
5-
import type { AnonymousTx, IQueryBuilder, Tx } from "./qb.type"
5+
import type { AnonymousTx,IQueryBuilder,Tx } from "./qb.type"
66

77
export interface TxContext {
88
trx: Tx | AnonymousTx
@@ -22,15 +22,21 @@ export class TxContextImpl implements ITxContext {
2222

2323
withTransaction<T = any>(callback: () => Promise<T>): Promise<T> {
2424
return this.qb.transaction().execute(async (trx) => {
25-
return new Promise(async (resolve, reject) => {
26-
this.startTransaction(trx)
27-
try {
28-
const result = await callback()
29-
resolve(result)
30-
} catch (error) {
31-
reject(error)
32-
}
33-
})
25+
let storeExisted = false
26+
const currentStore = this.context.getStore()
27+
if (currentStore?.trx) {
28+
storeExisted = true
29+
return callback()
30+
}
31+
32+
// 创建新事务上下文
33+
this.startTransaction(trx);
34+
try {
35+
const result = await callback();
36+
return result;
37+
} catch (error) {
38+
throw error;
39+
}
3440
})
3541
}
3642

0 commit comments

Comments
 (0)