127 lines
5.3 KiB
YAML
127 lines
5.3 KiB
YAML
uuid:
|
|
- value: b475d325-7c60-4115-b465-f1d691ab75b0
|
|
langcode:
|
|
- value: en
|
|
type:
|
|
- target_id: daily_email
|
|
target_type: node_type
|
|
target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7
|
|
revision_timestamp:
|
|
- value: '2025-05-11T09:00:50+00:00'
|
|
revision_uid:
|
|
- target_type: user
|
|
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
|
|
revision_log: { }
|
|
status:
|
|
- value: true
|
|
uid:
|
|
- target_type: user
|
|
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
|
|
title:
|
|
- value: |
|
|
Managing databases with Neovim and Docker
|
|
created:
|
|
- value: '2022-12-10T00:00:00+00:00'
|
|
changed:
|
|
- value: '2025-05-11T09:00:50+00:00'
|
|
promote:
|
|
- value: false
|
|
sticky:
|
|
- value: false
|
|
default_langcode:
|
|
- value: true
|
|
revision_translation_affected:
|
|
- value: true
|
|
path:
|
|
- alias: /daily/2022/12/10/managing-databases-with-neovim-and-docker
|
|
langcode: en
|
|
body:
|
|
- value: |
|
|
<p>If you work on software projects that use a database, you need a convenient way to connect, inspect, and query them.</p>
|
|
|
|
<p>Some IDEs like PhpStorm have an integrated database client, which I've recently added to my Neovim setup and working with Docker and Docker Compose.</p>
|
|
|
|
<h2 id="configuring-docker-compose">Configuring Docker Compose</h2>
|
|
|
|
<p>A local port needs to be exposed from the database container that Neovim can connect to.</p>
|
|
|
|
<p>I usually do this with a <code>docker-compose.override.yaml</code> file:</p>
|
|
|
|
<pre><code class="language-yaml">services:
|
|
database:
|
|
ports:
|
|
- 3307:3306
|
|
</code></pre>
|
|
|
|
<p>Docker Compose recognises this by default, extends the normal <code>docker-compose.yaml</code> file and adds a port forwarding to the <code>database</code> service.</p>
|
|
|
|
<h2 id="configuring-neovim">Configuring Neovim</h2>
|
|
|
|
<p>The two plugins I'm using are tpope/vim-dadbod and kristijanhusak/vim-dadbod-ui, and should work with Vim and Neovim. Thanks to both of these project maintainers.</p>
|
|
|
|
<p>Once installed, run <code>:DBUIAddconnection</code> to add a database connection.</p>
|
|
|
|
<p>Here is an example connection string:</p>
|
|
|
|
<pre><code>mysql://drupal:drupal@localhost:3307/drupal?protocol=tcp
|
|
</code></pre>
|
|
|
|
<p>Using the local port mapping, this connects to a MySQL database within the <code>database</code> service.</p>
|
|
|
|
<p>Then run <code>:DBUI</code> to toggle the UI and see a list of databases in the left-hand sidebar.</p>
|
|
|
|
<p>You can enter <code><leader>R</code> to refresh databases or <code>r</code> to rename or update connection details for a specific database.</p>
|
|
|
|
<p>Once connected, you can enter and save queries, using table and column name completion, which are executed every time the query is saved.</p>
|
|
|
|
<p>I like not needing to switch contexts and leave my editor in order to query a database, and feel a lot more productive being able to write, execute and save queries within this UI.</p>
|
|
|
|
<p>If you're a Vim or Neovim user, I'd suggest trying this setup and seeing if it works for you.</p>
|
|
|
|
|
|
format: full_html
|
|
processed: |
|
|
<p>If you work on software projects that use a database, you need a convenient way to connect, inspect, and query them.</p>
|
|
|
|
<p>Some IDEs like PhpStorm have an integrated database client, which I've recently added to my Neovim setup and working with Docker and Docker Compose.</p>
|
|
|
|
<h2 id="configuring-docker-compose">Configuring Docker Compose</h2>
|
|
|
|
<p>A local port needs to be exposed from the database container that Neovim can connect to.</p>
|
|
|
|
<p>I usually do this with a <code>docker-compose.override.yaml</code> file:</p>
|
|
|
|
<pre><code class="language-yaml">services:
|
|
database:
|
|
ports:
|
|
- 3307:3306
|
|
</code></pre>
|
|
|
|
<p>Docker Compose recognises this by default, extends the normal <code>docker-compose.yaml</code> file and adds a port forwarding to the <code>database</code> service.</p>
|
|
|
|
<h2 id="configuring-neovim">Configuring Neovim</h2>
|
|
|
|
<p>The two plugins I'm using are tpope/vim-dadbod and kristijanhusak/vim-dadbod-ui, and should work with Vim and Neovim. Thanks to both of these project maintainers.</p>
|
|
|
|
<p>Once installed, run <code>:DBUIAddconnection</code> to add a database connection.</p>
|
|
|
|
<p>Here is an example connection string:</p>
|
|
|
|
<pre><code>mysql://drupal:drupal@localhost:3307/drupal?protocol=tcp
|
|
</code></pre>
|
|
|
|
<p>Using the local port mapping, this connects to a MySQL database within the <code>database</code> service.</p>
|
|
|
|
<p>Then run <code>:DBUI</code> to toggle the UI and see a list of databases in the left-hand sidebar.</p>
|
|
|
|
<p>You can enter <code><leader>R</code> to refresh databases or <code>r</code> to rename or update connection details for a specific database.</p>
|
|
|
|
<p>Once connected, you can enter and save queries, using table and column name completion, which are executed every time the query is saved.</p>
|
|
|
|
<p>I like not needing to switch contexts and leave my editor in order to query a database, and feel a lot more productive being able to write, execute and save queries within this UI.</p>
|
|
|
|
<p>If you're a Vim or Neovim user, I'd suggest trying this setup and seeing if it works for you.</p>
|
|
|
|
|
|
summary: null
|
|
field_daily_email_cta: { }
|