Skip to content

A SurrealDB plugin for nvim so you don't have to leave your natural habitat

Notifications You must be signed in to change notification settings

DariusCorvus/surrealdb.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 

Repository files navigation

surrealdb.nvim


Requirements

The binarys curl and jq need to be on path.

Features

  • automatic buffer keymaps on buffers with the extensions *.sql, *.surql or *.sdb
  • automatic syntac highlighting on buffers with the extensions *.sql, *.surql or *.sdb
  • execute the current buffer
    • Hit <SPACE>5 in normal mode or execute :SurrealDBRun buf or :SurrealDBRun buffer
  • execute the line under the cursor
    • Hit <SPACE>5l in normal mode or execute :SurrealDBRun ln or ``:SurrealDBRun line`
  • execute the visual selected text of the current buffer
    • Hit <SPACE>5 in visual mode.
  • highlights the last executed query
  • shows a virtual status text at the right of the executed query
  • opens a buffer with the surrealdb response and reuses this buffer for all executed querys
  • possibility to create a scratchpad to write your querys on the fly
  • displays the response formatted thanks to jq

Note

The hotkeys are only available by default in buffers with the extensions *.sql, *.surql or *.sdb look into the config section to learn about the possible configurations for this plugin.

Commands

Command Description Parameter
:SurrealDBRun Runs the current buffer content, line under the cursor or selection buf, buffer, ln, line, sel, selection
:SurrealDBConnection Changes the certain variables of the used connection env, user, pass, host, ns, db, all
:SurrealDBScratch Creates a buffer that acts as a scratchpad for your querys

Setup

The code block below shows how to load the plugin.

local surrealdb = require("surrealdb-nvim")

-- default config
surrealdb.setup{}

surrealdb.setup{connection = {host="localhost:8001/sql"}} -- updates the key:value pair `host` of the default config.

Config

The config below is the default config for the surrealdb-nvim plugin.

config = {
	connection = {
		host = "localhost:8000/sql",
		ns = "test",
		db = "test",
		user = "root",
		pass = "root",
	},
	file = {
		extension = {"*.sdb", "*.surql", "*.sql"}
		run_on_safe = false,
		type = "sql",
	},
	keymaps = {
		{"n", "<leader>5", ":SurrealDBRun buf<CR>"},
		{"n", "<leader>5l", ":SurrealDBRun ln<CR>"},
		{"v", "<leader>5", ":<C-U>SurrealDBRun sel<CR>"},
	},
	virtual_texts = {
		success = { "", "GreenSign" },
		fail = { "", "RedSign" },
	},
	output = {
		buf_name = "SurrealDB Response",
		split = "vertical",
		format_cmd = ":%!jq --indent 2",
	},
	scratchpad = {
		buf_name = "SurrealDB Scratchpad",
		split = "horizontal",
	},
}

About

A SurrealDB plugin for nvim so you don't have to leave your natural habitat

Topics

Resources

Stars

Watchers

Forks

Languages