Code Monkey home page Code Monkey logo

dbui's Introduction

🗄 DBUI: Database CLI

dbui is database CLI for MySQL and PostgreSQL. It is the terminal user interface application built with the tview.

GitHub release (latest by date) GitHub Workflow Status Go Report Card Codecov

dbui screenshot

dbui provides features like,

  • Connect to multiple data sources and instances.
  • List all schemas in a selected data source.
  • List all tables in a selected schema.
  • Preview a selected table.
  • Execute custom SQL queries on a selected table or schema.
  • User-friendly UI features like,
    • query execution status,
    • warning and error messages,
    • full-screen and focus modes,
    • mouse support.

Runs on Mac, Linux, and Windows.

Linux

dbui is available as downloadable binaries from the releases page. Download the .deb or .rpm from the releases page and install with sudo dpkg -i and sudo rpm -i respectively.

Currently supported databases

  • MySQL
  • PostgreSQL
  • SQLite

What's next?

  • Auto-generate SQL Queries for Insert, Update, Delete.
  • Save frequently used SQL Queries.
  • Configurable keyboard layout.
  • Autocomplete for SQL Queries.

Current status

  • 🚧 Under development, expect bugs, errors, and unexpected crashes.
  • 🐞 Bug and error report very well appreciated.
  • 📣 I highly recommend to check for periodic updates.
Known Issues
  • ❗️Critically low amount of tests.
  • ⚠️Having multiple connections and many queries triggers a high CPU load. Now when this PR merged, as a next step, I will work on profiling the application.

Demo

Install

brew tap kenanbek/dbui https://github.com/kenanbek/dbui
brew install dbui

Other installation options. If you have installed the first versions of dbui, you might need to un-tap the old cask URL. Check this for more information.

Demo with in-memory dataset

You can run dbui with a demo data source.

dbui -demo

This command will open dbui with two dummy data sources, and you can navigate through the demo dataset.

To test it with a real database, you can use the following steps.

Demo with Docker containers

Step 1. Run demo databases

docker run -d --name dbui-mysql-demo -p 3316:3306 -e MYSQL_ROOT_PASSWORD=demo genschsa/mysql-employees
docker run -d --name dbui-postgresql-demo -p 5432:5432 ghusta/postgres-world-db:2.4-alpine

Step 2. Create dbui.yml configuration file

Create dbui.yml file in the current folder with the following content:

dataSources:
  - alias: employees
    type: mysql
    dsn: "root:demo@(localhost:3316)/employees"
  - alias: world-db
    type: postgresql
    dsn: "user=world password=world123 host=localhost port=5432 dbname=world-db sslmode=disable"
  - alias: chinook
    type: sqlite
    dsn: "internal/sqlite/testdata/chinook.db"
defaut: employees

More about configuration files.

Step 3. Start dbui

dbui

Table of Contents

Usage

Install

Option 1: Brew

brew tap kenanbek/dbui https://github.com/kenanbek/dbui
brew install dbui

If you have installed the first versions of dbui, you might need to un-tap the old cask URL. Check this for more information.

Option 2: Go Install

go install github.com/kenanbek/dbui@latest

Option 3: Source Code (+demo databases)

git clone https://github.com/KenanBek/dbui.git
cd dbui
make demodbs # runs docker containers with mysql and postgresql demo dbs

# you can destroy them by executing
make demodbs/destroy

Copy configuration and run:

touch dbui.yml # check below for the content
make run

Copy/paste the configuration provided below for demo databases.

Configuration

By default dbui uses configuration file (dbui.yml).

dataSources:
  - alias: employees
    type: mysql
    dsn: "root:demo@(localhost:3316)/employees"
  - alias: world-db
    type: postgresql
    dsn: "user=world password=world123 host=localhost port=5432 dbname=world-db sslmode=disable"
defaut: employees

First, it checks in the current directory, then in the user's home directory.

All provided database connections will be available in the application, and you can switch among them without restarting the application.

Alternatively, it is possible to start dbui for a single database connection using a DSN (data source name) and type arguments.

$ dbui -dsn <connection string> -type <data source type>

# example for a mysql connection
$ dbui -dsn "codekn:codekn@(localhost:3306)/codekn_omni" -type mysql

Configuration Order

# when
$ dbui
# read from `./dbui.yml` if not then from `~/dbui.yml`

# when
$ dbui -f /my/custom/dir/mydbui.yml
# read from custom directory `/my/custom/dir/mydbui.yml`

# when
$ dbui -dsn "<connection-string>" -type mysql
# init single connection mode

Default Keyboard Layout

dbui keyboard hot keys

Focus Hot Keys

  • Ctrl-A - sources
  • Ctrl-S - schemas
  • Ctrl-D - tables
  • Ctrl-E - preview
  • Ctrl-Q - query

Special

  • Tab - navigate to the next element
  • Shift-Tab - navigate to the prev element
  • Ctrl-F - toggle focus-mode
  • Ctrl-C - exit

Table Specific

Use these keys when the tables panel is active:

  • e - describe selected table
  • p - preview selected table (works as ENTER but does not change focus)

Preview Specific

Use these keys when the data preview panel is active:

  • y - copy a selected row into the clipboard (coming soon).

Contribution

The code and its sub-packages include various form of documentation: code comments or README files. Make sure to get familiar with them to know more about internal code structure. This section includes references to additional READMEs.

DBUI is a work in progress, and any feedback/contributions are more than welcome.

The backlog can be viewed on GitHub Issues page.

References

This project inspired by k9s , lazydocker, and htop.

I use tview terminal UI for the interactive user interface:

For test purposes, I use these Docker-based demo databases:

dbui's People

Contributors

goreleaserbot avatar kenanbek avatar ormanli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dbui's Issues

Auto select schema

Describe the bug
When choosing a different database, schema should be automatically selected

To Reproduce
Steps to reproduce the behavior:
image

Expected behavior
Should select the schema and show the tables for that selected database.

UI "crashes" when mysql is not ready

When MySQL database is not ready to accept connections it logs, and these log messages crash UI.

During the app:
Screenshot 2021-05-28 at 00 23 22

After it is closed:
Screenshot 2021-05-28 at 00 23 38

How to reproduce

  • initialize docker with dbs (e.g. make demodbs or directly execute docker run)
  • start the app and try to connect to the connection

Can't go get it.

Hi there,
I've got a small issue when I try to install it.

❯ go get github.com/KenanBek/dbui
go: downloading github.com/KenanBek/dbui v0.1.2
go get: github.com/KenanBek/dbui@none updating to
        github.com/KenanBek/[email protected]: parsing go.mod:
        module declares its path as: dbui
                but was required as: github.com/KenanBek/dbui

fix[homebrew-formulae]: error on install: "formulae require at least a URL"

Describe the bug
The formulae doesn't install. The full error is:

Error: formulae require at least a URL 
/opt/homebrew/Library/Homebrew/formula.rb:283:in `determine_active_spec'
/opt/homebrew/Library/Homebrew/formula.rb:214:in `initialize'
/opt/homebrew/Library/Homebrew/formulary.rb:308:in `new'
/opt/homebrew/Library/Homebrew/formulary.rb:308:in `get_formula'
/opt/homebrew/Library/Homebrew/formulary.rb:561:in `factory'
/opt/homebrew/Library/Homebrew/cli/parser.rb:634:in `block in formulae'
/opt/homebrew/Library/Homebrew/cli/parser.rb:630:in `map'
/opt/homebrew/Library/Homebrew/cli/parser.rb:630:in `formulae'
/opt/homebrew/Library/Homebrew/cli/parser.rb:307:in `parse'
/opt/homebrew/Library/Homebrew/cmd/install.rb:147:in `install'
/opt/homebrew/Library/Homebrew/brew.rb:97:in `<main>'

To Reproduce

  1. Open any terminal on macOS
  2. Run brew tap kenanbek/dbui && brew install dbui

Expected behavior
The formulae should install dbui.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS Darwin/macOS
  • Terminal n/a
  • Version 13.1

Additional context
Add any other context about the problem here.

create, recreate, destroy demo databases with makefile target

For the demo and testing purposes add makefile target to create a few MySQL and PostgreSQL databases running in docker with exposed ports (different port numbers)

Examples:

alias: tiger
type: MySQL

alias: lion
type: postgresql

alias: wolf
type: postgresql

db#systemlist crashes with Argument of filter() must be a List, Dictionary or Blob

Describe the bug

When trying to connect to a DB by hitting enter on the list item, I get this error:

Error detected while processing function <SNR>115_method[2]..47[30]..50[10]..51[5]..55[6]..db_ui#schemas#query:
line    1:
E118: Too many arguments for function: db#systemlist
Error detected while processing function <SNR>115_method[2]..47[30]..50[10]..51[5]..55[6]..<lambda>35:
line    1:
E896: Argument of filter() must be a List, Dictionary or Blob
Error detected while processing function <SNR>115_method[2]..47[30]..50[10]..51[5]..55[6]..<lambda>35[1]..<SNR>113_results_parser:
line    2:
E896: Argument of filter() must be a List, Dictionary or Blob
Press ENTER or type command to continue

The list item does not expand. But if I close DBUI and open it again, the list item shows up as opened and I see + New Query and the other menu items.

To Reproduce

  • Run :DBUI
  • Select a database
  • Hit enter

Expected behavior

  • Error does not show up
  • Database menu opens up immediately without me having to close and reopen :DBUI

Screenshots

image

Environment (please complete the following information):

  • OS: Linux, Debian 11.5, on kernel 5.10.0-19-amd64
  • Terminal: Alacritty 0.12.0-dev
  • DBUI Version: 0.7.0
  • Neovim Version: 0.8.1

Timeout for long running queries

Is your feature request related to a problem? Please describe.

Queries on big tables without LIMIT statement takes a long time and it looks like the application is hanging.

Describe the solution you'd like

Introduce a timeout parameter. If the execution takes longer than the timeout app raises an error.

Introduce `-version` flag

Prints out the version number.

Once done can be used also in the .goreleaser configuration for the check-up.

Example:

brews:
    ...
    test: |
         system "#{bin}/dbui --version"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.