iTranslated by AI
Developing SQL-Bless: A Multi-DB Terminal Client in Go
Long ago, when I first encountered Oracle's standard client SQL*Plus, I felt that while it reliably implemented all the essential features, the editing experience left something to be desired. At the time, I was also developing a command-line shell for OS/2, which made me want to create a client with more advanced editing capabilities. However, the high barrier to entry and my busy schedule ultimately prevented me from making any progress.
Years passed, and the ecosystem has become incredibly rich. With time on my hands, I started development and recently managed to create something reasonably usable. That is SQL-Bless.

Features
A multi-DB terminal-based database client modeled after SQL*Plus. It aims to balance comfortable editing with the safety and reproducibility required for production environments.
1. Comfortable SQL Editing (Multi-line Editing)
Editing supports Emacs-style key bindings and provides completion for table names, column names, and more.
Beyond that, it enables seamless editing of SQL spanning multiple lines. Without having to launch an external editor, you can press the Up arrow key or Ctrl-P to go back to the first line of the SQL statement and make corrections. Furthermore, if you try to move even further up, it behaves like normal Readline history, allowing you to recall previous inputs.
2. Spreadsheet-style Table Editing (edit command)
It includes a built-in terminal CSV editor (csvi), allowing you to edit table data in a spreadsheet-like fashion right from the terminal. The SQL statements that update the data are executed only after individual user confirmation upon finishing the edit, preventing accidents where updates occur without notice.
Updates are performed within transactions, so rollback is also possible.
3. Support for Five Types of Databases
It supports not only Oracle but also SQLite3, MySQL, PostgreSQL, and Microsoft SQL Server.
4. High Safety and Recordability
It starts with auto-commit turned "off" by default. A transaction automatically begins when the user issues DML statements such as UPDATE or INSERT, preventing mistakes like "accidentally editing without starting a transaction."
Additionally, operation logs can be captured using the SPOOL statement.
Log output example
# (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
- Each SQL statement, its execution timestamp, and the results are appended
- SELECT results are immediately converted to CSV format
- While the CSV editor appears on screen, background loading and SPOOL recording continue
- For
editstatements, since the output can be enormous, recording is currently limited to SQL history such asINSERT/DELETE/UPDATE
- To prevent accidental overwriting of past
SPOOLlogs, logs are always appended - During SPOOL, the prompt always displays the spool file name (e.g.,
Spooling to 'debug.lst' now), so you never have to wonder "Is spooling working right now?"
5. Configuration-Free, Standalone Operation
All settings are specified via command-line options. This is to avoid unexpected behavior influenced by configuration files whose locations are unknown. That said, specifying database connection parameters can require quite a few arguments, so typically you would prepare shell aliases or batch files for each connection target.
Example: run-oracle.bat
@rem Sample script to launch SQL-Bless with Oracle DB
@setlocal
@set PROMPT=$G$S
@rem $ sqlbless oracle://USERNAME:PASSWORD@HOST:PORT/SERVICE
sqlbless %* oracle://scott:tiger@localhost:1521/xepdb1
In this way, no environment variables or configuration files are required, and the connection string is handled explicitly, making it easier to maintain reproducibility. Furthermore, the executable is a single binary written in Go, so you can simply copy it and start using it immediately.
Struggles
The database/sql package absorbs some differences in specifications between databases, but creating a general-purpose tool is still quite challenging.
- How to retrieve table and column lists
- Naturally, each database has different specifications for dictionary (metadata) tables, and some use dedicated SQL syntax (e.g., SQLite3's
PRAGMA TABLE_INFO(テーブル名)).
- Naturally, each database has different specifications for dictionary (metadata) tables, and some use dedicated SQL syntax (e.g., SQLite3's
- Placeholder and bind variable formats
- It's not just about differences in expressions like
?,$1,:varname. Some databases (like MS SQL Server) require pairing name and value withsql.Named, while others have no such pairing at all.
- It's not just about differences in expressions like
- Date/time type variations
- Some databases have explicit date-time types, while in others they are merely hints for column attributes. Cases where
2006-01-02 15:04:05and2006-01-02T15:04:05Zrepresent the same thing despite being different formats caused great difficulty.
- Some databases have explicit date-time types, while in others they are merely hints for column attributes. Cases where
- Handling of transactions
- Implementing features like warnings before forcibly committing SQL statements, and displaying whether a transaction is active in the prompt, was good. However, the set of SQL statements that force a commit varies widely between databases.
Ultimately, I defined a structure to handle the differences between databases and centralized the management there. I plan to write a separate article explaining the details sometime.
On the other hand, the standout features of this tool—multi-line editing and spreadsheet editing—did not require much struggle to implement, as I leveraged modules that had been cultivated over time as general-purpose tools or libraries in collaboration with contributors to each package.
During the development of SQL-Bless, I further evolved those existing modules and restructured the entire system with a clean architecture. In the process, I also virtualized terminal key input using the following interface specification, making it swappable during testing.
type Tty interface {
Open(onResize func(int, int)) error
GetKey() (string, error)
Size() (int, int, error)
Close() error
}
This enables automated testing of all operations, including the edit command. Currently, simulated operation tests using an in-memory SQLite3 database run on GitHub Actions.
Future Development
SQL-Bless is still more of a "tool I want to nurture" than a "finished product." Having been accustomed to Oracle for many years, the operation feel naturally leans toward Oracle.
On the other hand, there is still room for improvement in usability rooted in the cultures of MySQL, PostgreSQL, SQLite, etc.
Also, since I've recently stepped away from jobs that involve daily use of databases, I lack "hands-on production usage" and "dogfooding in real business contexts."
If you read this article and think "I might give it a try," please feel free to share your thoughts. Pull Requests and Issues are welcome, and even brief impressions would be greatly appreciated. I aim to grow this into a truly usable SQL client for the field, balancing safety and reproducibility.
Discussion