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)
| 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. |
| 1597 | func (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. |
no test coverage detected