# Model/cache generation
`rzcli model gen` provides SQL schema parsing and model/cache skeleton generation:
```bash
rzcli model gen -s examples/model-cache/schema.sql -d target/generated
```
Generated files:
- `Cargo.toml`
- `src/lib.rs`
- `src/entity.rs`
- `src/repository.rs`
- `src/cache.rs`
- `README.md`
The generator emits entity structs, repository trait skeletons, SQLx pool markers when requested, and cache key helpers. It does not implement an ORM, database connection pool inside generated code, Redis topology, migration engine, or database introspection.
## MySQL/goctl default path
The default SQL parser supports a practical MySQL `CREATE TABLE` subset:
- column name and type
- `NOT NULL`
- inline `PRIMARY KEY`
- table-level `PRIMARY KEY`
- `UNIQUE KEY`
- `KEY` / `INDEX`
- `DEFAULT`
- `COMMENT`
- `AUTO_INCREMENT`
- charset/collation/table comment metadata
- composite unique and normal indexes
Default SQLx generation remains SQLite-compatible for backward compatibility:
```bash
rzcli model gen -s examples/model-cache/schema.sql -d target/generated --with-sqlx --with-redis-cache
```
Use an explicit MySQL SQLx backend when the generated skeleton should carry `rs_zero::db::MySqlDatabasePool`:
```bash
rzcli model gen \
-s examples/model-cache/schema.sql \
-d target/generated \
--with-sqlx \
--sqlx-backend mysql \
--with-redis-cache
```
The MySQL type mapper covers common goctl fixture types and practical MySQL types such as unsigned integers, `decimal`, `datetime`, `timestamp`, `date`, `json`, `blob`/`binary`, `text` and `varchar`.
## PostgreSQL path
PostgreSQL support is explicit:
```bash
rzcli model gen \
-s tests/fixtures/postgres/model/user.sql \
-d target/generated \
--dialect postgres \
--with-sqlx \
--with-redis-cache
```
With `--dialect postgres --with-sqlx`, the default SQLx backend is PostgreSQL and generated repositories use `rs_zero::db::PostgresDatabasePool`. Use `--sqlx-backend postgres` when you want the backend choice to be visible in scripts.
The PostgreSQL parser covers the project fixture subset:
- quoted identifiers and schema-qualified table names
- `SERIAL` / `BIGSERIAL`
- `GENERATED ... AS IDENTITY`
- table-level `PRIMARY KEY` and `UNIQUE` constraints
- `CREATE INDEX`
- `COMMENT ON TABLE` and `COMMENT ON COLUMN`
- common PostgreSQL types: integer family, boolean, text/varchar, uuid, json/jsonb, numeric/decimal, timestamp/timestamptz, date and bytea
## Boundaries
Applications still own concrete SQL queries, credentials, transaction boundaries, migration tooling, pool lifecycle and deployment configuration. Default tests do not connect to external MySQL or PostgreSQL services.