sqlbless

package module
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 34 Imported by: 0

README

SQL-Bless

Go Test License Go Reference

<English> / <Japanese>

SQL-Bless is a command-line database client similar to SQL*Plus, supporting multiple database systems.

It was designed with reliability and transparency in mind. In the past, I had to deliver an unfinished system due to client pressure, which led to serious data inconsistencies that took enormous effort to fix. That experience made me realize how important it is to have a tool that prevents silent data corruption and keeps a complete, traceable log of every operation. SQL-Bless is the result of that lesson — a tool that values safety over convenience.

  • Emacs-like keybindings for editing multi-line SQL input.
    • Pressing Enter inserts a line break by default.
    • Use the ↑ (Up) arrow key or Ctrl-P to move the cursor to the previous line for editing.
    • Press Ctrl-J or Ctrl-Enter to execute the input immediately.
    • When you press Enter alone, the input is also executed if the last line ends with a semicolon or if the first word is a non-SQL command such as EXIT or QUIT.
  • Save the result of SELECT in CSV format
  • Supported RDBMS
    • SQLite3
    • Oracle
    • PostgreSQL
    • Microsoft SQL Server
    • MySQL
  • Allows editing database records directly, similar to a spreadsheet (with the EDIT command)
  • Transaction mode (auto-commit disabled)
    • A transaction is automatically started when executing DML (INSERT/UPDATE/DELETE)
    • Users cannot input a BEGIN statement (transactions are managed automatically)
    • Transactions can be ended with COMMIT or ROLLBACK
    • Whether DDL (CREATE/ALTER/DROP etc.) can be executed inside a transaction depends on the database:
      • PostgreSQL: All DDL can be executed inside a transaction except VACUUM, REINDEX, CLUSTER, CREATE/DROP DATABASE, and CREATE/DROP TABLESPACE
      • SQLite3: All DDL can be executed inside a transaction except VACUUM
      • Oracle / SQL Server / MySQL: DDL must be executed after ending the transaction with COMMIT or ROLLBACK
      • If a transaction is still active when executing DDL, a warning will be displayed
  • Table name and column name completion
    • Column name completion works only when the corresponding table name appears to the left of the cursor

image

Video by @emisjerry

Key Binding
Enter, Ctrl-M Insert a newline (or execute SQL if line ends with ; or is a short command[^sc])
Ctrl-Enter/J Execute SQL
Ctrl-F/B Move Cursor forward or backward
Ctrl-N/P Move Cursor or refer history
Ctrl-C Exit with rollback
Ctrl-D Delete character or submit EOF (exit with rollback)
ALT-P, Ctrl-Up, PageUp Insert the previous SQL (history)
ALT-N, Ctrl-Down, PageDown Insert the next SQL (history)
TAB Table name and column name completion

[^sc]: DESC, EDIT, EXIT, HISTORY, HOST, QUIT, REM, SPOOL, START, \D

Supported commands

  • SELECT / INSERT / UPDATE / DELETE / MERGE ... ;
    • INSERT, UPDATE, DELETE, and MERGE automatically start a transaction.
    • For these commands, input continues across lines until a semicolon (;) or the string specified with the -term option is entered.
  • COMMIT
  • ROLLBACK ; -- semicolon required
  • SAVEPOINT savepoint;
    (or SAVE TRANSACTION savepoint; for Microsoft SQL Server)
  • ROLLBACK TO savepoint;
    (or ROLLBACK TRANSACTION savepoint; for Microsoft SQL Server)
  • SPOOL
    • spool FILENAME .. open FILENAME and write log and output.
    • spool off .. stop spooling and close.
  • EXIT / QUIT
    • Rollback a transaction and exit SQL-Bless.
  • START filename
    • Start the SQL script given with filename
  • REM comments
  • DESC [tablename] / \D [tablename]
    • When a table name is specified, shows the schema of that table.
    • If omitted, displays a list of tables.
      • In the table list view, the following keys are available:
      • r: Open the EDIT command for the selected table.
      • Enter: Show the schema of the selected table.
  • HISTORY
    • Show the history of input SQLs
  • EDIT [tablename [WHERE conditions...]]
    • Start an editor to modify the selected records of the table.
    • In the editor, these keys are bound.
      • x or d: set NULL to the current cell
      • ESC + y: Apply changes and exit
      • ESC + n: Discard changes and exit
      • q: Now equivalent to ESC
      • c: Apply changes and exit (deprecated)
    • Because the EDIT statement automatically generates SQL from data changed in the editor, it may not be able to properly represent SQL data for special types specific to individual databases. If you find it, we would appreciate it if you could contact us.
  • HOST command-line
    • Executes an operating system command.

 

  • ; (or the string specified with -term string) is a statement seperator when script is executed
  • When sql is input interactively, terminator string (; or the string specified with -term string) is ignored

Example of a spooled file

# (2023-04-17 22:52:16)
# select *
#   from tab
#  where rownum < 5
TNAME,TABTYPE,CLUSTERID
AQ$_INTERNET_AGENTS,TABLE,<NULL>
AQ$_INTERNET_AGENT_PRIVS,TABLE,<NULL>
AQ$_KEY_SHARD_MAP,TABLE,<NULL>
AQ$_QUEUES,TABLE,<NULL>
# (2023-04-17 22:52:20)
# history
0,2023-04-17 22:52:05,spool hoge
1,2023-04-17 22:52:16,"select *
  from tab
 where rownum < 5"
2,2023-04-17 22:52:20,history

Install

Download the binary package from Releases and extract the executable.

via Scoop-installer (Windows)
scoop install https://raw.githubusercontent.com/hymkor/sqlbless/master/sqlbless.json

or

scoop bucket add hymkor https://github.com/hymkor/scoop-bucket
scoop install sqlbless
Installing via Go
go install github.com/hymkor/sqlbless/cmd/sqlbless@latest

Configuration

SQL-Bless does not rely on any external configuration files. All settings—including database connection parameters, output format, and other options—are specified directly via command-line arguments.

For convenience, you can wrap frequently used connection settings in a shell script or batch file. Sample scripts for various databases are provided in this repository (see run-*.cmd). This approach ensures predictable, repeatable startup behavior without relying on hidden configuration files.

How to start

$ sqlbless {options} [DRIVERNAME] DATASOURCENAME

DRIVERNAME can be omitted when DATASOURCENAME contains DRIVERNAME.

SQLite3
$ sqlbless sqlite3 :memory:
$ sqlbless sqlite3 path/to/file.db
Oracle
$ sqlbless oracle oracle://USERNAME:PASSWORD@HOSTNAME:PORT/SERVICE
$ sqlbless oracle://USERNAME:PASSWORD@HOSTNAME:PORT/SERVICE
PostgreSQL
$ sqlbless postgres host=127.0.0.1 port=5555 user=USERNAME password=PASSWORD dbname=DBNAME sslmode=disable
$ sqlbless postgres postgres://USERNAME:PASSWORD@127.0.0.1:5555/DBNAME?sslmode=verify-full
$ sqlbless postgres://USERNAME:PASSWORD@127.0.0.1:5555/DBNAME?sslmode=verify-full
SQL Server
$ sqlbless sqlserver sqlserver://@localhost?database=master

( Windows authentication )

$ sqlbless sqlserver "Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;protocol=lpc"
MySQL
$ sqlbless.exe mysql user:password@/database

Common Options

  • -crlf
    • Use CRLF
  • -fs string
    • Set a field separator (default: ",")
  • -null string
    • Set a string representing NULL (default: ␀)
  • -tsv
    • Use TAB as seperator
  • -f string
    • Start the script
  • -submit-enter
    • Submit by [Enter] and insert a new line by [Ctrl]-[Enter]
  • -debug
    • Print type-information in the header of SELECT and EDIT
  • -spool filename
    • Spool to filename from startup
  • -help
    • Help
  • -rv
    • Use color schemes designed for light (white) backgrounds.
Environment Variables
  • NO_COLOR
    • If defined and non-empty, suppress all color output.
    • If undefined, colors are displayed as usual.
    • (Follows https://no-color.org/)
  • RUNEWIDTH_EASTASIAN
    • "1" — Treat ambiguous-width Unicode characters as double-width (2 cells).
    • Any other non-empty value — Treat them as single-width (1 cell).
  • COLORFGBG
    • When defined in the form (FG);(BG), where (FG) and (BG) are integers representing the foreground and background colors respectively, and (FG) is less than (BG), CSVI assumes a light background and uses colors suitable for it (equivalent to -rv).

Acknowledgements

Author

hymkor (HAYAMA Kaoru)

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTransactionIsNotClosed = errors.New("transaction is not closed. Please Commit or Rollback")
	ErrBeginIsNotSupported    = errors.New("'BEGIN' is not supported; transactions are managed automatically")
	ErrNoDataFound            = errors.New("no data found")
	ErrNotSupported           = errors.New("not supported")
	ErrInvalidRollback        = errors.New("invalid ROLLBACK syntax: expected 'TO' or 'TRANSACTION'")
	ErrNoActiveTransaction    = errors.New("no active transaction")
)
View Source
var Version string

Functions

func Run added in v0.23.0

func Run() error

Types

type Config

type Config struct {
	Auto           string `flag:"auto,autopilot"`
	Term           string `flag:"term,SQL terminator to use instead of semicolon"`
	CrLf           bool   `flag:"crlf,Use CRLF"`
	Null           string `flag:"null,Set a string representing NULL"`
	Tsv            bool   `flag:"tsv,Use TAB as seperator"`
	FieldSeperator string `flag:"fs,Set field separator"`
	Debug          bool   `flag:"debug,Print type in CSV"`
	SubmitByEnter  bool   `flag:"submit-enter,Submit by [Enter] and insert a new line by [Ctrl]-[Enter]"`
	Script         string `flag:"f,script file"`
	SpoolFilename  string `flag:"spool,Spool filename"`
	ReverseVideo   bool   `flag:"rv,Enable reverse-video display (invert foreground and background colors)"`
}

func New added in v0.23.0

func New() *Config

func (*Config) Bind added in v0.23.0

func (cfg *Config) Bind(fs *flag.FlagSet) *Config

func (*Config) Run

func (cfg *Config) Run(driver, dataSourceName string, dbDialect *dialect.Entry) error

type ErrColumnNotFound added in v0.25.0

type ErrColumnNotFound string

func (ErrColumnNotFound) Error added in v0.25.0

func (e ErrColumnNotFound) Error() string

Directories

Path Synopsis
cmd
sqlbless command
sqlite3bless command
internal

Jump to

Keyboard shortcuts

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