package
0.8.0
Repository: https://github.com/kenanbek/dbui.git
Documentation: pkg.go.dev

# 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

# Functions

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

# Variables

ErrAliasDoesNotExists indicates that the used alias does not exist in the set of data source connections.
ErrEmptyConnection indicates that the current connection is not set.
ErrIncorrectDefaultAlias indicates that the user-provided default alias has no match in the set of provided data source connections.
ErrUnsupportedDatabaseType indicates that in user-provided configuration Type field does not correspond to any supported database type.

# Structs

Controller implements internal.DataController interface.