db

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: AGPL-3.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InvokerService :: Invoker - when invoked by `service start`
	InvokerService Invoker = "service"
	// InvokerQuery :: Invoker - when invoked by `query`
	InvokerQuery = "query"
	// InvokerCheck :: Invoker - when invoked by `check`
	InvokerCheck = "check"
	// InvokerInstaller :: Invoker - when invoked by the `installer`
	InvokerInstaller = "installer"
	// InvokerPlugin :: Invoker - when invoked by the `pluginmanager`
	InvokerPlugin = "plugin"
)
View Source
const TagColumn = "column"

TagColumn :: tag used to specify the column name and type in the reflection tables

Variables

This section is empty.

Functions

func CreateMetadataTables added in v0.5.0

func CreateMetadataTables(workspaceResources *modconfig.WorkspaceResourceMaps, client *Client) error

func EnsureDBInstalled

func EnsureDBInstalled()

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

func EnsureDbAndStartService added in v0.5.0

func EnsureDbAndStartService(invoker Invoker) error

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

func ExecuteQuery

func ExecuteQuery(ctx context.Context, queryString string, client *Client) (*queryresult.ResultStreamer, error)

ExecuteQuery :: execute a single query. If shutdownAfterCompletion is true, shutdown the client after completion

func IsInstalled

func IsInstalled() bool

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

func PgEscapeName

func PgEscapeName(name string) string

func PgEscapeString

func PgEscapeString(str string) string

func RunInteractivePrompt added in v0.4.0

func RunInteractivePrompt(workspace NamedQueryProvider, client *Client) (*queryresult.ResultStreamer, error)

RunInteractivePrompt :: start the interactive query prompt

func Shutdown added in v0.2.0

func Shutdown(client *Client, invoker Invoker)

Shutdown :: closes the client connection and stops the database instance if the given `invoker` matches

func StartService

func StartService(invoker Invoker)

StartService :: invokes `steampipe service start --database-listen local --refresh=false --invoker query`

func TrimLogs added in v0.0.17

func TrimLogs()

func UpdateMetadataTables added in v0.5.0

func UpdateMetadataTables(workspaceResources *modconfig.WorkspaceResourceMaps, client *Client) error

Types

type Client

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

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

func NewClient added in v0.4.0

func NewClient(autoRefreshConnections bool) (*Client, error)

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

func (*Client) Close added in v0.4.0

func (c *Client) Close() error

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

func (*Client) ConnectionMap

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

ConnectionMap :: returns the latest connection map

func (*Client) ExecuteQuery added in v0.5.0

func (c *Client) ExecuteQuery(ctx context.Context, query string, countStream bool) (res *queryresult.Result, err error)

ExecuteQuery executes 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 (*Client) ExecuteSync

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

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

func (*Client) GetCurrentSearchPath added in v0.4.0

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

query the database to get the current search path

func (*Client) RefreshConnections added in v0.3.5

func (c *Client) RefreshConnections() (bool, error)

RefreshConnections :: load 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 (*Client) SchemaMetadata

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

SchemaMetadata :: returns the latest schema metadata

func (*Client) SetClientSearchPath added in v0.4.0

func (c *Client) SetClientSearchPath() error

SetClientSearchPath :: set 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 (*Client) SetServiceSearchPath added in v0.5.0

func (c *Client) SetServiceSearchPath() error

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

type InteractiveClient

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

InteractiveClient :: wrapper over *Client and *prompt.Prompt along to facilitate interactive query prompt

func (*InteractiveClient) InteractiveQuery

func (c *InteractiveClient) InteractiveQuery()

InteractiveQuery :: start an interactive prompt and return

type Invoker

type Invoker string

Invoker :: pseudoEnum for what starts the service

func (Invoker) IsValid

func (slt Invoker) IsValid() error

IsValid :: validator for Invoker known values

type NamedQueryProvider added in v0.5.0

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

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

type Passwords added in v0.0.16

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    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

type StartListenType

type StartListenType string

StartListenType :: 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 :: validator for StartListenType known values

type StartResult

type StartResult int

StartResult :: pseudoEnum for outcomes of Start

const (
	// ServiceStarted :: StartResult - Service was started
	ServiceStarted StartResult = iota
	// ServiceAlreadyRunning :: StartResult - Service was already running
	ServiceAlreadyRunning
	// ServiceFailedToStart :: StartResult - Could not start service
	ServiceFailedToStart
)

func StartDB

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

StartDB :: start the database is not already running

type StopStatus

type StopStatus int

StopStatus :: pseudoEnum for service stop result

const (
	// ServiceStopped :: StopStatus - service was stopped
	ServiceStopped StopStatus = iota
	// ServiceNotRunning :: StopStatus - service was not running
	ServiceNotRunning
	// ServiceStopFailed :: StopStatus - service could not be stopped
	ServiceStopFailed
	// ServiceStopTimedOut :: StopStatus - service stop attempt timed out
	ServiceStopTimedOut
)

func StopDB

func StopDB(force bool, invoker Invoker) (StopStatus, error)

StopDB :: search and stop the running instance. Does nothing if an instance was not found

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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