Skip to content

Commit

Permalink
Merge pull request #2194 from undb-io/release/v1.0.0-137
Browse files Browse the repository at this point in the history
Release version v1.0.0-137
  • Loading branch information
nichenqin authored Jan 9, 2025
2 parents 28d22b7 + a1536a2 commit b1a5b39
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 95 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## v1.0.0-137


### 🩹 Fixes

- Fix create table handon ([afafcfb](https://github.com/undb-io/undb/commit/afafcfb))

### ❤️ Contributors

- Nichenqin ([@nichenqin](http://github.com/nichenqin))

## v1.0.0-136


Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ docker run -p 3721:3721 ghcr.io/undb-io/undb:latest
```bash
docker run -d \
-p 3721:3721 \
-v $(pwd)/undb.sqlite:/usr/src/app/undb.sqlite \
-v $(pwd)/undb:/usr/src/app/undb \
-v $(pwd)/undb:/usr/src/app/.undb/storage
-v $(pwd)/undb:/usr/src/app/.undb \
--name undb \
ghcr.io/undb-io/undb:latest
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "undb",
"version": "1.0.0-136",
"version": "1.0.0-137",
"private": true,
"scripts": {
"build": "NODE_ENV=production bun --bun turbo build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
DashboardBaseIdSpecification,
DashboardTableIdSpecification,
DashboardUniqueSpecification,
IDashboardSpecification,
IDashboardSpecVisitor,
WithDashboardDescription,
WithDashboardId,
Expand All @@ -26,6 +27,11 @@ export class DashboardFilterVisitor extends AbstractQBVisitor<Dashboard> impleme
super(eb)
}

$where(spec: IDashboardSpecification) {
spec.accept(this)
return this.cond
}

withDescription(v: WithDashboardDescription): void {
this.addCond(this.eb.eb("description", "=", v.description ?? null))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
DashboardTableIdSpecification,
DashboardUniqueSpecification,
DuplicatedDashboardSpecification,
IDashboardSpecification,
IDashboardSpecVisitor,
WithDashboardDescription,
WithDashboardId,
Expand All @@ -25,6 +26,11 @@ export class DashboardMutateVisitor extends AbstractQBMutationVisitor implements
super()
}

$mutate(spec: IDashboardSpecification) {
spec.accept(this)
return this
}

withUniqueDashboard(v: DashboardUniqueSpecification): void {}
withDescription(v: WithDashboardDescription): void {
this.setData("description", v.description ?? null)
Expand Down
16 changes: 3 additions & 13 deletions packages/persistence/src/dashboard/dashboard.query-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,8 @@ export class DashboardQueryRepository implements IDashboardQueryRepository {
const dashboards = await qb
.selectFrom("undb_dashboard")
.selectAll()
.$if(spec.isSome(), (qb) => new DashboardReferenceVisitor(qb).call(spec.unwrap()))
.where((eb) => {
const visitor = new DashboardFilterVisitor(eb, qb)
if (spec.isSome()) {
spec.unwrap().accept(visitor)
}
return visitor.cond
})
.$if(spec.isSome(), (sb) => new DashboardReferenceVisitor(sb).call(spec.unwrap()))
.$if(spec.isSome(), (sb) => sb.where((eb) => new DashboardFilterVisitor(eb, qb).$where(spec.unwrap())))
.execute()

return dashboards.map((b) => this.mapper.toDTO(b))
Expand All @@ -51,11 +45,7 @@ export class DashboardQueryRepository implements IDashboardQueryRepository {
.selectFrom("undb_dashboard")
.selectAll()
.$call((qb) => new DashboardReferenceVisitor(qb).call(spec))
.where((eb) => {
const visitor = new DashboardFilterVisitor(eb, qb)
spec.accept(visitor)
return visitor.cond
})
.where((eb) => new DashboardFilterVisitor(eb, qb).$where(spec))
.executeTakeFirst()

return dashboard ? Some(this.mapper.toDTO(dashboard)) : None
Expand Down
22 changes: 5 additions & 17 deletions packages/persistence/src/dashboard/dashboard.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ export class DashboardRepository implements IDashboardRepository {
.selectFrom("undb_dashboard")
.selectAll()
.$call((qb) => new DashboardReferenceVisitor(qb).call(spec))
.where((eb) => {
const visitor = new DashboardFilterVisitor(eb, this.qb)
spec.accept(visitor)
return visitor.cond
})
.where((eb) => new DashboardFilterVisitor(eb, this.qb).$where(spec))
.execute()

return dashboards.map((dashboard) => this.mapper.toDo(dashboard))
Expand All @@ -53,11 +49,7 @@ export class DashboardRepository implements IDashboardRepository {
.selectFrom("undb_dashboard")
.selectAll()
.$call((qb) => new DashboardReferenceVisitor(qb).call(spec))
.where((eb) => {
const visitor = new DashboardFilterVisitor(eb, this.qb)
spec.accept(visitor)
return visitor.cond
})
.where((eb) => new DashboardFilterVisitor(eb, this.qb).$where(spec))
.executeTakeFirst()

return dashboard ? Some(this.mapper.toDo(dashboard)) : None
Expand All @@ -70,11 +62,7 @@ export class DashboardRepository implements IDashboardRepository {
.selectFrom("undb_dashboard")
.selectAll()
.$call((qb) => new DashboardReferenceVisitor(qb).call(spec))
.where((eb) => {
const visitor = new DashboardFilterVisitor(eb, this.qb)
spec.accept(visitor)
return visitor.cond
})
.where((eb) => new DashboardFilterVisitor(eb, this.qb).$where(spec))
.executeTakeFirst()

return dashboard ? Some(this.mapper.toDo(dashboard)) : None
Expand Down Expand Up @@ -115,8 +103,7 @@ export class DashboardRepository implements IDashboardRepository {
const userId = this.context.mustGetCurrentUserId()

const qb = this.txContext.getCurrentTransaction()
const visitor = new DashboardMutateVisitor(dashboard, qb)
spec.accept(visitor)
const visitor = new DashboardMutateVisitor(dashboard, qb).$mutate(spec)

await qb
.updateTable("undb_dashboard")
Expand All @@ -127,6 +114,7 @@ export class DashboardRepository implements IDashboardRepository {
for (const sql of visitor.sql) {
await qb.executeQuery(sql)
}

await this.outboxService.save(dashboard)
}

Expand Down
8 changes: 1 addition & 7 deletions packages/persistence/src/record/record-query.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ export class RecordQueryHelper {
return qb
.selectFrom(table.id.value)
.$call((qb) => new RecordReferenceVisitor(qb, table).join(visibleFields))
.$call((qb) => {
const visitor = new RecordSpecReferenceVisitor(qb, table)
if (spec.isSome()) {
spec.unwrap().accept(visitor)
}
return visitor.join()
})
.$if(spec.isSome(), (qb) => new RecordSpecReferenceVisitor(qb, table).$join(spec.unwrap()))
.select((sb) => new RecordSelectFieldVisitor(t, foreignTables, sb).$select(visibleFields))
}

Expand Down
8 changes: 4 additions & 4 deletions packages/persistence/src/record/record-reference-visitor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
DateRangeField,
ID_TYPE,
PercentageField,
type AttachmentField,
type AutoIncrementField,
type ButtonField,
Expand All @@ -10,14 +7,18 @@ import {
type CreatedByField,
type CurrencyField,
type DateField,
type DateRangeField,
type DurationField,
type EmailField,
type Field,
type FormulaField,
ID_TYPE,
type IFieldVisitor,
type IdField,
type JsonField,
type LongTextField,
type NumberField,
type PercentageField,
type RatingField,
type ReferenceField,
type RollupField,
Expand All @@ -29,7 +30,6 @@ import {
type UrlField,
type UserField,
} from "@undb/table"
import type { FormulaField } from "@undb/table/src/modules/schema/fields/variants/formula-field"
import type { SelectQueryBuilder } from "kysely"

export class RecordReferenceVisitor implements IFieldVisitor {
Expand Down
60 changes: 30 additions & 30 deletions packages/persistence/src/record/record-select-field-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { createDisplayFieldName } from "./record-utils"
export class RecordSelectFieldVisitor implements IFieldVisitor {
#select: SelectExpression<any, any>[] = []

addSelect(select: SelectExpression<any, any>): void {
#addSelect(select: SelectExpression<any, any>): void {
this.#select.push(select)
}

Expand All @@ -60,7 +60,7 @@ export class RecordSelectFieldVisitor implements IFieldVisitor {
private readonly foreignTables: Map<string, TableDo>,
private readonly eb: ExpressionBuilder<any, string>,
) {
this.addSelect(this.getField(ID_TYPE))
this.#addSelect(this.getField(ID_TYPE))
}

#selectSingelUser(field: UserField | CreatedByField | UpdatedByField) {
Expand All @@ -83,70 +83,70 @@ export class RecordSelectFieldVisitor implements IFieldVisitor {
.limit(1)
.as(as)

this.addSelect(name)
this.#addSelect(name)
}

select(field: SelectField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}

longText(field: LongTextField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}

id(field: IdField): void {
// this.addSelect(this.getField(field.id.value))
}
autoIncrement(field: AutoIncrementField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
createdAt(field: CreatedAtField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
createdBy(field: CreatedByField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
this.#selectSingelUser(field)
}
updatedBy(field: UpdatedByField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
this.#selectSingelUser(field)
}
updatedAt(field: UpdatedAtField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
string(field: StringField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
number(field: NumberField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
button(field: ButtonField): void {}
currency(field: CurrencyField): void {
const fieldName = this.getField(field.id.value)
const selection = sql`${sql.raw(fieldName)} / 100.0`.as(field.id.value)
this.addSelect(selection)
this.#addSelect(selection)
}
rating(field: RatingField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
email(field: EmailField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
url(field: UrlField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
json(field: JsonField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
duration(field: DurationField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
percentage(field: PercentageField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
reference(field: ReferenceField): void {
const select = `${field.id.value}.${field.id.value} as ${field.id.value}`
this.addSelect(select)
this.#addSelect(select)

const name = createDisplayFieldName(field)

Expand All @@ -163,37 +163,37 @@ export class RecordSelectFieldVisitor implements IFieldVisitor {
)
.as(name)

this.addSelect(select)
this.#addSelect(select)
}
}
rollup(field: RollupField): void {
const select = `${field.referenceFieldId}.${field.id.value} as ${field.id.value}`
this.addSelect(select)
this.#addSelect(select)
}
formula(field: FormulaField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
attachment(field: AttachmentField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
date(field: DateField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
dateRange(field: DateRangeField): void {
const { start, end } = getDateRangeFieldName(field)
this.addSelect(this.eb.fn("json_array", [this.getField(start), this.getField(end)]).as(field.id.value))
this.#addSelect(this.eb.fn("json_array", [this.getField(start), this.getField(end)]).as(field.id.value))
}
checkbox(field: CheckboxField): void {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
}
user(field: UserField): void {
const as = createDisplayFieldName(field)
if (field.isSingle) {
this.addSelect(this.getField(field.id.value))
this.#addSelect(this.getField(field.id.value))
this.#selectSingelUser(field)
} else {
this.addSelect(this.getField(field.id.value))
this.addSelect(
this.#addSelect(this.getField(field.id.value))
this.#addSelect(
this.eb
.case()
.when(`${this.table.name}.${field.id.value}`, "is", null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
UrlEqual,
UserEmpty,
UserEqual,
type IRecordComositeSpecification,
type IRecordVisitor,
type TableDo,
} from "@undb/table"
Expand All @@ -70,7 +71,8 @@ export class RecordSpecReferenceVisitor implements IRecordVisitor {
private readonly table: TableDo,
) {}

join() {
$join(spec: IRecordComositeSpecification) {
spec.accept(this)
return this.qb
}

Expand Down
Loading

0 comments on commit b1a5b39

Please sign in to comment.