kristijanhusak / vim-dadbod-ui

Simple UI for https://github.com/tpope/vim-dadbod
MIT License
1.36k stars 70 forks source link

Requirement to execute single query under cursor #206

Closed zhangddjs closed 7 months ago

zhangddjs commented 7 months ago

Background

Sometimes there are many sql querys in one single file, split by ; , but once I want execute a single query, I need to select the whole syntax and then <Leader>S .

But one problem is that , if I forgot to select the syntax, then <Leader>S will execute the whole file, what was not I wanted. (It maybe drop some tables without any confirm popup, which will cause serious results)

Requirement

According to this situation, is it possible to provide a mechanism that:

  1. once I run execute, it only execute the query block under current cursor, and will end until the first semi-colon
  2. if the query is plan to delete the whole table or drop a whole table, it will pop up a confirm from user.

Example

for e.g.

CREATE TABLE foo.`bar` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
  `uid` int(11) unsigned NOT NULL  {{ **I** <—— Cursor here }} DEFAULT '0' COMMENT 'UID',
  PRIMARY KEY (`id`)
);
drop table `foo`.bar;

the cursor is in middle of this create table query, when I execute, it will just execute the create table .... block ending with semi-colon, and will not execute the drop table and other querys outside of the cursor.

skbolton commented 7 months ago

I have gotten around this by turning off execute on save and then using this keybind to run the query under my cursor https://github.com/skbolton/titan/blob/d37c0178c41652191285fe031ca89ee0568c3bf5/nvim/nvim/after/ftplugin/sql.lua#L5

I am okay with separating my different queries my newlines to make it work.

zhangddjs commented 7 months ago

cool, this helped a lot, thanks @skbolton . Also I found that some of the dbext built-in keymap like <leader>sep or <leader>sel can execute the cursor querys.