Skip to content

Commit

Permalink
chore: remove db query spec handler
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Jan 10, 2025
1 parent f54b0c4 commit fbf55c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 34 deletions.
23 changes: 0 additions & 23 deletions packages/persistence/src/table/table-db.query-spec-handler.ts

This file was deleted.

9 changes: 9 additions & 0 deletions packages/persistence/src/table/table.filter-visitor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Option } from "@undb/domain"
import type {
DuplicatedTableSpecification,
ITableSpecVisitor,
TableBaseIdSpecification,
TableComositeSpecification,
TableDo,
TableFormsSpecification,
TableIdSpecification,
Expand Down Expand Up @@ -53,6 +55,13 @@ export class TableFilterVisitor extends AbstractQBVisitor<TableDo> implements IT
this.addCond(this.eb.eb("undb_table.space_id", "=", spaceId))
}
}
$where(spec: Option<TableComositeSpecification>) {
if (spec.isSome()) {
spec.unwrap().accept(this)
}

return this.cond
}
withSpaceId(id: TableSpaceIdSpecification): void {
this.addCond(this.eb.eb("undb_table.space_id", "=", id.spaceId))
}
Expand Down
8 changes: 4 additions & 4 deletions packages/persistence/src/table/table.query-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "@undb/table"
import { injectQueryBuilder } from "../qb.provider"
import type { IQueryBuilder } from "../qb.type"
import { TableDbQuerySpecHandler } from "./table-db.query-spec-handler"
import { TableFilterVisitor } from "./table.filter-visitor"
import { TableMapper } from "./table.mapper"
import { TableReferenceVisitor } from "./table.reference-visitor"

Expand All @@ -32,7 +32,7 @@ export class TableQueryRepository implements ITableQueryRepository {
.selectFrom("undb_table")
.selectAll()
.$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 TableFilterVisitor(this.qb, eb, this.context.mustGetCurrentSpaceId()).$where(spec))
.execute()

return tbs.map((r) => this.mapper.toDTO(r))
Expand All @@ -43,7 +43,7 @@ export class TableQueryRepository implements ITableQueryRepository {
.selectFrom("undb_table")
.selectAll()
.$call((qb) => new TableReferenceVisitor(qb).call(spec))
.where((eb) => new TableDbQuerySpecHandler(this.qb, eb, this.context.mustGetCurrentSpaceId()).handle(Some(spec)))
.where((eb) => new TableFilterVisitor(this.qb, eb, this.context.mustGetCurrentSpaceId()).$where(Some(spec)))
.executeTakeFirst()

return tb ? Some(this.mapper.toDTO(tb)) : None
Expand All @@ -55,7 +55,7 @@ export class TableQueryRepository implements ITableQueryRepository {
.selectFrom("undb_table")
.selectAll()
.$call((qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
.where((eb) => new TableDbQuerySpecHandler(this.qb, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
.where((eb) => new TableFilterVisitor(this.qb, eb, this.context.mustGetCurrentSpaceId()).$where(spec))
.executeTakeFirst()

return tb ? Some(this.mapper.toDTO(tb)) : None
Expand Down
12 changes: 5 additions & 7 deletions packages/persistence/src/table/table.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { injectQueryBuilder } from "../qb.provider"
import type { IQueryBuilder } from "../qb.type"
import { json } from "../qb.util"
import { UnderlyingTableService } from "../underlying/underlying-table.service"
import { TableDbQuerySpecHandler } from "./table-db.query-spec-handler"
import { TableFilterVisitor } from "./table.filter-visitor"
import { TableMapper } from "./table.mapper"
import { TableMutationVisitor } from "./table.mutation-visitor"
import { TableReferenceVisitor } from "./table.reference-visitor"
Expand Down Expand Up @@ -179,9 +179,7 @@ export class TableRepository implements ITableRepository {
.selectFrom("undb_table")
.selectAll("undb_table")
.$if(spec.isSome(), (qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
.where((eb) =>
new TableDbQuerySpecHandler(tx, eb, this.context.mustGetCurrentSpaceId(), ignoreSpace).handle(spec),
)
.where((eb) => new TableFilterVisitor(tx, eb, this.context.mustGetCurrentSpaceId(), ignoreSpace).$where(spec))
const tbs = await query.execute()

return tbs.map((t) => this.mapper.toDo(t))
Expand All @@ -193,7 +191,7 @@ export class TableRepository implements ITableRepository {
.selectFrom("undb_table")
.selectAll("undb_table")
.$if(spec.isSome(), (qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
.where((eb) => new TableDbQuerySpecHandler(tx, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
.where((eb) => new TableFilterVisitor(tx, eb, this.context.mustGetCurrentSpaceId()).$where(spec))
.executeTakeFirst()

if (!tb) {
Expand All @@ -210,7 +208,7 @@ export class TableRepository implements ITableRepository {
.selectFrom("undb_table")
.selectAll("undb_table")
.$call((qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
.where((eb) => new TableDbQuerySpecHandler(tx, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
.where((eb) => new TableFilterVisitor(tx, eb, this.context.mustGetCurrentSpaceId()).$where(spec))
.executeTakeFirst()

return tb ? Some(this.mapper.toDo(tb)) : None
Expand All @@ -223,7 +221,7 @@ export class TableRepository implements ITableRepository {
.selectFrom("undb_table")
.selectAll("undb_table")
.$call((qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
.where((eb) => new TableDbQuerySpecHandler(tx, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
.where((eb) => new TableFilterVisitor(tx, eb, this.context.mustGetCurrentSpaceId()).$where(spec))
.execute()

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

0 comments on commit fbf55c5

Please sign in to comment.