A Neovim plugin for PostgreSQL database interaction with an intuitive interface for querying, editing, and exporting data.

- Query Execution: Execute SQL queries and view results in a formatted markdown table
- Data Editing: Edit cell values directly in the result view
- Row Management: Insert new rows, update existing rows, and delete rows
- Column Management: Create, rename, and delete columns in table properties view
- Table Properties Editing: Edit column properties (name, data type, nullable, default values)
- Change Management: Apply, undo, or clear changes before committing to the database
- Export Support: Export query results to CSV or JSON formats
- Syntax Highlighting: Visual highlighting for NULL values, boolean values, edited cells, and deleted rows
- Primary Key Detection: Automatically detects primary keys for safe data updates and deletes
- Table Navigation: Browse database tables and quickly generate SQL templates
- SQL Templates: Quick access to INSERT, SELECT, UPDATE, and DELETE templates from the table list
This plugin requires psql (PostgreSQL command-line client) to be installed and available in your PATH. psql is typically included with PostgreSQL installations.
Using lazy.nvim:
{
"h4kbas/neosql.nvim",
config = function()
require('neosql').setup({
-- configuration options
})
end
}Using packer.nvim:
use 'h4kbas/neosql.nvim'Using vim-plug:
Plug 'h4kbas/neosql.nvim'require('neosql').setup({
bindings = {
query = {
execute = "<CR>",
focus_result = "e",
focus_table_list = "t",
},
result = {
edit_cell = "e",
insert_row = "i",
delete_row = "dd",
apply_changes = "a",
undo_table_changes = "c",
undo_cell_change = "u",
undo_row_changes = "U",
export = "s",
focus_query = "q",
focus_table_list = "t",
},
table_list = {
select_table = "<CR>",
insert_template = "i",
select_template = "s",
update_template = "u",
delete_template = "d",
edit_table_properties = "e",
focus_query = "q",
},
}
}):NeoSqlConnect [connection_string]- Connect to PostgreSQL database using connection string and open views. If no connection string is provided, you'll be prompted to enter one.:NeoSqlOpen- Open neosql views (table list, query, result):NeoSqlClose- Close neosql views:NeoSqlDisconnect- Disconnect from PostgreSQL database
<CR>- Execute querye- Focus result windowt- Focus table list window
e- Edit cell at cursor positioni- Insert new empty row after current rowdd- Delete current row (toggle: press again to undo deletion)a- Apply all changes to database (inserts, updates, and deletes)c- Clear all changes (undo all edits)u- Undo change for current cellU- Undo all changes for current rows- Export results (prompts for filepath, detects format from extension)q- Focus query windowt- Focus table list window
<CR>- Select table and generateSELECT * FROM "table_name" LIMIT 100;querye- Edit table properties (opens column management view)i- Insert template:INSERT INTO "table_name" (?) VALUES (?);s- Select template:SELECT ? FROM "table_name" WHERE ?;u- Update template:UPDATE "table_name" SET ? = ? WHERE ?;d- Delete template:DELETE FROM "table_name" WHERE ?;q- Focus query window
- Execute a SELECT query to view data
- Navigate to the result window and position your cursor on the cell you want to edit
- Press
eto edit the cell - Enter the new value (the plugin will attempt to preserve the data type)
- Press
ato apply all changes to the database
- Position your cursor on the row where you want to insert a new row
- Press
ito insert a new empty row after the current row - Edit the cells in the new row using
e - Press
ato apply all changes (the new row will be inserted into the database)
- Position your cursor on the row you want to delete
- Press
ddto mark the row for deletion (the row will be highlighted with strikethrough) - Press
ddagain on the same row to undo the deletion - Press
ato apply all changes (marked rows will be deleted from the database)
Note: The plugin automatically detects primary keys for the queried table. Updates and deletes are applied using WHERE clauses based on primary key values. If you edit a cell in a deleted row, the deletion is automatically undone and the row becomes an update instead.
The table properties view allows you to manage table columns: create new columns, rename existing columns, modify column properties (nullable, default values), and delete columns.
- Navigate to the table list window
- Position your cursor on the table you want to manage
- Press
eto open the table properties view
- In the table properties view, position your cursor where you want to insert a new column
- Press
ito insert a new empty row (representing a new column) - Edit the cells to set:
column_name(required) - The name of the new columndata_type(required) - The data type (e.g.,VARCHAR(255),INTEGER,TIMESTAMP)is_nullable(optional) - Set toYESorNO(defaults toYESif not specified)column_default(optional) - Default value for the column
- Press
ato apply changes (executesALTER TABLE ... ADD COLUMN)
- In the table properties view, navigate to the column you want to rename
- Press
eto edit thecolumn_namecell - Enter the new column name
- Press
ato apply changes (executesALTER TABLE ... RENAME COLUMN)
- In the table properties view, navigate to the column you want to modify
- Press
eto edit the property cell (is_nullableorcolumn_default) - Enter the new value:
- For
is_nullable: Set toYESorNO - For
column_default: Enter the default value (e.g.,'default_value',0,NOW(), or empty to remove)
- For
- Press
ato apply changes (executesALTER TABLE ... ALTER COLUMN)
- In the table properties view, position your cursor on the column you want to delete
- Press
ddto mark the column for deletion (the row will be highlighted with strikethrough) - Press
ddagain on the same row to undo the deletion - Press
ato apply changes (executesALTER TABLE ... DROP COLUMN)
Note: All column management operations use the same change management system as data editing. You can undo individual changes (u for cell, U for row, c for all changes) before applying them.
- Execute a query to view results
- In the result window, press
sto export - Enter a filepath with a
.csvor.jsonextension - The plugin will automatically detect the format and export accordingly
Supported formats:
- CSV: Exports with proper escaping for commas, quotes, and newlines
- JSON: Exports as a JSON array of objects
- NULL values: Highlighted in gray italic
- Boolean values:
t(true) highlighted in cyan,f(false) highlighted in red - Edited cells: Highlighted in blue bold
- Deleted rows: Highlighted with strikethrough in gray
Connect to database:
Using connection string:
require('neosql').connect("postgresql://user:password@localhost:5432/database")Or using config object:
require('neosql').connect({
host = 'localhost',
port = 5432,
database = 'mydb',
user = 'myuser',
password = 'mypassword',
})Open the interface:
require('neosql').open()Close the interface:
require('neosql').close()Get the app manager for advanced usage:
local app_manager = require('neosql').get_app_manager()