In my daily work, I like to use MySQL Workbench's data model tools to track and manage changes to the database and to generate the documentation needed for management. However, whenever the structure of the database changes slightly, it is also necessary to modify the ORM settings script written using SQLAlchemy. While using Sqlsoup, you can use the primary functionality of SQLAlchemy without configuring ORM, but is it possible to automatically generate scripts from existing databases? Search the internet for a bit, found the utility called Sqlautocode. Simply execute the sqlautocode command on the command line to automatically generate code based on the parameters!
Its invocation format is as follows:
Sqlautocode <database_url> [Options,]
database_url is the database we configured when we use SQLAlchemy url , some people also used to call it
-H,--help
Display Help information
-O OUTPUT,--output=output
The file to be written by default is stdout
--force
Overwrite the file to be written
-S SCHEMA,--schema=schema
Optional parameters to reverse map the specified database
-T TABLES,--tables=tables
Optional parameter, a comma-separated list that specifies the name of the table to reverse-engineer, supporting * as a wildcard character, for example:
--tables Account_*,orders,order_items,*_audit
-B table_prefix,--table-prefix=table_prefix
The prefix of the generated Sqlaclhemy Table object
-A table_suffix,--table-suffix=table_suffix
The suffix of the generated Sqlaclhemy Table object
-I.,--noindexes,--noindex
Do not generate index information
-G,--generic-types
Build is using ANSI-compliant field types instead of database-specific types
--encoding=encoding
The encoding used by the output file, which defaults to UTF8
-E,--example
Sample code to generate access to data at the same time
-3,--z3c
Generate code for Z3c.sqlalchemy
-D,--declarative
Generate code that uses SQLAlchemy declarative
-N,--interactive
The generated code contains an interactive example
Use Sqlautocode to automatically generate SQLAlchemy ORM settings scripts