Skip to content

Commit

Permalink
fix: fix aggregate field
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Nov 21, 2024
1 parent 5d41d37 commit ce0f563
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@
<CreateViewButton
tableId={$table.id.value}
viewNames={$table.views.views.map((v) => v.name.value)}
class="mt-0 p-0 hover:bg-transparent"
class="text-muted-foreground mt-0 p-0 hover:bg-transparent"
variant="ghost"
>
<PlusCircleIcon class="size-3" />
<PlusCircleIcon class="size-4" />
</CreateViewButton>
{/if}
</Breadcrumb.List>
Expand Down
6 changes: 3 additions & 3 deletions packages/persistence/src/record/record.aggregate-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export class AggregateFnBuiler {
public build(): AliasedExpression<any, any> {
const field = this.field
const aggregate = this.aggregate
if (!field && (aggregate === "count_empty" || aggregate === "count")) {
return sql`COUNT(*)`.as("id")
const alias = field?.id.value ?? ID_TYPE
if (!field && aggregate === "count") {
return sql`COUNT(*)`.as(alias)
}
if (!field) {
throw new Error("Field is required for aggregate")
}
const alias = field.id.value
const fieldId = this.table.getFieldName(alias)

const getRef = (field: Field) => {
Expand Down
11 changes: 5 additions & 6 deletions packages/persistence/src/record/record.query-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,6 @@ export class RecordQueryRepository implements IRecordQueryRepository {
const ebs: AliasedExpression<any, any>[] = []

for (const [fieldId, fieldAggregate] of Object.entries(aggregate.unwrap())) {
if (fieldAggregate === "count_empty" || fieldAggregate === "count") {
const builder = new AggregateFnBuiler(t, eb, undefined, fieldAggregate)
ebs.push(builder.build())
continue
}
if (!fieldAggregate) {
continue
}
Expand All @@ -314,7 +309,11 @@ export class RecordQueryRepository implements IRecordQueryRepository {
}
const field = table.schema.fieldMapById.get(fieldId)
if (!field) {
continue
if (fieldAggregate === "count") {
const builder = new AggregateFnBuiler(t, eb, undefined, fieldAggregate)
ebs.push(builder.build())
continue
}
}
const builder = new AggregateFnBuiler(t, eb, field, fieldAggregate)
ebs.push(builder.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const abstractDateAggregate = z.enum([
//
"min",
"max",
"count",
"count_empty",
"count_not_empty",
"count_uniq",
Expand Down

0 comments on commit ce0f563

Please sign in to comment.