(dbName string, handler ManagedQueryHandler)
| 25 | } |
| 26 | |
| 27 | func (gj *graphjinEngine) initManagedQueryTablesForDatabase(dbName string, handler ManagedQueryHandler) error { |
| 28 | if handler == nil { |
| 29 | return nil |
| 30 | } |
| 31 | dbctx := gj.databases[dbName] |
| 32 | if dbctx == nil { |
| 33 | return fmt.Errorf("managed query handler database %q not configured", dbName) |
| 34 | } |
| 35 | if dbctx.dbinfo == nil { |
| 36 | return fmt.Errorf("managed query handler database %q has no schema metadata", dbName) |
| 37 | } |
| 38 | schema := dbctx.dbinfo.Schema |
| 39 | for _, table := range handler.ManagedQueryTables() { |
| 40 | if strings.TrimSpace(table.Name) == "" { |
| 41 | return fmt.Errorf("managed query table name is required") |
| 42 | } |
| 43 | if !strings.HasPrefix(table.Name, "gj_") { |
| 44 | return fmt.Errorf("managed query table %q must use reserved gj_ prefix", table.Name) |
| 45 | } |
| 46 | if _, err := dbctx.dbinfo.GetTable(schema, table.Name); err == nil { |
| 47 | return fmt.Errorf("reserved GraphJin system table %q conflicts with an existing table", table.Name) |
| 48 | } |
| 49 | dbctx.dbinfo.AddTable(managedDBTable(schema, table)) |
| 50 | } |
| 51 | return nil |
| 52 | } |
| 53 | |
| 54 | func managedDBTable(schema string, table ManagedTable) sdata.DBTable { |
| 55 | cols := make([]sdata.DBColumn, 0, len(table.Columns)) |
no test coverage detected