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

Method DBForDatabase

core/api.go:1597–1613  ·  view source on GitHub ↗

DBForDatabase returns the read-only connection pool and database type for `database`. Empty name resolves to the default database. Do not close the pool.

(database string)

Source from the content-addressed store, hash-verified

1595// DBForDatabase returns the read-only connection pool and database type for
1596// `database`. Empty name resolves to the default database. Do not close the pool.
1597func (g *GraphJin) DBForDatabase(database string) (*sql.DB, string, error) {
1598 gj, err := g.getEngine()
1599 if err != nil {
1600 return nil, "", err
1601 }
1602 ctx, ok := gj.GetDatabase(database)
1603 if !ok || ctx == nil {
1604 if database == "" {
1605 return nil, "", fmt.Errorf("no default database configured")
1606 }
1607 return nil, "", fmt.Errorf("database %q not configured", database)
1608 }
1609 if ctx.db == nil {
1610 return nil, ctx.dbtype, fmt.Errorf("database %q has no active connection", database)
1611 }
1612 return ctx.db, ctx.dbtype, nil
1613}
1614
1615// getTables returns tables, optionally filtered by database name.
1616// With empty database, returns tables from all databases.

Callers 8

CapabilitiesForFunction · 0.80
RowCountsForNamespaceFunction · 0.80
NamespacesFunction · 0.80
loadIndexesFunction · 0.80
buildTableSampleFunction · 0.80
execDBTypeMethod · 0.80
loadColumnStatsFunction · 0.80

Calls 2

getEngineMethod · 0.95
GetDatabaseMethod · 0.65

Tested by

no test coverage detected