Skip to content

Support custom namespaces for dg_ctl create model(#1591)#2539

Merged
an-tao merged 1 commit into
drogonframework:masterfrom
two-headBoy:master
Jul 13, 2026
Merged

Support custom namespaces for dg_ctl create model(#1591)#2539
an-tao merged 1 commit into
drogonframework:masterfrom
two-headBoy:master

Conversation

@two-headBoy

Copy link
Copy Markdown
Contributor

Description

This PR resolves feature request #1591, decoupling generated model namespace from raw database name and providing two ways to customize namespace: command line argument --namespace and namespace field in model.json.

Changes

1. Command Entry & Header Definition

  • drogon_ctl/create.cc
    Update command help text to document --namespace option
  • drogon_ctl/create_model.h
    Add namespaceName_ and namespaceOverridden_ member variables

2. Core Logic File

  • drogon_ctl/create_model.cc
    • Add parsing logic for --namespace CLI argument
    • Read namespace value from model.json as fallback when no CLI override
    • Inject namespaceName_ into template render data for PG/MySQL/SQLite three database branches

3. Template Files (Dynamic Namespace Generation)

  • drogon_ctl/templates/model_h.csp
    Dynamically generate namespace bracket blocks and closing comment
  • drogon_ctl/templates/model_cc.csp
    Rewrite using namespace splicing logic to use custom namespace
  • drogon_ctl/templates/restful_controller_base_h.csp
    Adapt using statement template
  • drogon_ctl/templates/restful_controller_custom_h.csp
    Adapt using statement template

4. Test Script

  • test.sh
    Add full SQLite test cases covering:
    • Config priority
    • CLI override
    • Empty namespace scenarios

Closes #1591

@an-tao an-tao merged commit 115e7ee into drogonframework:master Jul 13, 2026
34 checks passed
@an-tao

an-tao commented Jul 13, 2026

Copy link
Copy Markdown
Member

@two-headBoy Thanks so much for your patch.

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.

dg_ctl create model -- support namespaces

2 participants