- Endpoint:
POST /studio/api/import/models(multipart file upload) - Upload a
.gofile containing struct definitions - The parser extracts struct fields, GORM tags, and type information
- Creates corresponding database tables using CREATE TABLE statements
- Relationship fields (slices, pointers to structs) are automatically skipped
- Only available when ReadOnly is false
Example Input
Upload a .go file:
package models
type Category struct {
ID uint `gorm:"primaryKey"`
Name string `gorm:"size:100;not null"`
Slug string `gorm:"size:100;uniqueIndex"`
}
type Product struct {
ID uint `gorm:"primaryKey"`
Name string `gorm:"size:200;not null"`
Price float64 `gorm:"type:decimal(10,2)"`
CategoryID uint
Category Category // Relationship field - skipped
}How It Works
- Parses Go structs using regex-based extraction
- Reads field names, Go types, and GORM struct tags
- Maps Go types to SQL types based on the database driver
- Skips relationship fields (slices, struct pointers, embedded structs)
- Generates and executes CREATE TABLE statements
Go Type to SQL Type Mapping
| Go Type | SQL Type |
|---|---|
| uint, int, int64 | BIGINT |
| int32 | INTEGER |
| string | VARCHAR(255) |
| bool | BOOLEAN |
| float32, float64 | DOUBLE |
| time.Time | TIMESTAMP |
| []byte | BLOB |
GORM tags override default mappings. For example, gorm:"type:decimal(10,2)" uses DECIMAL(10,2) instead of DOUBLE.
Usage
curl -X POST http://localhost:8080/studio/api/import/models \
-F "file=@models.go"Response
{
"tables_created": ["categories", "products"]
}