controller

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

controller package

dbui/controller package provides an abstraction over different data sources, and the ability to switch among them.

Usage:

cfg := config.Load() // Pseudocode, loads config from CLI params or `dbui` config file.   
ctrl := controller.New(cfg)

// once we have an instance of `controller` we can use it to initialize a `dbui` TUI application.
tui := tui.New(cfg, ctrl)

The controller implements following functions defined by dbui/internal.DataController interface.

  • List() - list all available data sources (returns map of alias to data source).
  • Switch(alias) - switch the current data source to a data source associated with the given alias.
  • Current() - return currently selected (default, or the most recently switched) data source.

Data source specific functions:

All data sources required to implement dbui/internal.DataSource interface and provide the following list of functions:

  • Ping() - Ping, check connection.
  • ListSchemas() - list all schemas.
  • ListTables(schema string) - list all tables in a given schema.
  • PreviewTable(schema, table string) - return top N rows of a table.
  • DescribeTable(schema, table string) - return structure of a table.
  • Query(schema, query string) - execute a custom SQL Query.

Currently there are two implemented data sources:

  • dbui/internal/mysql
  • dbui/internal/postgresql

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyConnection indicates that the current connection is not set.
	// This can happen when the application was initialized with an empty DSN,
	// or there was an unexpected exception during the switch.
	ErrEmptyConnection = errors.New("current connection is empty")

	// ErrUnsupportedDatabaseType indicates that in user-provided configuration
	// Type field does not correspond to any supported database type.
	ErrUnsupportedDatabaseType = errors.New("database type not supported")

	// ErrAliasDoesNotExists indicates that the used alias does not exist in the set of data source connections.
	ErrAliasDoesNotExists = errors.New("alias does not exists")

	// ErrIncorrectDefaultAlias indicates that the user-provided default alias has no match in the set of provided data source connections.
	ErrIncorrectDefaultAlias = errors.New("incorrect default database alias")
)

Functions

This section is empty.

Types

type Controller

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

Controller implements internal.DataController interface. It provides Switch, List, and Current methods used over a set of data source configurations.

func New

func New(appConfig internal.AppConfig) (c *Controller, err error)

New returns an instance of Controller initiated by the provided configuration.

func (*Controller) Current

func (c *Controller) Current() internal.DataSource

Current returns selected data source connection.

func (*Controller) List

func (c *Controller) List() (result [][]string)

List returns list of data sources available in the application.

func (*Controller) Switch

func (c *Controller) Switch(alias string) (err error)

Switch selects provided data source by its allias and tries to connect to it.

Jump to

Keyboard shortcuts

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