Skip to content

feat(cli): add db command for executing raw SQL#27

Merged
3m1n3nc3 merged 3 commits into
mainfrom
feat/db-raw-sql-command
Jul 5, 2026
Merged

feat(cli): add db command for executing raw SQL#27
3m1n3nc3 merged 3 commits into
mainfrom
feat/db-raw-sql-command

Conversation

@3m1n3nc3

@3m1n3nc3 3m1n3nc3 commented Jul 5, 2026

Copy link
Copy Markdown
Member

Arkorm's equivalent of artisan db. Executes a raw SQL statement against
the configured adapter and prints the result as a table (or JSON).

  • SQL source: positional argument, --file=, or an interactive editor
    (this.editor) when run with no argument, so a bare arkorm db lets you
    compose a statement.
  • --bindings= supplies positional ? bindings; --json prints rows
    as JSON. Results render as an aligned table with a row count; empty results
    report '0 rows returned'.
  • Requires an adapter that supports raw queries (Kysely/PostgreSQL); reports a
    clear error otherwise.

Tests: base (fake rawQuery adapter — table/JSON/bindings/file/editor/errors)
and postgres e2e against the Kysely adapter. Docs: 'Run raw SQL' section.

3m1n3nc3 added 3 commits July 5, 2026 05:25
Arkorm's equivalent of `artisan db`. Executes a raw SQL statement against
the configured adapter and prints the result as a table (or JSON).

- SQL source: positional argument, --file=<path>, or an interactive editor
  (this.editor) when run with no argument, so a bare `arkorm db` lets you
  compose a statement.
- --bindings=<json-array> supplies positional ? bindings; --json prints rows
  as JSON. Results render as an aligned table with a row count; empty results
  report '0 rows returned'.
- Requires an adapter that supports raw queries (Kysely/PostgreSQL); reports a
  clear error otherwise.

Tests: base (fake rawQuery adapter — table/JSON/bindings/file/editor/errors)
and postgres e2e against the Kysely adapter. Docs: 'Run raw SQL' section.
The db command read the adapter from a freshly constructed CliApp that had
not applied the user config yet, so it always reported 'Raw queries require a
configured database adapter'. It now calls loadArkormConfig() first (as the
migrate commands do), connecting through the project's configured driver.

Adds a regression test that runs db against an adapter declared only in a
temporary arkormx.config (no pre-set adapter), plus test isolation so config
loading runs in an empty working directory.
Resolve the effective adapter the same way models do — getRuntimeAdapter()
with a getRuntimeCompatibilityAdapter() fallback — so db works whether the
project configures an explicit adapter or a client, and give an accurate
message when the resolved adapter cannot run raw SQL. Also removes a stray
debug console.log and switches the tests to configure the runtime adapter so
they exercise the real resolution path.
@3m1n3nc3 3m1n3nc3 merged commit 0eb7aa8 into main Jul 5, 2026
5 of 6 checks passed
@3m1n3nc3 3m1n3nc3 deleted the feat/db-raw-sql-command branch July 5, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant