pgapi

package
v0.0.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapSqlExecutionError added in v0.0.2

func WrapSqlExecutionError(err error, query string, args ...string) error

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
	// IsDatabaseExtensionPresent checks if the given extension is created in the database
	IsDatabaseExtensionPresent(databaseName string, extension string) (bool, error)
	// CreateDatabaseExtension creates the given extension in the database
	CreateDatabaseExtension(databaseName string, extension 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
	// UpdateSchemaPrivileges updates the privileges for the given schema
	UpdateSchemaPrivileges(databaseName string, schemaName string, roleName string, privileges []string) error
	// UpdatePrivilegesOnAllObjects updates the privileges according to the given parameters
	UpdatePrivilegesOnAllObjects(databaseName string, schemaName string, roleName string, typeName string, privileges []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
	// IsSchemaUsable checks if the current user has the use privilege on the given schema
	IsSchemaUsable(databaseName string, schemaName string) (bool, error)
	// MakeSchemaUseable grants the use privilege on the given schema to the current user
	MakeSchemaUseable(databaseName string, schemaName string) error
	// GetSchemaOwner returns the owner of the database with the given name on the connected instance
	GetSchemaOwner(databaseName string, schemaName string) (string, error)
}

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

type SqlExecutionError added in v0.0.2

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

func (*SqlExecutionError) Error added in v0.0.2

func (e *SqlExecutionError) Error() string

func (*SqlExecutionError) Unwrap added in v0.0.2

func (e *SqlExecutionError) Unwrap() error

Jump to

Keyboard shortcuts

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