Code Monkey home page Code Monkey logo

termdbms's Introduction

termdbms

A TUI for viewing and editing databases, written in pure Go

Installation Instructions

Go Install
go install github.com/mathaou/termdbms@latest
Arch Linux
// pacman
sudo pacman -S termdbms-git
// yay
yay -S termdbms-git

Database Support
SQLite
CSV* (see note below)

made with modernc.org/sqlite, charmbracelet/bubbletea, and charmbracelet/lipgloss

Works with keyboard and mouse!

Keyboard Control

Navigate tables with any number of columns!

Columns and Tables

Navigate tables with any number of rows!

Lot of Rows

Serialize your changes as a copy or over the database original! (SQLite only)

Serialization

Query your database!

querying

Other Features

  • Run SQL queries and display the results!
  • Save SQL queries to a clipboard!
  • Update, delete, or insert with SQL, with undo/redo supported for SQLite
  • Automatic JSON formatting in selection/format mode
  • Edit multi-line text with vim-like controls
  • Undo/Redo of changes (SQLite only)
  • Themes (press T in table mode)
  • Output query results as a csv
  • Convert .csv to SQLite database! Export as a SQLite database or .csv file again!

Roadmap

  • MySQL/ PostgreSQL support
  • Line wrapping / horizontal scroll for format/SQL mode + revamped (faster format mode)

How To Build
Linux
GOOS=linux GOARCH=amd64/386 go build
ARM (runs kind of slow depending on the specs of the system)
GOOS=linux GOARCH=arm GOARM=7 go build
Windows
GOOS=windows GOARCH=amd64/386 go build
OSX
GOOS=darwin GOARCH=amd64 go build

Terminal settings

Whatever terminal emulator used should support ANSI escape sequences. If there is an option for 256 color mode, enable it. If not available, try running program in ascii mode (-a).

Known Issues

  • Using termdbms over a serial connection works very poorly. This is due to ANSI sequences not being supported natively. Maybe putty/mobaxterm have settings to allow this?
  • The headers wig out sometimes in selection mode
  • Line wrapping is not yet implemented, so text in format mode should be less than the maximum number of columns available per line for best use. It's in the works!
  • Weird combinations of newlines + tabs can break stuff. Tabs at beginning of line and mid-line works in a stable manner.
Help:
-p / database/.csv path
-d / specifies which database driver to use (sqlite/mysql)
-a / enable ascii mode
-h / prints this message
-t / starts app with specific theme (default, nord, solarized)
Controls:
MOUSE
Scroll up + down to navigate table/text
Move cursor to select cells for full screen viewing
KEYBOARD
[WASD] to move around cells, and also move columns if close to edge
[ENTER] to select selected cell for full screen view
[UP/K and DOWN/J] to navigate schemas
[LEFT/H and RIGHT/L] to navigate columns if there are more than the screen allows.
    Also to control the cursor of the text editor in edit mode
[BACKSPACE] to delete text before cursor in edit mode
[M(scroll up) and N(scroll down)] to scroll manually
[Q or CTRL+C] to quit program
[B] to toggle borders!
[C] to expand column
[T] to cycle through themes!
[P] in selection mode to write cell to file, or to print query results as CSV.
[R] to redo actions, if applicable
[U] to undo actions, if applicable
[ESC] to exit full screen view, or to enter edit mode
[PGDOWN] to scroll down one views worth of rows
[PGUP] to scroll up one views worth of rows
EDIT MODE (for quick, single line changes and commands)
[ESC] to enter edit mode with no pre-loaded text input from selection
When a cell is selected, press [:] to enter edit mode with selection pre-loaded
The text field in the header will be populated with the selected cells text. Modifications can be made freely
[ESC] to clear text field in edit mode
[ENTER] to save text. Anything besides one of the reserved strings below will overwrite the current cell
[:q] to exit edit mode/ format mode/ SQL mode
[:s] to save database to a new file (SQLite only)
[:s!] to overwrite original database file (SQLite only). A confirmation dialog will be added soon
[:h] to display help text
[:new] opens current cell with a blank buffer
[:edit] opens current cell in format mode
[:sql] opens blank buffer for creating an SQL statement
[:clip] to open clipboard of SQL queries. [/] to filter, [ENTER] to select.
[HOME] to set cursor to end of the text
[END] to set cursor to the end of the text
FORMAT MODE (for editing lines of text)
[ESC] to move between top control bar and format buffer
[HOME] to set cursor to end of the text
[END] to set cursor to the end of the text
[:wq] to save changes and quit to main table view
[:w] to save changes and remain in format view
[:s] to serialize changes, non-destructive (SQLite only)
[:s!] to serialize changes, overwriting original file (SQLite only)
SQL MODE (for querying database)
[ESC] to move between top control bar and text buffer
[:q] to quit out of statement
[:exec] to execute statement. Errors will be displayed in full screen view.
[:stow <NAME>] to create a snippet for the clipboard with an optional name. A random number will be used if no name is specified.
QUERY MODE (specifically when viewing query results)
[:d] to reset table data back to original view
[:sql] to query original database again

termdbms's People

Contributors

alphatroya avatar mathaou avatar meowgorithm 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  avatar  avatar  avatar  avatar  avatar

termdbms's Issues

runtime error: integer divide by zero

Hi @mathaou
Congrat for this project, I wanted to test because I like terminal based tools.

However, I cannot start sqlite3-viewer :

Caught panic:

runtime error: integer divide by zero

Restoring terminal...

goroutine 1 [running]:
runtime/debug.Stack(0x4d, 0x0, 0x0)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9f
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x25
github.com/charmbracelet/bubbletea.(*Program).Start.func2(0xc00017c1b0)
	/home/pierre/go/pkg/mod/github.com/charmbracelet/[email protected]/tea.go:447 +0xd6
panic(0x71fa60, 0x9937c0)
	/usr/local/go/src/runtime/panic.go:965 +0x1b9
sqlite3-viewer/viewer.(*TuiModel).CellWidth(...)
	/tmp/app/demo/sqlite-tui/viewer/util.go:33
sqlite3-viewer/viewer.(*TuiModel).GetBaseStyle(0xc000131bb0, 0x6e7db1, 0xc00000c0a8, 0x0)
	/tmp/app/demo/sqlite-tui/viewer/util.go:39 +0x86f
sqlite3-viewer/viewer.handleWidowSizeEvents(0xc000131bb0, 0xc000131810)
	/tmp/app/demo/sqlite-tui/viewer/events.go:39 +0xae
sqlite3-viewer/viewer.TuiModel.Update(0xc00015d0b0, 0xc00015d0e0, 0xc00015d110, 0x7, 0x1, 0x110, 0x44, 0x0, 0x3, 0x0, ...)
	/tmp/app/demo/sqlite-tui/viewer/viewer.go:55 +0xd46
github.com/charmbracelet/bubbletea.(*Program).Start(0xc00017c1b0, 0x0, 0x0)
	/home/pierre/go/pkg/mod/github.com/charmbracelet/[email protected]/tea.go:589 +0x5b9
main.main()
	/tmp/app/demo/sqlite-tui/main.go:111 +0x39d

Setup :

  • debian 10
  • go 1.16
  • xterm 256 activated

Is there something that I missed?

Publish a Homebrew package

This app is awesome and you are awesome for making and sharing it. Have you already started on a package for Homebrew? Happy to help contribute if not

Large (multi-gb) sqlite db support

This looks neat but it takes several minutes to open a 10 GB sqlite file containing 40 million rows.

It does eventually render the interface, but it's taking 38 GB memory according to macOS Activity Monitor.

DB Browser for SQLite is able to work with this DB without loading the entire DB into memory (it's consuming 800 MB RAM).

Loading the entire DB into memory would be OK if it's done in a more memory-efficient way (my system could handle taking 1.5x the size of the sqlite db file but not 3.8x)

Once the interface loaded, I got this crash when I pressed a button:


panic: runtime error: slice bounds out of range [1450:61]-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------┤ 1450, 0

goroutine 561 [running]:
github.com/mathaou/termdbms/viewer.DisplaySelection(0xc203347600)
	/Users/hubert/go/pkg/mod/github.com/mathaou/[email protected]/viewer/ui.go:250 +0x5f3
github.com/mathaou/termdbms/viewer.AssembleTable(0xc203347600?)
	/Users/hubert/go/pkg/mod/github.com/mathaou/[email protected]/viewer/tableutil.go:18 +0x7b
github.com/mathaou/termdbms/viewer.TuiModel.View.func1(0xc203e34880)
	/Users/hubert/go/pkg/mod/github.com/mathaou/[email protected]/viewer/viewer.go:152 +0x2e
created by github.com/mathaou/termdbms/viewer.TuiModel.View
	/Users/hubert/go/pkg/mod/github.com/mathaou/[email protected]/viewer/viewer.go:151 +0x219

Alpha 1.0 Release (Database Agnostic Spreadsheet Program)

I've realized that I could turn the program into a database agnostic fully fledged spreadsheet program with about a months worth of work. Any features you'd like? Here's what I have planned:

  • Edit cell
  • Add row below/above
  • Remove row below/above
  • Add column left/right
  • Remove column/right
  • Macros? Need to think about which functions would be most helpful in which circumstances. Currency conversion or something maybe.
  • Cell highlight/coloring
  • Expand column to fill screen
  • Serialize (this is going to be the hardest part because it's different for every database)
  • Copy/paste (going to also be tricky to implement

That's all for Alpha 1.0 release

Need to think about input. I need text and dialog boxes, maybe some more fancy stuff, but having mouse / keyboard support for all of this is maybe kind of cluttered so maybe some kind of vim-esque structuring idk

PRs related to this effort welcome and suggestions / feedback appreciated!

Fails to build with 32-bit Go

This error when trying to build with 32-bit version of Go.

# sqlite3-viewer/viewer
viewer\util.go:269:22: constant 9223372036854775807 overflows int
viewer\util.go:274:22: constant 9223372036854775807 overflows int
viewer\viewer.go:8:2: imported and not used: "github.com/mattn/go-runewidth" as runewidth

Builds OK (after removing the unused import) with 64-bit Go.

(Also, I'm on Win7, and the terminal codes do not work with ANSI.)

No installation instructions + getting started

I apologize if this is obvious to Go progammers - but how would one go about installing this on ubuntu (wsl2) with a fresh golang install?

As for getting started instructions, what is the shell command to use it?

Thanks!

Build failes due to "imported and not used" error

go build does not build project due to following error:

# sqlite3-viewer/viewer viewer/viewer.go:8:2: imported and not used: "github.com/mattn/go-runewidth" as runewidth

Removing this import from code fixes issue and build finishes successfuly.

Missing quoting when tables have "special" names

I have a database with a table called transaction. Opening it view the viewer:

panic: SQL logic error: near "transaction": syntax error (1)

goroutine 1 [running]:
sqlite3-viewer/viewer.(*TuiModel).SetModel(0x987d60, 0x0, 0xc0000142c6)
        termdbms/viewer/events.go:171 +0x765
main.main()
        termdbms/main.go:113 +0x4e5

Probably only a missing quoting somewhere...

Schema is:

CREATE TABLE `transaction` (
        id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        sheetId INTEGER NOT NULL,
        transactionId INTEGER NOT NULL,
        lineno INTEGER NOT NULL,
        lineId INTEGER NOT NULL REFERENCES line(id)
);

Crash on DB with many columns?

ts.sqlite.zip

If I open this file and press down arrow twice I get a crash:

panic: runtime error: slice bounds out of range [:-1]                                                                                                                                                                                                                                                                                                                                                                             

goroutine 43 [running]:
sqlite3-viewer/viewer.TruncateIfApplicable(0xc000896340, {0xc00001e680, 0x7})
	~/go/tuitty/viewer/util.go:99 +0x192
sqlite3-viewer/viewer.TuiModel.View.func2(0xc00059c070)
	~/go/tuitty/viewer/viewer.go:121 +0xae5
created by sqlite3-viewer/viewer.TuiModel.View
	~/go/tuitty/viewer/viewer.go:106 +0x272

libsql support (turso)

hello! do you think this could add libsql support so one can use turso? it behaves like sqlite driver (mostly) i think you need to include an import and then allow the user to pass 'libsql' as the driver. it works with sqlite drivers, i think the ones you already use.

https://github.com/tursodatabase/libsql-client-go#readme

Installation
Install the driver into your module:

go get github.com/tursodatabase/libsql-client-go

Import the driver into your code using a blank import:

import (
	_ "github.com/tursodatabase/libsql-client-go/libsql"
)

Ensure all the module requirements are up to date:

go mod tidy

Add support for sqlite3 database files

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.