@@ -45,7 +45,7 @@ type Param struct {
4545 HideResetButton bool `json:"hide_reset_button"`
4646 HideBackButton bool `json:"hide_back_button"`
4747
48- TablePageTitle string `json:"table_title "`
48+ TablePageTitle string `json:"table_page_title "`
4949 TableDescription string `json:"table_description"`
5050 FormTitle string `json:"form_title"`
5151 FormDescription string `json:"form_description"`
@@ -59,6 +59,9 @@ type Param struct {
5959 FormFields Fields `json:"form_fields"`
6060 DetailFields Fields `json:"detail_fields"`
6161
62+ PrimaryKey string `json:"primary_key"`
63+ PrimaryKeyType string `json:"primary_key_type"`
64+
6265 DetailDisplay uint8 `json:"detail_display"`
6366
6467 Output string `json:"output"`
@@ -123,6 +126,8 @@ func NewParam(cfg Config) *Param {
123126 fields := getFieldsFromConn (cfg .Conn , dbTable , cfg .Driver )
124127 tt := strings .Title (ta )
125128
129+ pkey , ptype := fields .GetPrimaryKey ()
130+
126131 return & Param {
127132 Connection : cfg .Connection ,
128133 Driver : cfg .Driver ,
@@ -156,6 +161,9 @@ func NewParam(cfg Config) *Param {
156161 TableDescription : utils .SetDefault (cfg .TableDescription , "" , tt ),
157162 FormTitle : utils .SetDefault (cfg .FormTitle , "" , tt ),
158163 FormDescription : utils .SetDefault (cfg .FormDescription , "" , tt ),
164+
165+ PrimaryKey : pkey ,
166+ PrimaryKeyType : ptype ,
159167 }
160168}
161169
@@ -218,6 +226,15 @@ func NewParamWithFields(cfg Config, fields ...Fields) *Param {
218226
219227type Fields []Field
220228
229+ func (fs Fields ) GetPrimaryKey () (string , string ) {
230+ for _ , field := range fs {
231+ if field .IsPrimaryKey {
232+ return field .Name , field .DBType
233+ }
234+ }
235+ return "" , ""
236+ }
237+
221238type Field struct {
222239 Head string `json:"head"`
223240 Name string `json:"name"`
@@ -234,6 +251,7 @@ type Field struct {
234251 Default string `json:"default"`
235252 CanAdd bool `json:"can_add"`
236253 ExtraFun string `json:"extra_fun"`
254+ IsPrimaryKey bool `json:"is_primary_key"`
237255}
238256
239257func Generate (param * Param ) error {
@@ -442,13 +460,19 @@ func getFieldsFromConn(conn db.Connection, table, driver string) Fields {
442460
443461 for i , model := range columnsModel {
444462 typeName := getType (model [typeField ].(string ))
463+ isPrimaryKey := false
464+ if columnKey , ok := model ["Key" ].(string ); ok {
465+ isPrimaryKey = columnKey == "PRI"
466+ }
467+
445468 fields [i ] = Field {
446- Head : strings .Title (model [fieldField ].(string )),
447- Name : model [fieldField ].(string ),
448- DBType : typeName ,
449- CanAdd : true ,
450- Editable : true ,
451- FormType : form .GetFormTypeFromFieldType (db .DT (strings .ToUpper (typeName )), model [fieldField ].(string )),
469+ Head : strings .Title (model [fieldField ].(string )),
470+ Name : model [fieldField ].(string ),
471+ DBType : typeName ,
472+ CanAdd : true ,
473+ Editable : true ,
474+ IsPrimaryKey : isPrimaryKey ,
475+ FormType : form .GetFormTypeFromFieldType (db .DT (strings .ToUpper (typeName )), model [fieldField ].(string )),
452476 }
453477 if model [fieldField ].(string ) == "id" {
454478 fields [i ].Filterable = true
0 commit comments