Skip to content

Support nested folders in config/queries/ for query organization #218

@C0dingMast3r

Description

@C0dingMast3r

Support nested folders in config/queries/ for query organization

Problem

As the number of SQL queries in a project grows, config/queries/ becomes a flat bag of files with no way to organize them by feature or domain. The only option is naming conventions (e.g. nego_chart_data.sql, trip_summary.sql), which doesn't scale well and provides no structural separation.

Current behavior

  • AppManager hardcodes queriesDir to path.resolve(process.cwd(), "config/queries")
  • fs.readdir() is non-recursive — subdirectories are silently ignored
  • Query key validation (/^[a-zA-Z0-9_-]+$/) rejects any delimiter that could encode a path
  • generate-types (typegen) also uses flat readdir + path.basename

Proposed behavior

Allow queries to live in subdirectories:

config/queries/
  negotiations/
    chart_data.sql
    spend_summary.sql
  dashboard/
    trip_summary.sql
    trips_by_day.sql
  docs/
    annotations.obo.sql

Query key derivation would use the relative path with a separator (e.g. / or .):

  • negotiations/chart_data or negotiations.chart_data

Frontend usage:

useAnalyticsQuery('negotiations/chart_data', params)

Minimal change required

The fix is small — roughly 3-4 locations need updating:

  1. AppManager.getAppQuery() — change fs.readdir() to fs.readdir(dir, { recursive: true }) and adjust filename matching to include relative subdirectory paths
  2. getQueries() in plugins/server/utils.js — same recursive readdir change
  3. generateQueriesFromDescribe() in typegen — derive query names from relative paths instead of just path.basename()
  4. Query key validation regex — allow / or . as a path separator

Workarounds

Currently using prefix naming (nego_*, trip_*) which works but doesn't provide IDE folder navigation or structural grouping benefits.

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