Skip to content

Commit

Permalink
fix: fix create table handon
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Jan 9, 2025
1 parent 5a885d7 commit afafcfb
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/persistence/src/table/table.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,26 @@ export class TableRepository implements ITableRepository {
}

async find(spec: Option<TableComositeSpecification>, ignoreSpace?: boolean): Promise<TableDo[]> {
const query = this.qb
const tx = this.txContext.getCurrentTransaction()
const query = tx
.selectFrom("undb_table")
.selectAll("undb_table")
.$if(spec.isSome(), (qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
.where((eb) =>
new TableDbQuerySpecHandler(this.qb, eb, this.context.mustGetCurrentSpaceId(), ignoreSpace).handle(spec),
new TableDbQuerySpecHandler(tx, eb, this.context.mustGetCurrentSpaceId(), ignoreSpace).handle(spec),
)
const tbs = await query.execute()

return tbs.map((t) => this.mapper.toDo(t))
}

async findOne(spec: Option<TableComositeSpecification>): Promise<Option<TableDo>> {
const tb = await this.qb
const tx = this.txContext.getCurrentTransaction()
const tb = await tx
.selectFrom("undb_table")
.selectAll("undb_table")
.$if(spec.isSome(), (qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
.where((eb) => new TableDbQuerySpecHandler(this.qb, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
.where((eb) => new TableDbQuerySpecHandler(tx, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
.executeTakeFirst()

if (!tb) {
Expand All @@ -203,24 +205,25 @@ export class TableRepository implements ITableRepository {

async findOneById(id: TableId): Promise<Option<TableDo>> {
const spec = Some(new TableIdSpecification(id))
const tb = await this.qb
const tx = this.txContext.getCurrentTransaction()
const tb = await tx
.selectFrom("undb_table")
.selectAll("undb_table")
.$call((qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
.where((eb) => new TableDbQuerySpecHandler(this.qb, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
.where((eb) => new TableDbQuerySpecHandler(tx, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
.executeTakeFirst()

return tb ? Some(this.mapper.toDo(tb)) : None
}

async findManyByIds(ids: TableId[]): Promise<TableDo[]> {
const spec = Some(new TableIdsSpecification(ids))
const tbs = await this.txContext
.getCurrentTransaction()
const tx = this.txContext.getCurrentTransaction()
const tbs = await tx
.selectFrom("undb_table")
.selectAll("undb_table")
.$call((qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
.where((eb) => new TableDbQuerySpecHandler(this.qb, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
.where((eb) => new TableDbQuerySpecHandler(tx, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
.execute()

return tbs.map((t) => this.mapper.toDo(t))
Expand Down

0 comments on commit afafcfb

Please sign in to comment.