MCPcopy Create free account
hub / github.com/zalando/postgres-operator / getDatabases

Method getDatabases

pkg/cluster/database.go:333–364  ·  view source on GitHub ↗

getDatabases returns the map of current databases with owners The caller is responsible for opening and closing the database connection

()

Source from the content-addressed store, hash-verified

331// getDatabases returns the map of current databases with owners
332// The caller is responsible for opening and closing the database connection
333func (c *Cluster) getDatabases() (dbs map[string]string, err error) {
334 var (
335 rows *sql.Rows
336 )
337
338 if rows, err = c.pgDb.Query(getDatabasesSQL); err != nil {
339 return nil, fmt.Errorf("could not query database: %v", err)
340 }
341
342 defer func() {
343 if err2 := rows.Close(); err2 != nil {
344 if err != nil {
345 err = fmt.Errorf("error when closing query cursor: %v, previous error: %v", err2, err)
346 } else {
347 err = fmt.Errorf("error when closing query cursor: %v", err2)
348 }
349 }
350 }()
351
352 dbs = make(map[string]string)
353
354 for rows.Next() {
355 var datname, owner string
356
357 if err = rows.Scan(&datname, &owner); err != nil {
358 return nil, fmt.Errorf("error when processing row: %v", err)
359 }
360 dbs[datname] = owner
361 }
362
363 return dbs, err
364}
365
366// executeCreateDatabase creates new database with the given owner.
367// The caller is responsible for opening and closing the database connection.

Callers 3

syncStreamsMethod · 0.95
installLookupFunctionMethod · 0.95
syncDatabasesMethod · 0.95

Calls 1

CloseMethod · 0.80

Tested by

no test coverage detected