local_db

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: AGPL-3.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const ServiceExecutableRelativeLocation = "/db/12.1.0/postgres/bin/postgres"

Variables

This section is empty.

Functions

func EnsureDBInstalled

func EnsureDBInstalled() (err error)

EnsureDBInstalled makes sure that the embedded pg database is installed and running

func EnsureDbAndStartService

func EnsureDbAndStartService(invoker constants.Invoker) error

EnsureDbAndStartService :: ensure db is installed and start service if necessary

func FindAllSteampipePostgresInstances

func FindAllSteampipePostgresInstances() ([]*psutils.Process, error)

func GetCountOfConnectedClients

func GetCountOfConnectedClients() (int, error)

GetCountOfConnectedClients returns the number of clients currently connected to the service

func IsInstalled

func IsInstalled() bool

IsInstalled :: checks and reports whether the embedded database is installed and setup IsInstalled checks and reports whether the embedded database is installed and setup

func PidExists

func PidExists(targetPid int) (bool, error)

PidExists scans through the list of PIDs in the system and checks for the `targetPID`.

PidExists uses iteration, instead of signalling, since we have observed that signalling does not always work reliably when the destination of the signal is a child of the source of the signal - which may be the case then starting implicit services

func PrepareDb

func PrepareDb(spinner *spinner.Spinner) error

PrepareDb updates the FDW if needed, and inits the database if required

func RefreshConnectionAndSearchPaths

func RefreshConnectionAndSearchPaths(invoker constants.Invoker) error

RefreshConnectionAndSearchPaths creates a local client and refreshed connections and search paths

func ShutdownService

func ShutdownService(invoker constants.Invoker)

ShutdownService stops the database instance if the given `invoker` matches

func SslMode

func SslMode() string

func SslStatus

func SslStatus() string

func TrimLogs

func TrimLogs()

Types

type LocalClient

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

LocalClient wraps over `sql.DB` and gives an interface to the database

func NewLocalClient

func NewLocalClient(invoker constants.Invoker) (*LocalClient, error)

NewLocalClient ensures that the database instance is running and returns a `Client` to interact with it

func (*LocalClient) CacheClear

func (c *LocalClient) CacheClear() error

func (*LocalClient) CacheOff

func (c *LocalClient) CacheOff() error

func (*LocalClient) CacheOn

func (c *LocalClient) CacheOn() error

func (*LocalClient) Close

func (c *LocalClient) Close() error

Close closes the connection to the database and shuts down the backend

func (*LocalClient) ConnectionMap

func (c *LocalClient) ConnectionMap() *steampipeconfig.ConnectionMap

ConnectionMap returns the latest connection map

func (*LocalClient) Execute

func (c *LocalClient) Execute(ctx context.Context, query string, disableSpinner bool) (res *queryresult.Result, err error)

Execute implements DbClient execute the provided query against the Database in the given context.Context Bear in mind that whenever ExecuteQuery is called, the returned `queryresult.Result` MUST be fully read - otherwise the transaction is left open, which will block the connection and will prevent subsequent communications with the service

func (*LocalClient) ExecuteSync

func (c *LocalClient) ExecuteSync(ctx context.Context, query string, disableSpinner bool) (*queryresult.SyncQueryResult, error)

ExecuteSync implements DbClient execute a query against this client and wait for the result

func (*LocalClient) GetCurrentSearchPath

func (c *LocalClient) GetCurrentSearchPath() ([]string, error)

GetCurrentSearchPath implements DbClient query the database to get the current search path

func (*LocalClient) LoadSchema

func (c *LocalClient) LoadSchema()

LoadSchema retrieves both the raw query result and a sanitised version in list form todo share this between local and remote client - make a function not a method??

func (*LocalClient) RefreshConnectionAndSearchPaths

func (c *LocalClient) RefreshConnectionAndSearchPaths() *db_common.RefreshConnectionResult

func (*LocalClient) RefreshConnections

func (c *LocalClient) RefreshConnections() *db_common.RefreshConnectionResult

RefreshConnections loads required connections from config and update the database schema and search path to reflect the required connections return whether any changes have been made

func (*LocalClient) SchemaMetadata

func (c *LocalClient) SchemaMetadata() *schema.Metadata

SchemaMetadata returns the latest schema metadata

func (*LocalClient) SetClientSearchPath

func (c *LocalClient) SetClientSearchPath() error

SetClientSearchPath implements DbClient sets the search path for this client if either a search-path or search-path-prefix is set in config, set the search path (otherwise fall back to service search path)

func (*LocalClient) SetEnsureSessionDataFunc added in v0.8.3

func (c *LocalClient) SetEnsureSessionDataFunc(f db_common.EnsureSessionStateCallback)

SetEnsureSessionDataFunc sets the callback function which setups the session data - prepared statements and introspection tables this will be called when there is a client error/timeout

func (*LocalClient) SetServiceSearchPath

func (c *LocalClient) SetServiceSearchPath() error

SetServiceSearchPath sets the search path for the db service (by setting it on the steampipe user)

type NamedQueryProvider

type NamedQueryProvider interface {
	GetNamedQueryMap() map[string]*modconfig.Query
	GetNamedQuery(queryName string) (*modconfig.Query, bool)
}

NamedQueryProvider is an interface encapsulating named query searching capability - provided to avoid db needing a reference to workspace

type Passwords

type Passwords struct {
	Root      string
	Steampipe string
}

Passwords :: structure for working with DB passwords

type RunningDBInstanceInfo

type RunningDBInstanceInfo struct {
	Pid        int
	Port       int
	Listen     []string
	ListenType StartListenType
	Invoker    constants.Invoker
	Password   string
	User       string
	Database   string
}

RunningDBInstanceInfo :: contains data about the running process and it's credentials

func GetStatus

func GetStatus() (*RunningDBInstanceInfo, error)

GetStatus :: check that the db instance is running and returns it's details

func (*RunningDBInstanceInfo) Save

func (r *RunningDBInstanceInfo) Save() error

func (*RunningDBInstanceInfo) String added in v0.8.3

func (r *RunningDBInstanceInfo) String() string

type StartListenType

type StartListenType string

StartListenType is a pseudoEnum of network binding for postgres

const (
	// ListenTypeNetwork :: StartListenType - bind to all known interfaces
	ListenTypeNetwork StartListenType = "network"
	// ListenTypeLocal :: StartListenType - bind to localhost only
	ListenTypeLocal = "local"
)

func (StartListenType) IsValid

func (slt StartListenType) IsValid() error

IsValid is a validator for StartListenType known values

type StartResult

type StartResult int

StartResult :: pseudoEnum for outcomes of Start

const (
	// ServiceStarted :: StartResult - Service was started
	// start from 10 to prevent confusion with int zero-value
	ServiceStarted StartResult = iota + 1
	// ServiceAlreadyRunning :: StartResult - Service was already running
	ServiceAlreadyRunning
	// ServiceFailedToStart :: StartResult - Could not start service
	ServiceFailedToStart
)

func StartDB

func StartDB(port int, listen StartListenType, invoker constants.Invoker) (startResult StartResult, err error)

StartDB starts the database if not already running

type StopStatus

type StopStatus int

StopStatus :: pseudoEnum for service stop result

const (
	// ServiceStopped indicates service was stopped.
	// start from 10 to prevent confusion with int zero-value
	ServiceStopped StopStatus = iota + 1
	// ServiceNotRunning indicates service was not running
	ServiceNotRunning
	// ServiceStopFailed indicates service could not be stopped
	ServiceStopFailed
	// ServiceStopTimedOut indicates service stop attempt timed out
	ServiceStopTimedOut
)

func StopDB

func StopDB(force bool, invoker constants.Invoker, spinner *spinner.Spinner) (status StopStatus, e error)

StopDB searches for and stops the running instance. Does nothing if an instance was not found

Jump to

Keyboard shortcuts

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