You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These inline fields (added recently) allow constraints to be defined directly on columns in addition to table-level `TableConstraint` definitions.
95
99
100
+
### ColumnType Structure
101
+
`ColumnType` is an enum with two variants:
102
+
-`Simple(SimpleColumnType)`: Built-in types like `Integer`, `Text`, `Boolean`, etc.
103
+
-`Complex(ComplexColumnType)`: Types with parameters like `Varchar { length }` or `Custom { custom_type }`
104
+
105
+
**Important**: In Rust code, always use `ColumnType::Simple(SimpleColumnType::Integer)` instead of the old `ColumnType::Integer` syntax. The `From` trait is implemented for convenience:
106
+
```rust
107
+
// These are equivalent:
108
+
ColumnType::Simple(SimpleColumnType::Integer)
109
+
SimpleColumnType::Integer.into()
110
+
```
111
+
112
+
### ColumnType Methods
113
+
`ColumnType` provides two utility methods:
114
+
-`to_sql()`: Returns the PostgreSQL SQL type string (e.g., `"INTEGER"`, `"VARCHAR(255)"`)
115
+
-`to_rust_type(nullable: bool)`: Returns the Rust type string for SeaORM entity generation (e.g., `"i32"` or `"Option<i32>"`)
116
+
117
+
These methods replace the old standalone functions `column_type_sql()` and `rust_type()`.
118
+
96
119
### Foreign Key Definition
97
120
Foreign keys can be defined inline on columns via the `foreign_key` field:
Copy file name to clipboardExpand all lines: SKILL.md
+22-8Lines changed: 22 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,11 @@ Models are JSON files in the `models/` directory:
73
73
74
74
## Column Types
75
75
76
-
### Built-in Types
76
+
Column types in JSON can be either simple (string) or complex (object) values.
77
+
78
+
### Simple Types (Built-in)
79
+
80
+
Simple types are represented as strings in JSON (snake_case):
77
81
78
82
| Type | PostgreSQL | Use Cases |
79
83
|------|------------|-----------|
@@ -96,17 +100,27 @@ Models are JSON files in the `models/` directory:
96
100
|`"cidr"`| CIDR | Network address |
97
101
|`"macaddr"`| MACADDR | MAC address |
98
102
99
-
### Custom Types
103
+
**Note**: In JSON, simple types are written as lowercase strings (e.g., `"integer"`, `"text"`). The Rust enum uses `SimpleColumnType` wrapped in `ColumnType::Simple()`.
100
104
101
-
For types not covered above:
105
+
### Complex Types
102
106
107
+
Complex types are represented as objects with a `kind` field:
**Note**: In Rust code, complex types are represented as `ColumnType::Complex(ComplexColumnType::Varchar { length })` or `ColumnType::Complex(ComplexColumnType::Custom { custom_type })`.
0 commit comments