MCPcopy Index your code
hub / github.com/LUSHDigital/modelgen

github.com/LUSHDigital/modelgen @1.4.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.4.4 ↗ · + Follow
43 symbols 76 edges 10 files 16 documented · 37% updated 7y ago1.4.4 · 2018-10-24★ 85
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Modelgen License Go Report Card Build Status

Modelgen generates working database interaction code from reading your MySQL / MariaDB database.

Install:

brew tap lushdigital/tools
brew install modelgen

This will install modelgen under /usr/local/bin.

If you want to uninstall it, simply delete it, or run brew uninstall modelgen

Conventions:

modelgen assumes your database will follow a couple conventions:

  • tables must have a primary key id field
  • column names must not collide with a valid Go type, ex: string

The primary id doesn't need to auto-increment, though it is recommended.

Ordering:

In cases where you want the migrations to be generated in a particular order (ex. because of foreign key constraints) you can control this by simply adding a comment to your id field.

This format must take the following format:

# for example a the user table id has the comment:
modelgen:1

# then the user_post table id has the comment:
modelgen:2

by doing so you ensure that the user table always gets migrated before the user_post table.

Usage:

Usage:
   [command]

Available Commands:
  generate    Generate models from a database connection
  help        Help about any command
  migrate     Generate migration files from a database connection

Flags:
  -c, --connection string   user:pass@host:port
  -d, --database string     name of database
  -h, --help                help for this command
  -o, --output string       path to package (default "generated_models")
  -p, --package string      name of package (default "generated_models")

Example:

# Create models
modelgen generate -c root:pass@localhost:3306 -d my-db -o models

# Create migrations
modelgen migrate -c root:pass@localhost:3306 -d my-db -o migrations

Visual Aid:

visual.svg

Credit:

Modelgen is built using the following amazing libraries:

Core symbols most depended-on inside this repo

getTables
called by 2
generate.go
GetOrderFromComment
called by 2
generate.go
copyFile
called by 2
generate.go
connect
called by 2
main.go
validate
called by 2
main.go
archive
called by 1
migrate.go
makeMigrations
called by 1
migrate.go
writeModels
called by 1
generate.go

Shape

Function 34
Struct 7
TypeAlias 2

Languages

Go100%

Modules by API surface

tmpl/tmpl.go12 symbols
generate.go7 symbols
migrate.go5 symbols
main.go5 symbols
tmpl/types.go4 symbols
sqltypes/sqltypes.go4 symbols
sqlfmt/sqlfmt.go2 symbols
generate_test.go2 symbols
main-packr.go1 symbols
a_main-packr.go1 symbols

For agents

$ claude mcp add modelgen \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact