MCPcopy Create free account
hub / github.com/PostHog/duckgres / getModel

Method getModel

controlplane/admin/models_api.go:164–211  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

162 if _, ok := covered[r.TableName]; ok {
163 continue
164 }
165 out = append(out, autoTable{Schema: r.TableSchema, Name: r.TableName})
166 }
167 sort.Slice(out, func(i, j int) bool { return out[i].key() < out[j].key() })
168 return out, nil
169}
170
171// resolveAutoTable validates an auto key against a FRESH discovery — the only
172// table names ever interpolated into SQL are ones information_schema just
173// returned, so a crafted key can't smuggle SQL.
174func (h *modelsHandler) resolveAutoTable(key string) (autoTable, bool) {
175 if !strings.HasPrefix(key, autoKeyPrefix) {
176 return autoTable{}, false
177 }
178 tables, err := h.discoverTables()
179 if err != nil {
180 return autoTable{}, false
181 }
182 for _, t := range tables {
183 if t.key() == key {
184 return t, true
185 }
186 }
187 return autoTable{}, false
188}
189
190// autoColumns returns the table's column names in ordinal order.
191func (h *modelsHandler) autoColumns(t autoTable) ([]string, error) {
192 var cols []string
193 err := h.store.DB().Raw(`
194 SELECT column_name
195 FROM information_schema.columns
196 WHERE table_schema = ? AND table_name = ?
197 ORDER BY ordinal_position`, t.Schema, t.Name).Scan(&cols).Error
198 return cols, err
199}
200
201// registerModelsAPI registers the read-only generic models explorer used by the
202// admin dashboard's models browser.
203func registerModelsAPI(r *gin.RouterGroup, store *configstore.ConfigStore) {
204 h := &modelsHandler{store: store}
205 r.GET("/models", h.listModels)
206 r.GET("/models/:model", h.getModel)
207}
208
209// qualifiedTable returns the table name to read for a descriptor, schema-
210// qualifying runtime tables with the CP runtime schema.
211func (h *modelsHandler) qualifiedTable(d modelDescriptor) string {
212 if d.Runtime {
213 return h.store.RuntimeSchema() + "." + d.Table
214 }

Callers 1

useModelFunction · 0.80

Calls 6

qualifiedTableMethod · 0.95
modelDescriptorsFunction · 0.85
jsonFieldOrderFunction · 0.85
DBMethod · 0.45
CountMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected