fix(web): expose web_db_table_info for admin schema forms
Wire existing db.TableInfo through the C ABI so offline admin smoke can introspect columns before form_from_schema. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
12d2c7be69
commit
7fab85b389
2 files changed
+32
No files matched your search
@@ -217,6 +217,36 @@ func web_form_submit(argsJSON *C.char, outJSON **C.char, errMsg **C.char) C.int
|
||||
return replyJSON(outJSON, errMsg, out, err)
|
||||
}
|
||||
|
||||
//export web_db_table_info
|
||||
func web_db_table_info(argsJSON *C.char, outJSON **C.char, errMsg **C.char) C.int {
|
||||
args, err := parseArgs(argsJSON)
|
||||
if err != nil {
|
||||
return replyJSON(outJSON, errMsg, nil, err)
|
||||
}
|
||||
url, err := dbURLOf(args)
|
||||
if err != nil {
|
||||
return replyJSON(outJSON, errMsg, nil, err)
|
||||
}
|
||||
tableName, err := argStrReq(args, "table")
|
||||
if err != nil {
|
||||
return replyJSON(outJSON, errMsg, nil, err)
|
||||
}
|
||||
cols, err := db.TableInfo(url, tableName)
|
||||
if err != nil {
|
||||
return replyJSON(outJSON, errMsg, nil, err)
|
||||
}
|
||||
arr := make([]any, len(cols))
|
||||
for i, c := range cols {
|
||||
arr[i] = map[string]any{
|
||||
"name": c.Name,
|
||||
"type": c.SQLType,
|
||||
"notnull": c.NotNull,
|
||||
"pk": c.PK,
|
||||
}
|
||||
}
|
||||
return replyJSON(outJSON, errMsg, map[string]any{"columns": arr}, nil)
|
||||
}
|
||||
|
||||
//export web_form_from_schema
|
||||
func web_form_from_schema(argsJSON *C.char, outJSON **C.char, errMsg **C.char) C.int {
|
||||
args, err := parseArgs(argsJSON)
|
||||
|
||||
@@ -76,6 +76,7 @@ extern int web_db_rollback(char *args_json, char **out_json, char **err_msg);
|
||||
extern int web_db_migrate(char *args_json, char **out_json, char **err_msg);
|
||||
extern int web_db_fts_create(char *args_json, char **out_json, char **err_msg);
|
||||
extern int web_db_search(char *args_json, char **out_json, char **err_msg);
|
||||
extern int web_db_table_info(char *args_json, char **out_json, char **err_msg);
|
||||
extern int web_form_rules(char *args_json, char **out_json, char **err_msg);
|
||||
extern int web_form_validate(char *args_json, char **out_json, char **err_msg);
|
||||
extern int web_form_render(char *args_json, char **out_json, char **err_msg);
|
||||
@@ -158,6 +159,7 @@ static int register_core(void) {
|
||||
if (host_register((char *)"web_db_migrate", (char *)"url,steps", web_db_migrate) != 0) return 1;
|
||||
if (host_register((char *)"web_db_fts_create", (char *)"url,table,columns,name", web_db_fts_create) != 0) return 1;
|
||||
if (host_register((char *)"web_db_search", (char *)"url,table,q,limit,name", web_db_search) != 0) return 1;
|
||||
if (host_register((char *)"web_db_table_info", (char *)"url,table", web_db_table_info) != 0) return 1;
|
||||
if (host_register((char *)"web_form_new", (char *)"table,action,id", web_form_new) != 0) return 1;
|
||||
if (host_register((char *)"web_form_fields", (char *)"form,fields", web_form_fields) != 0) return 1;
|
||||
if (host_register((char *)"web_form_rules", (char *)"form,rules", web_form_rules) != 0) return 1;
|
||||
|
||||
Reference in new issue
Block a user