Skip to main content
Version: 0.5.x

Using sea-orm-cli

First, install sea-orm-cli with cargo.

$ cargo install sea-orm-cli

Configure Environment

Set DATABASE_URL in your environment, or create a .env file in your project root. Specify your database connection.


Getting Help

Use -h flag on any CLI command or subcommand for help.

# List all available commands
$ sea-orm-cli -h

# List all subcommands available in `generate` command
$ sea-orm-cli generate -h

# Show how to use `generate entity` subcommand
$ sea-orm-cli generate entity -h

Generating Entity Files

Discover all tables in a database and generate a corresponding SeaORM entity file for each table.

Supported databases:

  • MySQL
  • PostgreSQL
  • SQLite

Command line options:

  • -u / --database-url: database URL (default: DATABASE_URL specified in ENV)
  • -s / --database-schema: database schema (default: DATABASE_SCHEMA specified in ENV)
    • For MySQL & SQLite, this argument is ignored
    • For PostgreSQL, this argument is optional with default value 'public'
  • -o / --output-dir: entity file output directory (default: current directory)
  • -v / --verbose: print debug messages
  • --include-hidden-tables: generate entity files from hidden tables (tables with names starting with an underscore are hidden and ignored by default)
  • --compact-format: generate entity file of compact format (default: true)
  • --expanded-format: generate entity file of expanded format
  • --with-serde: automatically derive serde Serialize / Deserialize traits for the entity (none, serialize, deserialize, both) (default: none)
# Generate entity files of database `bakery` to `src/entity`
$ sea-orm-cli generate entity \
-u sql://sea:sea@localhost/bakery \
-o src/entity