31 lines
867 B
Markdown
31 lines
867 B
Markdown
# ORM Schema Generation
|
|
|
|
`OrmSchema` builds a `TableSpec` from annotated entities.
|
|
|
|
## Example
|
|
|
|
```java
|
|
import com.andrewkydev.database.orm.OrmSchema;
|
|
import com.andrewkydev.database.schema.SqlDialect;
|
|
import com.andrewkydev.database.schema.TableSpec;
|
|
|
|
TableSpec spec = OrmSchema.fromEntity(PlayerModel.class, SqlDialect.MYSQL);
|
|
api.schema().createTable(spec);
|
|
```
|
|
|
|
## Type Mapping
|
|
|
|
Default mapping (when `@DbColumn(type = "...")` is not specified):
|
|
|
|
- `String` -> `VARCHAR(length)`
|
|
- `int`/`Integer` -> `INT`
|
|
- `long`/`Long` -> `BIGINT`
|
|
- `short`/`Short` -> `SMALLINT`
|
|
- `boolean`/`Boolean` -> `BOOLEAN` (PostgreSQL) or `TINYINT(1)` (MySQL)
|
|
- `float`/`Float` -> `FLOAT`
|
|
- `double`/`Double` -> `DOUBLE`
|
|
- `UUID` -> `UUID` (PostgreSQL) or `CHAR(36)` (MySQL)
|
|
- `@DbJson` -> `JSON` (MySQL) or `JSONB` (PostgreSQL)
|
|
|
|
`@DbColumn(length, unique, nullable)` is also applied.
|