sponsor Vim development Vim logo Vim Book Ad

SQHell.vim : A lightweight SQL wrapper for vim

 script karma  Rating 32/25, Downloaded by 1701  Comments, bugs, improvements  Vim wiki

created by
Joe Reynolds
 
script type
utility
 
description
Note that development happens on github
https://github.com/joereynolds/SQHell.vim

# SQHell.vim

An SQL wrapper for Vim.
Execute commands, sort results, navigate tables and databases and so much more!

The supported providers at the moment are
- MySQL
- Postgres
- Sqlite

## Examples

(Gifs are using the data from my punk rock band [bogans](http://bogans.uk))
### Execute a command using `SQHExecute!`

Execute a line with `SQHExecute`.

Execute a visual block with `SQHExecute` over a visual selection.

Execute an arbitrary command with `SQHExecute!`.

![](https://i.imgur.com/osjpU6u.gif)

### Execute a file using `SQHExecuteFile`

`SQHExecuteFile` will work on the current buffer if no file is supplied

![](https://i.imgur.com/67nONqC.gif)

### Explore the database with buffer aware mappings

![](https://i.imgur.com/E12LHnA.gif)

## Installation


### Vim Plug

```
Plug 'joereynolds/SQHell.vim'
```

## Configuration

Connection details will need to be supplied in order for SQHell.vim to connect
to your DBMS of choice. The connections are in a dictionary to let you manage
multiple hosts. By default SQHell uses the 'default' key details (no surprise there)

Example:

```
let g:sqh_connections = {
    \ 'default': {
    \   'user': 'root',
    \   'password': 'testing345',
    \   'host': 'localhost'
    \},
    \ 'live': {
    \   'user': 'root',
    \   'password': 'jerw5Y^$Hdfj',
    \   'host': '46.121.44.392'
    \}
\}
```

You can use the `SQHSwitchConnection` function to change hosts.
i.e. `SQHSwitchConnection live`

I **strongly** suggest that the above configuration details are kept *outside*
of version control and gitignored in your global gitignore.

## Default Keybindings

SQHell creates 3 filetypes to make navigation a nicer experience.
These are SQHDatabase, SQHTable, and SQHResult

### SQHDatabase

Inside an SQHDatabase you can press the following

`dd` - Drop the database (don't worry there's a prompt).

`e` - To see all the tables in that database. This will open an SQHTable buffer.


### SQHTable

Inside an SQHDatabase you can press the following

`dd` - Drop the table (don't worry there's a prompt).

`e` - To see all the results for that table with a limit of `g:sqh_results_limit`.
      This will open an SQHResult buffer

### SQHResult

Inside an SQHResult you can press the following

`s` to sort results by the column the cursor is on.

`S` to sort results by the column the cursor is on (in reverse).

`dd` to delete the row WHERE the column is the value under the cursor (don't worry... there's a prompt).

`e` to edit the current row. This will open an SQHInsert buffer


### SQHInsert

Inside an SQHInsert you can press the following

`ZZ` to close and save the edited row. This will reopen the previous SQHResult buffer


For more sorting options, you can use `:SQHSortResults` with extra arguments for the unix sort command, a la `:SQHSortResults -rn`. It will always sort by the column the cursor is located on.

## Contributing

Please see the [Contributing guidelines](CONTRIBUTING.md) if you would like to make SQHell even better!

## Tests

Tests use [vader](https://github.com/junegunn/vader.vim).

Tests are housed in the `test` directory and can be ran by
`vim`ing into the test file and running `:Vader`.

## What about dbext, vim-sql-workbench and others?

DBExt is very featureful (and very good) but comes in at a whopping 12000 lines
of code. By contrast SQHell.vim is a mere ~200 lines

The setup and installation process for vim-sql-workbench is something that I
aim to avoid with SQHell.vim, ideally a 'set and forget' plugin.

There are no clever inferences inside SQHell.vim.
 
install details
Using vim-plug you can just add the following to your .vimrc

Plug 'joereynolds/SQHell.vim'
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
sqhell.zip 0.4 2017-12-13 7.4 Joe Reynolds Features
------------

- Added support for Sqlite
- Allow results to be in new split each time or stay in current buffer
- Allow postgres to work with multiple queries
- Better documentation
sqhell.zip 0.3 2017-12-10 7.0 Joe Reynolds Features
--------

- Reuse the same buffer instead of creating new ones.
- Add statusline variable
- Codebase now has tests
- Ability to UPDATE a row in an SQHResult
- Sort is now on -n by default
- No longer clobbers the register when entering any SHQ* buffer
- Add command completion for SQHSwitchConnection and SQHExecuteFile

sqhell.zip 0.2 2017-12-02 7.0 Joe Reynolds Features
------------

- ability to sort results with SQHSortResults or using S and s on SQHResult filetype
- Improved postgres support
- e on sqhtable works on all providers
- k on sqhtable works on all providers
- e on sqhdatabase works on all providers
- fixed some lint errors
- Merged 3 commands into one, SQHExecute now works on line, block, or argument
sqhell.zip 0.1 2017-11-30 7.0 Joe Reynolds Initial upload
ip used for rating: 3.133.79.70

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github