Skip to content

Commit fbf55c5

Browse files
committed
chore: remove db query spec handler
1 parent f54b0c4 commit fbf55c5

File tree

4 files changed

+18
-34
lines changed

4 files changed

+18
-34
lines changed

packages/persistence/src/table/table-db.query-spec-handler.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/persistence/src/table/table.filter-visitor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import type { Option } from "@undb/domain"
12
import type {
23
DuplicatedTableSpecification,
34
ITableSpecVisitor,
45
TableBaseIdSpecification,
6+
TableComositeSpecification,
57
TableDo,
68
TableFormsSpecification,
79
TableIdSpecification,
@@ -53,6 +55,13 @@ export class TableFilterVisitor extends AbstractQBVisitor<TableDo> implements IT
5355
this.addCond(this.eb.eb("undb_table.space_id", "=", spaceId))
5456
}
5557
}
58+
$where(spec: Option<TableComositeSpecification>) {
59+
if (spec.isSome()) {
60+
spec.unwrap().accept(this)
61+
}
62+
63+
return this.cond
64+
}
5665
withSpaceId(id: TableSpaceIdSpecification): void {
5766
this.addCond(this.eb.eb("undb_table.space_id", "=", id.spaceId))
5867
}

packages/persistence/src/table/table.query-repository.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "@undb/table"
1111
import { injectQueryBuilder } from "../qb.provider"
1212
import type { IQueryBuilder } from "../qb.type"
13-
import { TableDbQuerySpecHandler } from "./table-db.query-spec-handler"
13+
import { TableFilterVisitor } from "./table.filter-visitor"
1414
import { TableMapper } from "./table.mapper"
1515
import { TableReferenceVisitor } from "./table.reference-visitor"
1616

@@ -32,7 +32,7 @@ export class TableQueryRepository implements ITableQueryRepository {
3232
.selectFrom("undb_table")
3333
.selectAll()
3434
.$if(spec.isSome(), (qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
35-
.where((eb) => new TableDbQuerySpecHandler(this.qb, eb, this.context.mustGetCurrentSpaceId()).handle(spec))
35+
.where((eb) => new TableFilterVisitor(this.qb, eb, this.context.mustGetCurrentSpaceId()).$where(spec))
3636
.execute()
3737

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

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

6161
return tb ? Some(this.mapper.toDTO(tb)) : None

packages/persistence/src/table/table.repository.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { injectQueryBuilder } from "../qb.provider"
1818
import type { IQueryBuilder } from "../qb.type"
1919
import { json } from "../qb.util"
2020
import { UnderlyingTableService } from "../underlying/underlying-table.service"
21-
import { TableDbQuerySpecHandler } from "./table-db.query-spec-handler"
21+
import { TableFilterVisitor } from "./table.filter-visitor"
2222
import { TableMapper } from "./table.mapper"
2323
import { TableMutationVisitor } from "./table.mutation-visitor"
2424
import { TableReferenceVisitor } from "./table.reference-visitor"
@@ -179,9 +179,7 @@ export class TableRepository implements ITableRepository {
179179
.selectFrom("undb_table")
180180
.selectAll("undb_table")
181181
.$if(spec.isSome(), (qb) => new TableReferenceVisitor(qb).call(spec.unwrap()))
182-
.where((eb) =>
183-
new TableDbQuerySpecHandler(tx, eb, this.context.mustGetCurrentSpaceId(), ignoreSpace).handle(spec),
184-
)
182+
.where((eb) => new TableFilterVisitor(tx, eb, this.context.mustGetCurrentSpaceId(), ignoreSpace).$where(spec))
185183
const tbs = await query.execute()
186184

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

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

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

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

0 commit comments

Comments
 (0)