### Configure sqmeow with setup() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Example of calling sqmeow.setup() with a partial table to override only named keys, such as the drawer width. ```lua require('sqmeow').setup({ ui = { drawer = { width = 40 } }, }) ``` -------------------------------- ### Install sqmeow engine with specific methods Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Examples of installing the engine with different methods: 'cargo', 'wget', and a table with a version. Without a method, downloads a release then falls back to cargo. ```lua require('sqmeow').install('cargo') ``` ```lua require('sqmeow').install('wget') ``` ```lua require('sqmeow').install({ version = '1.0.2' }) ``` -------------------------------- ### Setup with default options Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Call setup() to customize sqmeow.nvim behavior. The example shows common options with their defaults, including UI drawer position and width, result height and page size, query limits, and redaction of URLs. Set max_rows = 0 for unlimited rows or timeout_ms = 0 to disable query deadlines. ```lua require("sqmeow").setup({ ui = { drawer = { position = "left", width = 36 }, result = { height = 16, page_size = 100, max_column_width = 48 }, persist_session = false, }, query = { max_rows = 100000, timeout_ms = 0, persist_history = true, confirm_destructive = true, }, redact_urls = true, }) ``` -------------------------------- ### Development setup commands Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/CONTRIBUTING.md Run these commands after entering the repository directory to start the Nix development environment and build the project. The initial setup may take a while as Nix downloads and builds dependencies. On slower machines, use `-j 1` with Cargo and run checks individually to reduce memory usage. ```sh nix develop cargo build -j 1 ``` -------------------------------- ### Install sqmeow engine via build hook Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Example of installing the engine binary from a build hook. Call it from a build hook; nothing else installs it. ```lua { '2giosangmitom/sqmeow.nvim', dependencies = { 'MunifTanjim/nui.nvim' }, build = function() require('sqmeow').install() end, opts = {}, } ``` -------------------------------- ### sqmeow.install({opts}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Installs the engine binary. Call it from a build hook, nothing else installs it. Without a method, downloads a release then falls back to cargo. Methods: 'cargo', 'curl', 'wget' and 'powershell'. Blocks until done unless a callback is given. ```APIDOC ## sqmeow.install({opts}) ### Description Installs the engine binary. Call it from a build hook, nothing else installs it. Without a method, downloads a release then falls back to cargo. Methods: 'cargo', 'curl', 'wget' and 'powershell'. Blocks until done unless a callback is given. ### Parameters - **opts** (string|table|nil) - Optional - A method name, or a table of `method`, `version`, `callback` and `timeout` in milliseconds. ### Return Values - **ok** (boolean|nil) - Whether an engine was installed, or nil when a `callback` was given. - **err** (string|nil) - Error message if any. ### Usage Examples ```lua require('sqmeow').install('cargo') require('sqmeow').install('wget') require('sqmeow').install({ version = '1.0.2' }) ``` ``` -------------------------------- ### Quick start: Run SELECT 1 in a scratchpad Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Used in the quick start workflow to verify the plugin works. After opening the drawer with :Sqmeow, adding a connection, and creating a scratchpad, write this SQL and press to run the statement under the cursor. ```sql SELECT 1; ``` -------------------------------- ### Configure blink.cmp for Sqmeow completion Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Adds the 'sqmeow' source to blink.cmp. Requires blink.cmp to be installed. For query-aware column and alias suggestions, install the SQL Tree-sitter parser (e.g., :TSInstall sql). ```lua require("blink.cmp").setup({ sources = { default = { "lsp", "path", "buffer", "sqmeow" }, providers = { sqmeow = { name = "Sqmeow", module = "sqmeow.completion.blink", }, }, }, }) ``` -------------------------------- ### Database Test Setup and Teardown with Just Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/CONTRIBUTING.md Start test databases with `just db-up`, run Rust and Lua tests, then stop databases and remove test data with `just db-down`. Tests requiring unavailable database servers are skipped automatically. ```sh # Start test databases just db-up # Run your tests just test-rust just test-lua # Stop databases and remove test data just db-down ``` -------------------------------- ### mini.deps plugin configuration Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Configure sqmeow.nvim with mini.deps. Add this after setting up mini.deps. Tracks the default branch and builds the engine from source; for a release, set checkout to a release tag and call install() in the hook. ```lua local install_engine = function() vim.schedule(function() require("sqmeow").install("cargo") end) end MiniDeps.add({ source = "2giosangmitom/sqmeow.nvim", depends = { "MunifTanjim/nui.nvim" }, hooks = { post_install = install_engine, post_checkout = install_engine, }, }) ``` -------------------------------- ### Configure nvim-cmp for Sqmeow completion Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Registers the 'sqmeow' source with nvim-cmp and adds it to the sources list. Requires nvim-cmp to be installed. For query-aware column and alias suggestions, install the SQL Tree-sitter parser (e.g., :TSInstall sql). ```lua local cmp = require("cmp") cmp.register_source("sqmeow", require("sqmeow.completion.cmp").new()) cmp.setup({ sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "sqmeow" }, }), }) ``` -------------------------------- ### Default configuration for sqmeow Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Default configuration table with core settings. Pass only changed fields to setup. Icons control display glyphs. ```lua sqmeow.config.defaults = { core = { -- The directory the plugin keeps its files in. path = vim.fs.joinpath(vim.fn.stdpath('data'), 'sqmeow'), -- One of 'error', 'warn', 'info', 'debug', 'trace'. log_level = 'warn', }, } ``` -------------------------------- ### blink.cmp setup for Sqmeow completion Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Configures blink.cmp to use the Sqmeow completion source. Requires the 'sql' Tree-sitter parser for query-aware completion; without it, plain metadata and 'table.' column completion still work. ```lua require('blink.cmp').setup({ sources = { default = { 'lsp', 'path', 'buffer', 'sqmeow' }, providers = { sqmeow = { name = 'Sqmeow', module = 'sqmeow.completion.blink', }, }, }, }) ``` -------------------------------- ### lazy.nvim plugin configuration Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Configure sqmeow.nvim with lazy.nvim. Requires Neovim 0.10+ and nui.nvim. The build hook installs the engine; remove the version setting and use install("cargo") to track master. ```lua { "2giosangmitom/sqmeow.nvim", version = "*", dependencies = { "MunifTanjim/nui.nvim" }, build = function() require("sqmeow").install() end, opts = {}, cmd = "Sqmeow", } ``` -------------------------------- ### nvim-cmp setup for Sqmeow completion Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Configures nvim-cmp to use the Sqmeow completion source. Requires the 'sql' Tree-sitter parser for query-aware completion; without it, plain metadata and 'table.' column completion still work. ```lua require('cmp').setup({ sources = { { name = 'sqmeow' }, -- ... }, }) require('cmp').register_source('sqmeow', require('sqmeow.completion.cmp').new()) ``` -------------------------------- ### vim.pack plugin configuration Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Configure sqmeow.nvim with vim.pack (Neovim 0.12+). Register the handler before vim.pack.add(). Run :packupdate to update plugins. To track master, remove the release version setting and use install("cargo"). ```lua vim.api.nvim_create_autocmd("PackChanged", { callback = function(event) local data = event.data if data.spec.name ~= "sqmeow.nvim" or (data.kind ~= "install" and data.kind ~= "update") then return end vim.schedule(function() require("sqmeow").install() end) end, }) vim.pack.add({ "https://github.com/MunifTanjim/nui.nvim", { src = "https://github.com/2giosangmitom/sqmeow.nvim", version = vim.version.range(">=0.0.0"), }, }) ``` -------------------------------- ### Command: Execute a line range with :Sqmeow execute Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Runs an inclusive line range of the current buffer. The example `:2,5Sqmeow execute` executes lines 2 through 5. ```vim :2,5Sqmeow execute ``` -------------------------------- ### Example of status() return table Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Shows the structure of the table returned by `require("sqmeow.api.view").status()`. `status()` returns `nil` outside database buffers. `staged_changes` counts edits across all open results, `column` is set only in the result grid, and `state`/row counts describe the call whose connection matches the buffer. ```lua local info = require("sqmeow.api.view").status() -- info = { -- connection = "dev", -- dialect = "postgres", -- database = nil, -- read_only = false, -- role = "query", -- "query" | "result" | "drawer" | "preview" | "alter" | "routine" -- state = "done", -- "executing" | "done" | "error" | "cancelled" -- rows = 142, -- view_rows = nil, -- set when filtered -- affected = nil, -- set for UPDATE / DELETE / INSERT -- truncated = false, -- elapsed_ms = 12, -- elapsed = "12ms", -- page = 1, -- total_pages = 2, -- filtered = false, -- staged_changes = 0, -- error = nil, -- set when state is "error" -- column = { index = 1, total = 6, name = "id", type_name = "int4", class = "number" }, -- } ``` -------------------------------- ### Get relationships for a table Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Returns the relationships for the given connection, schema, and relation. Empty sections show `None`; unsupported adapters and metadata failures error. Needs an open connection; close/disconnect/restart voids pending replies. Never fetches rows or infers cardinality. ```lua require('sqmeow.api.view').relationships(1, 'public', 'orders') ``` -------------------------------- ### Group snapshot with Polars aggregates Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Groups the snapshot locally with Polars aggregates. Output is read-only and exportable. Empty group_by/aggregates/having clears, source stays. Returns a boolean indicating whether the aggregation started. ```lua require('sqmeow.api.view').aggregate({ group_by = 'country', aggregates = 'COUNT(*) AS users, SUM(amount) AS total', having = 'users >= 10', order_by = 'total DESC', }) ``` -------------------------------- ### Get status for current buffer Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Returns connection, buffer role, and query telemetry for a buffer. Returns nil outside database buffers. The `state` and row counts describe the call whose connection matches the buffer, except in the result grid. `staged_changes` counts staged edits across all open results. ```lua local info = require('sqmeow.api.view').status() if info then print(('%s · %s'):format(info.connection or info.role, info.state or 'idle')) end ``` -------------------------------- ### Filter kept rows with Polars SQL Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Filters kept rows using Polars SQL WHERE + ORDER BY. Same syntax everywhere, including disconnected and restored history. No rerun. Empty clears; kept rows only. Returns a boolean indicating whether the filter started. ```lua require('sqmeow.api.view').filter({ where = "name like 'a%'", order_by = 'age desc' }) ``` -------------------------------- ### sqmeow.setup({opts}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Configures the plugin. Optional; partial tables override only named keys. ```APIDOC ## sqmeow.setup({opts}) ### Description Configures the plugin. Optional; partial tables override only named keys. ### Parameters - **opts** (table|nil) - Optional - See |sqmeow-config|. ### Usage Example ```lua require('sqmeow').setup({ ui = { drawer = { width = 40 } }, }) ``` ``` -------------------------------- ### Connect using a database URL in connections.toml Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Alternative connection method using a URL. Set DATABASE_URL in the environment or in a .env file next to .sqmeow/. Environment variables take precedence over .env values. Keep .env out of version control and reconnect after changing credentials. ```toml [dev] url = "{{ env 'DATABASE_URL' }}" read_only = true ``` -------------------------------- ### Configure keymaps in sqmeow.setup() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Sets buffer-local keymaps for the drawer, results, and editor surfaces. String sets one key, list sets aliases, and false disables the action. Unset keys keep defaults; '?' shows resolved mappings and ':checkhealth sqmeow' flags unknown action names. ```lua require('sqmeow').setup({ keymaps = { drawer = { close = { 'q', '' } }, result = { next_page = '', prev_page = '' }, editor = { execute_buffer = 'rr', cancel = false }, }, }) ``` -------------------------------- ### sqmeow.api.view.scratchpad(name, default, store) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Creates a scratchpad. A '/' in the name creates folders. ```APIDOC ## sqmeow.api.view.scratchpad(name, default, store) ### Description Creates a scratchpad. A '/' in the name creates folders. ### Parameters - **name** (string|nil) - Name with extension (e.g., `report.sql`, `reports/monthly.sql`). If given, created directly; if missing, prompts. - **default** (string|nil) - Prefilled prompt when asking, such as a folder followed by `/`. - **store** (table|nil) - Internal file operations for the selected drawer section. ``` -------------------------------- ### Configure Sqmeow and lualine.nvim statusline Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Sets up Sqmeow with winbars disabled and configures lualine.nvim to display connection and query telemetry. The `query` function builds a status string from `view.status()`, and `view.column()` shows the active result column. Requires lualine.nvim and the Sqmeow plugin. ```lua require("sqmeow").setup({ ui = { -- Hide winbars when showing connection and result telemetry in lualine: winbar = false, -- Or configure editor and result winbars independently: -- winbar = { editor = false, result = true, show_connection = false }, }, }) local view = require("sqmeow.api.view") local function query() local info = view.status() if not info then return "" end local parts = { info.connection or info.role } if info.read_only then parts[#parts + 1] = "󰌾" end if info.state == "executing" then parts[#parts + 1] = "running…" elseif info.state == "error" then parts[#parts + 1] = info.error and ("error: " .. info.error) or "error" elseif info.state == "cancelled" then parts[#parts + 1] = "cancelled" elseif info.state == "done" then if info.view_rows then parts[#parts + 1] = ("%d/%d rows"):format(info.view_rows, info.rows or 0) elseif info.rows then parts[#parts + 1] = ("%d rows"):format(info.rows) elseif info.affected then parts[#parts + 1] = ("%d affected"):format(info.affected) end if info.elapsed then parts[#parts + 1] = info.elapsed end if info.total_pages and info.total_pages > 1 then parts[#parts + 1] = ("p%d/%d"):format(info.page or 1, info.total_pages) end if info.filtered then parts[#parts + 1] = "filtered" end end if info.staged_changes > 0 then parts[#parts + 1] = "●" end return table.concat(parts, " · ") end require("lualine").setup({ sections = { lualine_x = { -- Active column name and SQL type when focused inside the result grid (e.g. `󰠵 user_id (int4)`) { view.column, cond = function() return view.column() ~= "" end, }, }, lualine_y = { -- Active connection and query telemetry (e.g. `dev · 142 rows · 12ms`) { query, cond = function() return view.status() ~= nil end, }, }, }, }) ``` -------------------------------- ### Typical Git Workflow with Just Commands Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/CONTRIBUTING.md Standard workflow for creating a branch, making changes, and running relevant checks. Use `just lint`, `just test-rust`, and `just test-lua` to validate changes before pushing. ```sh # Create a branch git checkout -b fix/short-description # Make your changes, then run the relevant checks just lint just test-rust just test-lua ``` -------------------------------- ### connect({url}, {opts}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Opens a database connection using the provided URL and options. Returns a connection id or nil if the engine refused the request. ```APIDOC ## connect({url}, {opts}) ### Description Opens a connection. Returns when the engine accepts; success arrives as an event. ### Parameters - **url** (string) - Required - A database URL, such as `sqlite://app.db` or `postgres://localhost/app`. - **opts** (table|nil) - Optional - `name` labels it; `database` and `parent` identify a child database; `read_only` rejects writes; `ssh` selects an SSH host or alias. Project sources carry an `env_file` path for project-local credential templates. ### Returns - **id** (integer|nil) - The connection id, or nil if the engine refused the request. - **error** (string|nil) ### Usage ```lua require('sqmeow.api.connection').connect('sqlite://./app.db', { name = 'app' }) ``` ``` -------------------------------- ### sqmeow.api.view.open_all() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Opens the drawer and the result window. ```APIDOC ## sqmeow.api.view.open_all() ### Description Opens the drawer and the result window. ### Parameters None. ``` -------------------------------- ### available() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Reads configured sources without connecting. Returns entries in source order with duplicates removed, along with a list of problems. ```APIDOC ## available() ### Description Read configured sources without connecting. Returns entries in source order, dupes removed. Problems lists failures and conflicts; usable entries stay. Project parsing may start the engine. Templates resolve only on connect. ### Returns - **connections** (sqmeow.ConnectionSpec[]) - The list of connection specifications. - **problems** (string[]) - List of problems encountered. ``` -------------------------------- ### sqmeow.config.get() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Returns the active configuration. ```APIDOC ## sqmeow.config.get() ### Description Returns the active configuration. ### Method Function call ### Return - **config** (table) - The active configuration. ``` -------------------------------- ### sqmeow.keymap.summary() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Returns every surface's mappings as lines, intended for generating a help file. This provides a complete overview of all keybindings. ```APIDOC ## sqmeow.keymap.summary() ### Description Returns every surface's mappings as lines, for the help file. ### Return - `(string[])` - A list of lines describing all mappings. ``` -------------------------------- ### sqmeow.api.connection.connections() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Returns a list of all open connections. ```APIDOC ## sqmeow.api.connection.connections() ### Description Returns a list of all open connections. ### Returns - **connections** (sqmeow.Connection[]) - All open connections. ``` -------------------------------- ### sqmeow.api.query.first_page() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Shows the first page of the current result set. ```APIDOC ## sqmeow.api.query.first_page() ### Description Shows the first page of the current result set. ### Method Function call ### Endpoint `sqmeow.api.query.first_page()` ### Parameters None ### Return None ``` -------------------------------- ### sqmeow.api.query.execute_buffer() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Runs the entire current buffer as SQL. ```APIDOC ## sqmeow.api.query.execute_buffer() ### Description Runs the entire current buffer as SQL. ### Returns - **call_id** (integer|nil) - Accepted run id. - **error** (string|nil) - Error, including deferred prompts. ``` -------------------------------- ### sqmeow.config.apply({opts}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Merges a user configuration over the defaults and makes it current. Returns the merged configuration and any problems found. ```APIDOC ## sqmeow.config.apply({opts}) ### Description Merges a user configuration over the defaults and makes it current. ### Method Function call ### Parameters - **opts** (table|nil) - Configuration as passed to `setup()`. ### Return - **config** (table) - The merged configuration. - **errors** (string[]) - Problems found. ``` -------------------------------- ### sqmeow.api.view.toggle() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Shows everything, or hides all when anything shows. ```APIDOC ## sqmeow.api.view.toggle() ### Description Shows everything, or hides all when anything shows. ### Parameters None. ``` -------------------------------- ### List source errors with sqmeow.api.connection.available() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Use this snippet to list source errors when a connection is missing from the drawer. It prints errors from the available() function. ```lua local _, errors = require('sqmeow.api.connection').available() vim.print(errors) ``` -------------------------------- ### Connect to a database with sqmeow.api.connection.connect() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Opens a connection using a database URL and optional options. The `name` option labels the connection, `database` and `parent` identify a child database, `read_only` rejects writes, and `ssh` selects an SSH host or alias. Returns the connection id or nil if the engine refused the request. ```lua require('sqmeow.api.connection').connect('sqlite://./app.db', { name = 'app' }) ``` -------------------------------- ### Template syntax for secrets Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Shows the three template types available in connection URLs: env reads an environment variable, file reads a UTF-8 file with trailing whitespace trimmed, and exec runs a shell command with trailing whitespace trimmed. Shell commands time out after 30 seconds. ```text {{ env "PGPASSWORD" }} Read an environment variable. {{ file "~/.secrets/database" }} Read a UTF-8 file; trailing whitespace is trimmed. {{ exec "pass show db/dev" }} Run a shell command; trailing whitespace is trimmed. ``` -------------------------------- ### sqmeow.api.query.execute({sql}, {opts}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Executes SQL statements and opens the result window. Supports connection selection, statement targeting, and options for history, confirmation, and parameters. ```APIDOC ## sqmeow.api.query.execute({sql}, {opts}) ### Description Executes SQL statements and opens the result window. Supports connection selection, statement targeting, and options for history, confirmation, and parameters. ### Parameters - **sql** (string) - Required - One or more statements in the connection's dialect. - **opts** (table|nil) - Optional - Options table: - **conn_id** (integer) - Optional - Picks a connection. - **source_buf** (integer) - Optional - Buffer for binding lookup. - **line** (integer) - Optional - Zero-based line to select a statement. - **where** (string) - Optional - Wraps one query. - **order_by** (string) - Optional - Wraps one query. - **history** (boolean) - Optional - Set to false to skip log+archive. - **confirmed** (boolean) - Optional - Set to true to skip destructive prompt. - **parameters** (table) - Optional - Maps names to raw input strings, skipping prompts. ### Returns - **call_id** (integer|nil) - Accepted run id; nil when rejected or waiting input. - **error** (string|nil) - Reason, or what is being waited on. ``` -------------------------------- ### sqmeow.config.winbar({part}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Returns whether a winbar surface ('editor', 'result', or 'show_connection') is enabled. ```APIDOC ## sqmeow.config.winbar({part}) ### Description Returns whether a winbar surface ('editor', 'result', or 'show_connection') is enabled. ### Method Function call ### Parameters - **part** (string) - One of 'editor', 'result', or 'show_connection'. ### Return - **boolean** - Whether the winbar surface is enabled. ``` -------------------------------- ### sqmeow.keymap.register_plug() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Defines the `` mappings for the plugin. This is used to set up custom mapping hooks. ```APIDOC ## sqmeow.keymap.register_plug() ### Description Define the `` mappings. ``` -------------------------------- ### require("sqmeow.api.view").status() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Returns the current buffer's state as a plain table, including connection and query telemetry. Returns nil outside database buffers. ```APIDOC ## status() ### Description Returns the current buffer's state as a plain table, including connection and query telemetry. Returns nil outside database buffers. ### Method Function call ### Endpoint `require("sqmeow.api.view").status()` ### Parameters None ### Return Value - **table or nil** - A table with the following fields: - `connection` (string) - Connection name - `dialect` (string) - Database dialect - `database` (string or nil) - Database name - `read_only` (boolean) - Whether the buffer is read-only - `role` (string) - Buffer role: "query" | "result" | "drawer" | "preview" | "alter" | "routine" - `state` (string) - Query state: "executing" | "done" | "error" | "cancelled" - `rows` (number) - Number of rows - `view_rows` (number or nil) - Number of visible rows when filtered - `affected` (number or nil) - Number of affected rows for UPDATE/DELETE/INSERT - `truncated` (boolean) - Whether results are truncated - `elapsed_ms` (number) - Elapsed time in milliseconds - `elapsed` (string) - Elapsed time as a string (e.g., "12ms") - `page` (number) - Current page number - `total_pages` (number) - Total number of pages - `filtered` (boolean) - Whether results are filtered - `staged_changes` (number) - Number of staged changes across all open results - `error` (string or nil) - Error message when state is "error" - `column` (table or nil) - Active column info when in result grid: `{ index, total, name, type_name, class }` ### Example ```lua local info = require("sqmeow.api.view").status() -- info = { -- connection = "dev", -- dialect = "postgres", -- database = nil, -- read_only = false, -- role = "query", -- state = "done", -- rows = 142, -- view_rows = nil, -- affected = nil, -- truncated = false, -- elapsed_ms = 12, -- elapsed = "12ms", -- page = 1, -- total_pages = 2, -- filtered = false, -- staged_changes = 0, -- error = nil, -- column = { index = 1, total = 6, name = "id", type_name = "int4", class = "number" }, -- } ``` ``` -------------------------------- ### sqmeow.api.query.execute_selection() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Runs the most recent visual selection as SQL. ```APIDOC ## sqmeow.api.query.execute_selection() ### Description Runs the most recent visual selection as SQL. ### Returns - **call_id** (integer|nil) - Accepted run id. - **error** (string|nil) - Error. ``` -------------------------------- ### Execute a query with parameters from Lua Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Pass raw input strings in the `parameters` map to answer prompts programmatically. An empty map falls back to declared defaults; missing required values fail before anything runs. Supplied values are not written to history. ```lua require('sqmeow.api.query').execute(sql, { parameters = { user_id = '42' } }) ``` -------------------------------- ### sqmeow.api.query.prev_page() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Shows the previous page of the current result. ```APIDOC ## sqmeow.api.query.prev_page() ### Description Shows the previous page of the current result. ``` -------------------------------- ### TOML connection configuration with env template Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Defines two database connections in a TOML file. The first uses type and dialect fields with an env template for the password; the second uses a URL with an env template. Only the nearest config file is used, and parent configs are not merged. ```toml [dev_db] type = "postgres" host = "localhost" port = 5432 database = "my_app_dev" user = "dev_user" password = '{{ env "PGPASSWORD" }}' read_only = true [local_sqlite] type = "sqlite" path = ".sqmeow/test.db" ``` -------------------------------- ### sqmeow.api.query.next_page() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Shows the next page of the current result. ```APIDOC ## sqmeow.api.query.next_page() ### Description Shows the next page of the current result. ``` -------------------------------- ### sqmeow.api.view.open_drawer() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Shows the schema drawer. On a supported table, pressing 'e' opens an unexecuted in-memory scratch buffer bound to that connection; column names and current types prefill separate ALTER statements. On functions and procedures, 'e' fetches the complete stored definition into a bound scratch buffer. 'K' shows the full definition in a read-only popup. ```APIDOC ## sqmeow.api.view.open_drawer() ### Description Shows the schema drawer. On a supported table, pressing 'e' opens an unexecuted in-memory scratch buffer bound to that connection; column names and current types prefill separate ALTER statements. On functions and procedures, 'e' fetches the complete stored definition into a bound scratch buffer. 'K' shows the full definition in a read-only popup. ### Parameters None. ### Returns - **win** (integer) - The window ID of the drawer. ``` -------------------------------- ### sqmeow.keymap.problems() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Returns a list of overrides that name an action the surface does not have. This helps identify configuration errors. ```APIDOC ## sqmeow.keymap.problems() ### Description Returns overrides that name an action the surface does not have. ### Return - `(string[])` - A list of problematic override names. ``` -------------------------------- ### use({id}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Picks the default target for unbound buffers. Never connects or waits; bound buffers keep their own target. ```APIDOC ## use({id}) ### Description Pick the default target for unbound buffers. Never connects or waits. Bound buffers keep their own target. ### Parameters - **id** (integer) - Required ### Returns - **connection** (sqmeow.Connection|nil) - The one now active, or nil if there is no such id. ``` -------------------------------- ### Snapshot aggregation with GROUP BY and AGGREGATE Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Press `gG` for GROUP BY in the same bar. List plain column names in GROUP BY and built-in aggregates with explicit aliases in AGGREGATE. Everything runs locally through Polars over the snapshot you already queried. WHERE filters before grouping; HAVING filters on the output names after aggregation. Aggregate outputs are read-only; settle or discard staged edits before aggregating. ```sql WHERE active = 1 ORDER BY total DESC GROUP BY country AGGREGATE COUNT(*) AS users, SUM(amount) AS total HAVING users >= 10 ``` -------------------------------- ### connect_named({name}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Opens a named source entry with its read-only and SSH settings. Reuses an open connection only when its definition matches. ```APIDOC ## connect_named({name}) ### Description Open a named source entry with its read-only and SSH settings. Reuses an open connection only when its definition matches. Disconnect first when definitions changed. Returned id may still be connecting; it never proves login worked. ### Parameters - **name** (string) - Required - The name the source gave it. ### Returns - **id** (integer|nil) - **error** (string|nil) ``` -------------------------------- ### sqmeow.config.border() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Returns the border style dialogs are drawn with. ```APIDOC ## sqmeow.config.border() ### Description Returns the border style dialogs are drawn with. ### Method Function call ### Return - **style** (string|string[]) - The border style. ``` -------------------------------- ### TOML URL connection with env template Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Defines a connection using a complete URL with an env template. URL entries need no type field, and read_only and ssh settings work with them. ```toml [dev_url] url = "{{ env 'DATABASE_URL' }}" read_only = true ``` -------------------------------- ### Run a Single SQLite Integration Test with Nix Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/CONTRIBUTING.md Run a specific SQLite integration test using `nix develop` and `cargo test` with exact match and single-threaded execution. For other databases, set the corresponding `SQMEOW_TEST_*_URL` environment variable and replace `sqlite` with the appropriate test target. ```sh nix develop --command cargo test -j 1 \ -p sqmeow-adapters \ --test sqlite \ relationships_preserve_catalog_endpoints \ -- --exact --test-threads=1 --nocapture ``` -------------------------------- ### save({name}, {url}, {opts}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Persists a connection to the file source, replacing same-named file entries. Does not open a connection or write to project sources. ```APIDOC ## save({name}, {url}, {opts}) ### Description Persist a connection to the file source. Replaces same-named file entries. Never opens a connection or writes to project sources. Templates stay raw. ### Parameters - **name** (string) - Required - **url** (string) - Required - **opts** (table|nil) - Optional - `read_only` saves it as a connection that runs only statements that read, and `ssh` as one reached through an SSH tunnel to that `user@host`. ### Returns - **written** (boolean) ``` -------------------------------- ### sqmeow.api.view.review() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Reviews the statements for staged edits. Apply them with `` in the review. ```APIDOC ## sqmeow.api.view.review() ### Description Reviews the statements for staged edits. Apply them with `` in the review. ### Method Function call ### Endpoint `sqmeow.api.view.review()` ### Parameters None ### Return None ``` -------------------------------- ### Define project-specific connections in .sqmeow/connections.toml Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/README.md Configure named connections for a project. The nearest project configuration overrides saved connections with the same name. Relative database paths are resolved from the project root. Supports environment variable interpolation with {{ env 'VAR' }}. ```toml [dev] type = "postgres" host = "localhost" port = 5432 database = "my_app" user = "dev_user" password = "{{ env 'PGPASSWORD' }}" [local] type = "sqlite" path = "app.db" ``` -------------------------------- ### Common URL forms for Sqmeow connections Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt List of URL formats for supported databases. Percent-encode reserved characters in credentials (e.g., '@' as '%40'); the input form and project field loader do this automatically. For Redis Cluster or Sentinel, use 'redis+cluster://' or 'redis+sentinel://'. ```text postgres://user:password@localhost:5432/app mysql://user:password@localhost:3306/app mssql://sa:password@localhost:1433/master sqlite:/absolute/path/app.db duckdb:/absolute/path/app.duckdb redis://localhost:6379/0 mongodb://localhost:27017/app scylla://localhost:9042/keyspace surrealdb://root:password@localhost:8000/namespace/database clickhouse://localhost:8123/default oracle://user:password@localhost:1521/FREEPDB1 ``` -------------------------------- ### sqmeow.api.view.open() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Opens the result window. On Neovim 0.11+, drawer and result windows use 'winfixbuf', so editing commands that would replace the buffer fail with E1513; switch to an editing window first. ```APIDOC ## sqmeow.api.view.open() ### Description Opens the result window. On Neovim 0.11+, drawer and result windows use 'winfixbuf', so editing commands that would replace the buffer fail with E1513; switch to an editing window first. ### Parameters None. ``` -------------------------------- ### sqmeow.api.export.export({opts}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Exports kept rows to a file or clipboard asynchronously. If no path or clipboard is provided, opens a preview dialog. Uses visible columns and the current view unless 'all' is true, and never reruns the query. ```APIDOC ## sqmeow.api.export.export({opts}) ### Description Exports kept rows to a file or clipboard, asynchronously. If no `path` or `clipboard` is provided, opens a preview dialog. Uses visible columns and the current view unless `all` is true. Never reruns the query. ### Parameters - `opts` (table|nil) - Optional - Options table with the following fields: - `format` (string) - Optional - Export format: `csv` (default), `json`, or `sql`. - `path` (string) - Optional - File destination path. - `clipboard` (boolean) - Optional - If `true`, copies to clipboard instead of writing to file. - `headers` (boolean) - Optional - If `false`, omits CSV headers. - `offset` (integer) - Optional - Zero-based row offset for selecting rows. - `limit` (integer) - Optional - Maximum number of rows to export. - `table` (string) - Optional - SQL option: overrides the target table name. - `batch` (boolean) - Optional - SQL option: combines INSERT rows into batches. - `create` (boolean) - Optional - SQL option: includes DDL (CREATE TABLE) statements. - `all` (boolean) - Optional - If `true`, exports retained rows outside the current filtered view. ### Behavior - If neither `path` nor `clipboard` is provided, opens a preview dialog. - Uses visible columns and the current view unless `all` is true. - Does not rerun the query. ``` -------------------------------- ### Run Cargo Tests with Nocapture to See Skip Messages Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/CONTRIBUTING.md Run Rust tests with `--nocapture` to display skip messages for tests that were skipped due to unavailable database servers. ```sh cargo test -- --nocapture ``` -------------------------------- ### Declare parameter types and defaults in a header comment Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Placeholder declarations use `-- @param name type = default` lines above the query. Supported types are `text`, `int`, `float`, and `bool`; typing `NULL` binds a null of the declared type. Placeholders cannot replace table or column names and cannot mix with native positional placeholders. ```sql -- @param user_id int = 42 -- @param status text = active SELECT * FROM users WHERE id = :user_id AND status = :status; ``` -------------------------------- ### sqmeow.api.connection.target({buf}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Resolves a buffer's target connection, preferring a named binding and falling back to the active connection. Returns an error if no bound connection exists. ```APIDOC ## sqmeow.api.connection.target({buf}) ### Description Resolves a buffer's target connection, preferring a named binding and falling back to the active connection. Returns an error if no bound connection exists. ### Parameters - **buf** (integer|nil) - Optional - Defaults to the current buffer. ### Returns - **connection** (sqmeow.Connection|nil) - The resolved connection. - **error** (string|nil) - Why there is no connection. ``` -------------------------------- ### sqmeow.api.view.restore(entry) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Shows an archived result the engine dropped, from the copy next to the log. ```APIDOC ## sqmeow.api.view.restore(entry) ### Description Shows an archived result the engine dropped, from the copy next to the log. ### Parameters - **entry** (table) - Required - From the query log, with a saved result. ### Returns - **call_id** (integer|nil) - The call ID of the restored result. - **error** (string|nil) - Error message if restoration failed. ``` -------------------------------- ### sqmeow.api.query.execute_range({first}, {last}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Runs a one-based, inclusive line range from the current buffer. ```APIDOC ## sqmeow.api.query.execute_range({first}, {last}) ### Description Runs a one-based, inclusive line range from the current buffer. ### Parameters - **first** (integer) - Required - First line, counted from one. - **last** (integer) - Required - Last line, inclusive. ### Returns - **call_id** (integer|nil) - Accepted run id. - **error** (string|nil) - Error. ``` -------------------------------- ### sqmeow.keymap.apply({surface}, {buf}, {actions}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Binds a surface's mappings in a specific buffer. This is used to set up keymaps for a given surface within a buffer. ```APIDOC ## sqmeow.keymap.apply({surface}, {buf}, {actions}) ### Description Binds a surface's mappings in one buffer. ### Parameters - **surface** (string) - Required - The surface name. - **buf** (integer) - Required - The buffer handle. - **actions** (table) - Required - A table mapping action names to their implementations. ``` -------------------------------- ### sqmeow.api.view.relationships({conn_id}, {schema}, {relation}) Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Browse a table's foreign keys. `gR` on a drawer table or result column. Popup shows Belongs to / Referenced by, columns in order, incl. composite and self-references. follows, `K` shows structure, `?` maps. Remap under `keymaps.relationships`. ```APIDOC ## sqmeow.api.view.relationships({conn_id}, {schema}, {relation}) ### Description Browse a table's foreign keys. `gR` on a drawer table or result column. Popup shows Belongs to / Referenced by, columns in order, incl. composite and self-references. follows, `K` shows structure, `?` maps. Remap under `keymaps.relationships`. ### Method Function call ### Endpoint `sqmeow.api.view.relationships({conn_id}, {schema}, {relation})` ### Parameters #### Path Parameters - `conn_id` (string) - Required - Connection identifier. - `schema` (string) - Required - Schema name. - `relation` (string) - Required - Table name. ### Return None ``` -------------------------------- ### sqmeow.api.view.close_drawer() Source: https://github.com/2giosangmitom/sqmeow.nvim/blob/master/doc/sqmeow.txt Hides the schema drawer. ```APIDOC ## sqmeow.api.view.close_drawer() ### Description Hides the schema drawer. ### Parameters None. ```