Skip to content

Quick start: SQL (stdio)

Russ Tokuyama edited this page Aug 5, 2023 · 1 revision

SQL is a programming language for working with relational database management systems (RDBMS).

Conjure lets you write your SQL DDL (Data Definition Language) and DML (Data Manipulation Language) statements and send them to your SQL command line client program. This is like being in that program but better because you can take advantage of the superior editing experience of Neovim. You can even send non-SQL commands like psql's meta-commands.

This client was developed using PostgreSQL's psql command line client. Thus, the default configuration values for the command and prompt pattern are set for psql. It should work other SQL command line client programs. One user reported that this client works with the MySQL command line client.

Prerequisites

  • Install the latest Neovim.
  • Install the Conjure plugin.
  • Install your SQL command line client.

Before you start, configure this:

You can do this in the Neovim command mode or put the equivalent in your config file.

You must set the command to use to start your SQL command line client. The default command is set to "psql -U blogger postgres". This assumes that you have psql set up with:

  • ~/.pgpass password file.
  • PostgreSQL server running on your local computer listening on the default port.
  • The default postgres database.
  • A database user named blogger with its password stored in the ~/.pgpass password file.

To change that command (especially if you're using a different command line client), you set this:

  • :let g:conjure#client#sql#stdio#command = "your command"

Conjure will automatically start a REPL when you open the first .sql file but you may not want it do that just yet. To delay the start of the REPL, set this global variable to false.

  • :let g:conjure#client_on_load = v:false

After opening your *.sql file, you can start the REPL using <LocalLeader>cs. If the REPL appears unresponsive, you can interrupt it using <LocalLeader>ei.

When you are done or when you want to, you can stop the REPL using <LocalLeader>cS.

Set the prompt pattern of the SQL command line client if it isn't => .

  • let g:conjure#client#sql#stdio#prompt_pattern = "=> "

Open and edit!

You should now be able to open any .sql file and evaluate as you would normally.

If you're unsure how to evaluate things with Conjure, please refer to :help conjure, :help conjure-client-scheme-stdio and :ConjureSchool (an interactive tutorial).