pgapi

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PgConnectionString

type PgConnectionString struct {
	// contains filtered or unexported fields
}

func NewPgConnectionString

func NewPgConnectionString(
	hostname string,
	port int,
	username string,
	password string,
	database string,
	sslMode string,
) (*PgConnectionString, error)

func (*PgConnectionString) Database

func (pgcs *PgConnectionString) Database() string

func (*PgConnectionString) Hostname

func (pgcs *PgConnectionString) Hostname() string

func (*PgConnectionString) Password

func (pgcs *PgConnectionString) Password() string

func (*PgConnectionString) Port

func (pgcs *PgConnectionString) Port() int

func (*PgConnectionString) SSLMode

func (pgcs *PgConnectionString) SSLMode() string

func (*PgConnectionString) Username

func (pgcs *PgConnectionString) Username() string

type PgConnector

type PgConnector interface {
	// ConnectionString provides the PgConnectionString of the current connection
	ConnectionString() PgConnectionString
	// IsConnected returns the current connection state,
	// true if the connection is established, false if not
	IsConnected() bool
	// TestConnection tries to establish a connection
	// and communicates with the Postgres instance if possible.
	// If the connection cannot be established, or the server does not communicate
	// as expected, an error is returned
	TestConnection() error
}

PgConnector provides functionality to check the current connection to a Postgres instance

type PgDatabaseAPI

type PgDatabaseAPI interface {
	// IsDatabaseExisting returns true if a database
	// with the given name exists on the connected instance and false if not.
	IsDatabaseExisting(databaseName string) (bool, error)
	// CreateDatabase creates a new database on the connected instance
	CreateDatabase(databaseName string) error
	// DeleteDatabase drops the database with the given name on the connected instance
	DeleteDatabase(databaseName string) error
	// GetDatabaseOwner returns the owner of the database with the given name on the connected instance
	GetDatabaseOwner(databaseName string) (string, error)
	// UpdateDatabaseOwner changes the owner of the database with the given name to the role with the given name
	UpdateDatabaseOwner(databaseName string, roleName string) error
	// ResetDatabaseOwner changes the owner of the database with the given name to the role with which the client is connected
	ResetDatabaseOwner(databaseName string) error
	// UpdateDatabasePrivileges changes the given privileges on the given database for the given role
	UpdateDatabasePrivileges(databaseName string, roleName string, privileges []string) error
}

PgDatabaseAPI provides functionality to check and manipulate databases, database ownership and privileges on databases

type PgInstanceAPI

type PgInstanceAPI interface {
	PgConnector
	PgRoleAPI
	PgDatabaseAPI
	PgSchemaAPI
}

PgInstanceAPI represents the full functionality of the API to a postgres instance of a cluster The implementation for this interface can be created by NewPgInstanceAPI Instead of using this interface directly a client should implement its own interfaces or use one of the provided interfaces like PgConnector, PgRoleAPI, PgDatabaseAPI or PgSchemaAPI

func NewPgInstanceAPI

func NewPgInstanceAPI(ctx context.Context, name string, connectionString *PgConnectionString) (PgInstanceAPI, error)

NewPgInstanceAPI creates an implementation for the PgInstanceAPI interface

type PgRoleAPI

type PgRoleAPI interface {
	// IsRoleExisting returns true if a role
	// with the given name exists on the connected instance and false if not.
	IsRoleExisting(roleName string) (bool, error)
	// CreateRole creates the given role on the connected instance
	CreateRole(name string) error
	// DeleteRole drops the given role from the connected instance
	DeleteRole(name string) error
	// UpdateUserPassword changes the password for the given role
	UpdateUserPassword(name string, password string) error
}

PgRoleAPI provides functionality to check and manipulate login roles (role with login)

type PgSchemaAPI

type PgSchemaAPI interface {
	// IsSchemaInDatabase returns true if a schema
	// with the given name exists in the given database and false if not.
	IsSchemaInDatabase(databaseName string, schemaName string) (bool, error)
	// CreateSchema creates a new schema with the given name in the given database
	CreateSchema(databaseName string, schemaName string) error
	// DeleteSchema drops the given schema from the given database
	DeleteSchema(databaseName string, schemaName string) error
	// UpdateDefaultPrivileges updates the default privileges in the given schema
	// for the given role on the given type to the given privileges
	UpdateDefaultPrivileges(databaseName string, schemaName string, roleName string, typeName string, privileges []string) error
	// DeleteAllPrivilegesOnSchema removes all privileges on the given schema for the given role
	DeleteAllPrivilegesOnSchema(databaseName string, schemaName string, role string) error
}

PgSchemaAPI provides functionality to check and manipulate schemas and privileges on schemas

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL