Repository navigation
feat(cli): add the model command-line interface - #138
Merged
Merged
Conversation
|
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.



Description
Adds the model-level command-line interface to the core package:
rhosocial.activerecord.cli, exposed as therhosocial-activerecordconsole script and aspython -m rhosocial.activerecord.cli.Motivation: the framework has a complete Python API but no supported way to run model operations from a shell. The CLI gives scripts and agents the same model-level semantics as the Python API without introducing a second ORM or a SQL-string layer.
The CLI is a thin adapter over existing APIs. It never builds SQL: DML calls ActiveRecord methods, DQL calls
ActiveQuery, andset/cteexecute user-suppliedSetOperationQuery/CTEQueryobjects.Command groups:
dml:create,update,delete,bulk create,bulk update,bulk deletedql:get,list,count,exists,aggregate,runset:union,union-all,intersect,except,runcte:runBehaviour highlights:
module:Class; backends and connection configs are named explicitly (--backend-class,--config-class,--connection), with the model module'sconfigure()as the fallback.--yesin a non-interactive context (exit 5), support--dry-run, and reportsoft_deletefor soft-delete models.dql list, groupeddql aggregate, anddql run --mode list|aggregateinject a default limit of 100 and explain it on stderr;--no-limit,--limit 0, and--quietcontrol this.json,jsonl,csv,tsv,value) keep stdout payload-only;tableuses Rich when installed and falls back to JSON otherwise.--data @-,--input-format,--batch-size).RecordNotFoundmaps to CLI-layerCliNotFoundError, keeping the original exception in the chain.--whereis equality-only; complex predicates are expressed throughdql runfactories.Error:prefix.Core robustness included, because the CLI exercised these paths directly:
find_one_or_createkeeps a failed race re-read in__cause__instead of swallowing it.StaleRecordErrorno longer asserts the row was updated; the message says it may have been updated or deleted.Dependencies: no new runtime dependency.
richremains optional (pip install "rhosocial-activerecord[cli]") and only affects-o table.Adds #138
Type of change
feat: A new featuredocs: Documentation only changes (if related to the new feature)test: Adding missing tests or correcting existing tests (for the new feature)perf: A code change that improves performance (if part of the feature)chore: Changes to the build process or auxiliary tools and libraries suchs as documentation generation (if related to the new feature)ci: Changes to our CI configuration files and scripts (if related to the new feature)build: Changes that affect the build system or external dependencies (if related to the new feature)revert: Reverts a previous commitBreaking Change
Impact on End-Users:
No backward-incompatible changes are expected for typical end-user applications. The CLI is additive: existing Python APIs, exception classes, and model behaviour are unchanged. The intermediate
crudcommand group existed only on this feature branch and was replaced bydml/dql/set/ctebefore any release.Impact on Backend Developers (Custom Implementations):
No backward-incompatible changes are expected for backend developers using custom implementations. Backends already provide
StorageBackend/AsyncStorageBackendand dialect implementations; the CLI only consumes them.Related Repositories/Packages
python-activerecord-testsuite(release/v1.0.0.dev17): adds CLI validation contracts (test_cli_validation.py,test_cli_validation_async.py), exposesvalidated_modelin the generic CLI providers, and updates optimistic-lock assertions to the clarifiedStaleRecordErrormessage. Changes are on the pinned testsuite branch; no separate PR.mysql,mariadb,postgres,sqlserver,oracle,snowflake,clickhouse,bigquery,firebird): CLI contract wrappers and provider registrations are already committed on their feature branches. Their CLI CI can only pass once this change is available through a core release that containsrhosocial.activerecord.cli; they must not be rerun before that.python-github-actions-tracker(application): no coordination needed. Its feedback informed the robustness fixes above.Testing
Test Plan:
CI:
654bbc94): 12/12 jobs success (3.8–3.15, including 3.13t / 3.14t / 3.15t and coverage/benchmarks).56bdb62e): 12/12 jobs success.Local verification commands:
Backend/database matrix: not applicable here; the backend CLI wrappers are verified separately once the release branch contains this change.
Checklist
README.md, etc.).changelog.d/<issue_number>.<type>.md).Additional Notes
docs/en_US/clianddocs/zh_CN/cli(DML, bulk DML, DQL, set/CTE, connections, output, errors), withdocs/examples/chapter_13_clicontaining runnable examples that invoke real CLI commands against a temporary SQLite database. Every page ends with guidance for AI agents.--no-limitand--limit 0opt out, and the note is stderr-only so machine output stays clean.rhosocial.activerecord.cli, which does not exist on the release branch yet.DataError/RecordError/ConcurrencyError) are intentionally deferred to a separate change so this PR stays reviewable.