Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
40 lines
878 B
Go
40 lines
878 B
Go
package core
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
func (c *Catalog) CreateNamespace(name string) (int64, error) {
|
|
oid, err := c.q.CreateNamespace(context.Background(), name)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("create namespace %q: %w", name, err)
|
|
}
|
|
return oid, nil
|
|
}
|
|
|
|
func (c *Catalog) NamespaceOID(name string) (int64, error) {
|
|
oid, err := c.q.NamespaceOID(context.Background(), name)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("namespace %q: %w", name, err)
|
|
}
|
|
return oid, nil
|
|
}
|
|
|
|
type NamespaceInfo struct {
|
|
OID int64
|
|
Name string
|
|
}
|
|
|
|
func (c *Catalog) Namespaces() ([]NamespaceInfo, error) {
|
|
rows, err := c.q.ListNamespaces(context.Background())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("list namespaces: %w", err)
|
|
}
|
|
out := make([]NamespaceInfo, 0, len(rows))
|
|
for _, r := range rows {
|
|
out = append(out, NamespaceInfo{OID: r.Oid, Name: r.Name})
|
|
}
|
|
return out, nil
|
|
}
|