MCPcopy Index your code
hub / github.com/danvergara/dblab

github.com/danvergara/dblab @v0.42.1 sqlite

repository ↗ · DeepWiki ↗ · release v0.42.1 ↗
352 symbols 960 edges 45 files 169 documented · 48%
README

dblab

integration tests unit tests Release

dblab logo

Interactive client for PostgreSQL, MySQL, SQLite3, Oracle and SQL Server.


Documentation: https://dblab.app


Table of contents

Overview

dblab is a fast and lightweight interactive terminal-based UI application for PostgreSQL, MySQL, and SQLite3, written in Go and works on macOS, Linux, and Windows machines. The main idea behind using Go for backend development is to utilize the ability of the compiler to produce zero-dependency binaries for multiple platforms. dblab was created as an attempt to build a very simple and portable application to work with local or remote PostgreSQL/MySQL/SQLite3/Oracle/SQL Server databases.

Features

  • Cross-platform support for macOS/Linux/Windows (32/64-bit)
  • Simple installation (distributed as a single binary)
  • Zero dependencies.
  • Vim-style query editor (normal and insert modes, line-oriented editing commands).
  • Connection profiles with secure credential storage in the OS keyring.

Installation

The above comment is deprecated and CGO is not needed anymore. There will be a single binary capable of dealing with all supported clients.

Homebrew

It works with Linux, too.

brew install --cask danvergara/tools/dblab

Or

brew tap danvergara/tools
brew install --cask dblab

Binary Release (Linux/macOS/Windows)

You can manually download a binary release from the release page.

Automated installation/update

Don't forget to always verify what you're piping into bash

Install the binary using our bash script:

curl https://raw.githubusercontent.com/danvergara/dblab/master/scripts/install_update_linux.sh | bash

Help

dblab is a terminal UI-based interactive database client

Usage:
  dblab [flags]
  dblab [command]

Available Commands:
  connect     Re-use saved connection profiles
  help        Help about any command
  version     The version of the project

Flags:
      --cfg-name string                   Database config name section
      --config                            Get the connection data from a config file (default locations are: current directory, $HOME/.dblab.yaml or $XDG_CONFIG_HOME/.dblab.yaml)
      --keybindings, -k                   Get the keybindings configuration from the config file (default locations are: current directory, $HOME/.dblab.yaml or $XDG_CONFIG_HOME/.dblab.yaml)
      --db string                         Database name
      --driver string                     Database driver
      --encrypt string                    [strict|disable|false|true] whether data sent between client and server is encrypted
  -h, --help                              help for dblab
      --host string                       Server host name or IP
      --limit uint                        Size of the result set for the table content query (should be greater than zero, otherwise the app will error out) (default 100)
      --pass string                       Password for user
      --port string                       Server port
      --save-as string                    Save the connection as a named profile for later reuse
      --schema string                     Database schema (optional for postgres and oracle only)
      --socket string                     Path to a Unix socket file
      --ssh-host string                   SSH Server Hostname/IP
      --ssh-key string                    File with private key for SSH authentication
      --ssh-key-pass string               Supports connections with protected private keys with passphrase
      --ssh-pass string                   SSH Password (Empty string for no password)
      --ssh-port string                   SSH Port
      --ssh-user string                   SSH User
      --ssl string                        SSL mode
      --ssl-verify string                 [enable|disable] or [true|false] enable ssl verify for the server
      --sslcert string                    This parameter specifies the file name of the client SSL certificate, replacing the default ~/.postgresql/postgresql.crt
      --sslkey string                     This parameter specifies the location for the secret key used for the client certificate. It can either specify a file name that will be used instead of the default ~/.postgresql/postgresql.key, or it can specify a key obtained from an external “engine”
      --sslpassword string                This parameter specifies the password for the secret key specified in sslkey
      --sslrootcert string                This parameter specifies the name of a file containing SSL certificate authority (CA) certificate(s). The default is ~/.postgresql/root.crt
      --timeout string                    in seconds (default is 0 for no timeout), set to 0 for no timeout. Recommended to set to 0 and use context to manage query and connection timeouts
      --trace-file string                 File name for trace log
      --trust-server-certificate string   [false|true] whether the server certificate is checked
  -u, --url string                        Database connection string
      --user string                       Database user
  -v, --version                           version for dblab
      --wallet string                     Path for auto-login oracle wallet

Use "dblab [command] --help" for more information about a command.

Usage

You can start the app without passing flags or parameters; you'll be asked for connection data instead. dblab-demo

$ dblab --host localhost --user myuser --db users --pass password --ssl disable --port 5432 --driver postgres --limit 50
$ dblab --db path/to/file.sqlite3 --driver sqlite
$ dblab --host localhost --user system --db FREEPDB1 --pass password --port 1521 --driver oracle --limit 50
$ dblab --host localhost --user SA --db msdb --pass '5@klkbN#ABC' --port 1433 --driver sqlserver --limit 50

Connection URL scheme is also supported:

$ dblab --url 'postgres://user:password@host:port/database?sslmode=[mode]'
$ dblab --url 'mysql://user:password@tcp(host:port)/db'
$ dblab --url 'file:test.db?_pragma=foreign_keys(1)&_time_format=sqlite'
$ dblab --url 'oracle://user:password@localhost:1521/db'
$ dblab --url 'sqlserver://SA:myStrong(!)Password@localhost:1433?database=tempdb&encrypt=true&trustservercertificate=false&connection+timeout=30'

If you're using PostgreSQL or Oracle, you have the option to define the schema you want to work with. The --schema flag is optional: if omitted, dblab will display all schemas the connected user has access to in the sidebar tree. If provided, only that specific schema will be shown.

# Postgres
$ dblab --host localhost --user myuser --db users --pass password --schema myschema --ssl disable --port 5432 --driver postgres --limit 50
$ dblab --url postgres://user:password@host:port/database?sslmode=[mode] --schema myschema

# Oracle
$ dblab --host localhost --user user2 --db FREEPDB1 --pass password --port 1521 --driver oracle --limit 50 --schema user1
$ dblab --url 'oracle://user2:password@localhost:1521/FREEPDB1' --schema user1

As requested in #125, support for MySQL/MariaDB sockets was integrated.

$ dblab --url "mysql://user:password@unix(/path/to/socket/mysql.sock)/dbname?charset=utf8"
$ dblab --socket /path/to/socket/mysql.sock --user user --db dbname --pass password --ssl disable --port 5432 --driver mysql --limit 50

Postgres connection through Unix sockets:

$ dblab --url "postgres://user:password@/dbname?host=/path/to/socket"
$ dblab --socket /path/to/socket --user user --db dbname --pass password --ssl disable --port 5432 --driver postgres --limit 50

Now, it is possible to ensure SSL connections with PostgreSQL databases. SSL-related parameters have been added, such as --sslcert, --sslkey, --sslpassword, and --sslrootcert. More information on how to use such connection flags can be found here.

dblab --host  db-postgresql-nyc3-56456-do-user-foo-0.fake.db.ondigitalocean.com --user myuser --db users --pass password --schema myschema --port 5432 --driver postgres --limit 50 --ssl require --sslrootcert ~/Downloads/foo.crt

SSH Tunnel

Now, it's possible to connect to Postgres or MySQL (more to come later) databases on a server via SSH using a password or SSH key files.

To do so, 6 new flags have been added to the dblab command:

Flag Description
--ssh-host SSH Server Hostname/IP
--ssh-port SSH Port
--ssh-user SSH User
--ssh-pass SSH Password (Empty string for no password)
--ssh-key File with private key for SSH authentication
--ssh-key-pass Passphrase for protected private key files

Examples

Postgres connection via SSH tunnel using a password:

dblab --host localhost --user postgres --pass password --schema public --ssl disable --port 5432 --driver postgres --limit 50 --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-pass root

Postgres connection via SSH tunnel using an SSH private key file:

dblab --host localhost --user postgres --pass password --schema public --ssl disable --port 5432 --driver postgres --limit 50 --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-key my_ssh_key --ssh-key-pass password

Postgres connection using the url parameter via SSH tunnel using a password:

dblab --url postgres://postgres:password@localhost:5432/users?sslmode=disable --schema public --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-pass root

MySQL connection via SSH tunnel using a password:

dblab --host localhost --user myuser --db mydb --pass 5@klkbN#ABC --ssl enable --port 3306 --driver mysql --limit 50 --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-pass root

MySQL connection via SSH tunnel using an SSH private key file:

dblab --host localhost --user postgres --pass password --ssl enable --port 3306 --driver mysql --limit 50 --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-key my_ssh_key --ssh-key-pass passphrase

MySQL connection using the url parameter via SSH tunnel using a password:

dblab --url "mysql://myuser:5@klkbN#ABC@mysql+tcp(localhost:3306)/mydb" --driver mysql --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-pass root

Configuration

Entering these flags every time is tedious, so dblab provides a couple of flags to help with it: --config and --cfg-name.

dblab is going to look for a file called .dblab.yaml. Currently, there are three places where you can drop a config file:

  • $XDG_CONFIG_HOME ($XDG_CONFIG_HOME/.dblab.yaml)
  • $HOME ($HOME/.dblab.yaml)
  • . (the current directory where you run the command line tool)

If you want to use this feature, --config is mandatory and --cfg-name may be omitted. The config file can store one or multiple database connection sections under the database field. database is an array; previously it was an object only able to store a single connection section at a time.

We strongly encourage you to adopt the new format as of v0.18.0. --cfg-name takes the name of the desired database section to connect with. It can be omitted and its default value will be the first item in the array.

As of v0.21.0, SSL connection options are supported in the config file.

# default: test
$ dblab --config

$ dblab --config --cfg-name "prod"

Key bindings configuration

Key bindings can be configured through the .dblab.yaml file. There is a field called keybindings where key bindings can be modified. Under keybindings, an editor section configures the Vim-style query editor (movement between normal and insert mode, cursor motion in normal mode, and the editor’s execute-query shortcut). By default, the keybindings are not loaded, so you need to use the --keybindings or -k flag to load them. See the example to see the full list of the key bindings subject to change. The file shows the default values. The list of the available key bindings belongs to the bubbletea library. Specifically, see the [KeyNames map](https://github.com/charmbracelet/bubbletea/blob/1ed724a2d1316ace504f87a2f0bbbcc189d

Extension points exported contracts — how you extend this code

MetadataPanel (Interface)
(no doc)
pkg/bubbletui/resultset.go
Option (FuncType)
(no doc)
pkg/sshdb/sshdb.go

Core symbols most depended-on inside this repo

Query
called by 25
pkg/client/client.go
Close
called by 22
pkg/sshdb/sshdb.go
SetWidth
called by 18
pkg/bubbletui/editor.go
View
called by 16
pkg/form/form.go
Update
called by 15
pkg/form/form.go
Run
called by 15
pkg/app/app.go
SetContent
called by 13
pkg/bubbletui/resultset.go
Port
called by 13
pkg/form/form.go

Shape

Method 164
Function 122
Struct 60
TypeAlias 3
Interface 2
FuncType 1

Languages

Go100%

Modules by API surface

pkg/bubbletui/resultset.go28 symbols
pkg/client/client.go27 symbols
pkg/form/form.go25 symbols
pkg/sshdb/sshdb.go24 symbols
pkg/bubbletui/connect.go18 symbols
pkg/config/config.go16 symbols
pkg/bubbletui/sidebar.go16 symbols
pkg/bubbletui/bubbletui.go16 symbols
pkg/client/client_test.go15 symbols
pkg/connection/connection.go14 symbols
pkg/bubbletui/editor.go14 symbols
pkg/pagination/pagination.go12 symbols

Dependencies from manifests, versioned

dario.cat/mergov1.0.2 · 1×
filippo.io/edwards25519v1.1.0 · 1×
github.com/Azure/go-ansitermv0.0.0-2023012417243 · 1×
github.com/Azure/go-autorestv14.2.0+incompatible · 1×
github.com/Azure/go-autorest/autorest/adalv0.9.16 · 1×
github.com/Azure/go-autorest/autorest/datev0.3.0 · 1×
github.com/Azure/go-autorest/loggerv0.2.1 · 1×
github.com/Azure/go-autorest/tracingv0.6.0 · 1×
github.com/Digital-Shane/treeview/v2v2.0.0 · 1×

Datastores touched

(mysql)Database · 1 repos
dbDatabase · 1 repos
mydbDatabase · 1 repos
dbDatabase · 1 repos
usersDatabase · 1 repos
dbnameDatabase · 1 repos
dbnameDatabase · 1 repos

For agents

$ claude mcp add dblab \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact