Skip to content

feat: Query builder support for GROUP BY / GROUP ALL aggregations #1

@albedosehen

Description

@albedosehen

Context

Kushtaka uses surql-py for SurrealDB access. During refactoring (#387), we found that aggregation queries (GROUP BY, GROUP ALL, count(), math::mean, math::sum) cannot be expressed with the typed CRUD helpers and must fall back to raw SurrealQL strings.

Examples that need support

# Current (raw SurrealQL):
await query('SELECT network, count() AS count FROM memory_entry GROUP BY network')
await query('SELECT math::mean(strength) AS avg FROM memory_entry GROUP ALL')
await query('SELECT count() AS total, math::sum(tokens_used) AS tokens FROM task GROUP ALL')

# Desired (typed):
await query_records('memory_entry', select=['network', count('*').as_('count')], group_by='network')

Patterns needed

  • GROUP BY field and GROUP ALL
  • count() aggregate
  • math::mean(), math::sum(), math::max(), math::min()
  • Aliased select fields (AS)
  • Combining aggregates with filters

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions