straysheep3
11/5/2017 - 1:15 PM

vimでsqlを実行する環境

  • neovim
  • dbext
  • postgresql

postgresqlの確認

(*^ - ^)❯postgres --version
postgres (PostgreSQL) 10.0

ない場合は、`brew install postgresql'


postgresqlの設定

DBの設定 initdb /usr/local/var/postgres -E utf8

パーミッションのエラーが出た場合

The files belonging to this database system will be owned by user "ユーザー名".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /usr/local/var/postgres ... initdb: could not change permissions of directory "/usr/local/var/postgres": Operation not permitted

sudo chown -Rwhoami/usr/local

権限を変えておく。

参考リンク

サーバーの起動

brew services start postgresql

データベースの確認

psql -l

ユーザーを作成しておくと良いかも


dbextの設定

  Plug 'vim-scripts/dbext.vim', { 'for': 'sql' }

  let g:dbext_default_profile_psql = 'type=PGSQL:host=localhost:port=5432:dbname=squat:user=kage'
  let g:dbext_default_profile = 'psql'
  let dbext_default_buffer_lines=30

$HOMEに.pgpassを作成しておく

hostname:port:database:username:password

一行で良い。

.pgpassに関して、warningが出るようであればchmod 600 .pgpassしておけば警告は消える。

コマンドに関しては、リンクを参照

Qiita記事