feat(cli): add db command for executing raw SQL#27
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Arkorm's equivalent of
artisan db. Executes a raw SQL statement againstthe configured adapter and prints the result as a table (or JSON).
(this.editor) when run with no argument, so a bare
arkorm dblets youcompose a statement.
as JSON. Results render as an aligned table with a row count; empty results
report '0 rows returned'.
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.