MCPcopy
hub / github.com/dosco/graphjin / initManagedQueryTablesForDatabase

Method initManagedQueryTablesForDatabase

core/managed_query.go:27–52  ·  view source on GitHub ↗
(dbName string, handler ManagedQueryHandler)

Source from the content-addressed store, hash-verified

25}
26
27func (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
54func managedDBTable(schema string, table ManagedTable) sdata.DBTable {
55 cols := make([]sdata.DBColumn, 0, len(table.Columns))

Calls 4

managedDBTableFunction · 0.85
AddTableMethod · 0.80
ManagedQueryTablesMethod · 0.65
GetTableMethod · 0.45

Tested by

no test coverage detected