mtxr / vscode-sqltools

Database management for VSCode
https://vscode-sqltools.mteixeira.dev?utm_source=github&utm_medium=homepage-link
MIT License
1.52k stars 307 forks source link

add compatibility with Remote Development #692

Open Morgy93 opened 4 years ago

Morgy93 commented 4 years ago

Is your feature request related to a problem? Please describe. I am not able to get SQLTools working while connected on remote using https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack

Describe the solution you'd like I'd love to be able to use SQLTools while connected on some remote server via https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack so I can access localhost there.

Describe alternatives you've considered I tried to run the extension as an ui extension, but then of course it tries to connect to my host machine stating that the mysql driver is not present.

Additional context It would be great to have a local settings.json config which is also applied on remote. Currently it is not and it would require to configure a localhost connection on every remote machine.

Morgy93 commented 3 years ago

The error thrown is:

[renderer1] [error] command 'sqltools.openAddConnectionScreen' not found: Error: command 'sqltools.openAddConnectionScreen' not found
    at g._tryExecuteCommand (file:///[...]Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1743:3364)
    at file:///[...]Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1743:3245
    at async u.open (file:///[...]Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:628:19630)
    at async l.open (file:///[...]Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:628:21654)
mathroc commented 2 years ago

Would someone be able to explain how much work it would take to implement this? And if it's something the maintainers are interested in?

I'm just trying to figure out if this is something we'll likely see one day? And, if this is something I could look into when I have some spare time

gjsjohnmurray commented 2 years ago

@mathroc when I tested just now with SQLTools 0.25.1 and SQLite driver 0.4.0 installed and VS Code connected over SSH to an Ubuntu server I was able to connect to a database on that server provided I typed the full path and filename of the database file into the field on the Connection Assistant dialog. The "SELECT FILE" button does indeed browse my workstation's local filesystem when it should target the remote server's filesystem. I don't know if that is fixable, but entering the database file manually instead of browsing for it doesn't seem a huge inconvenience.

mathroc commented 2 years ago

Hi! I tried it again, with SQLTools 0.25.1 SQLite driver 0.4.0, and MySQL/MariaDB driver 0.4.0 connected to a Dev Container in my case

and I can't add a connection, when I lunch the "SQLTools Management: Add New Connection" command, here is what I got:

image

I tried it when not connected to Dev Container, the connection assistant is started correctly then.

Then I tried it when connected to a an SSH server and again the connection assistant is starting correctly. So it seems the issue only appears when using Docker as a remote

The "SELECT FILE" button does indeed browse my workstation's local filesystem when it should target the remote server's filesystem. I don't know if that is fixable, but entering the database file manually instead of browsing for it doesn't seem a huge inconvenience.

that wouldn't be an issue at all for me

V-ed commented 1 year ago

A solution to use this extension in a dev container is to specify that this extension (and the driver extensions) run in the UI :

// vscode's settings.json
"remote.extensionKind": {
    "mtxr.sqltools": ["ui"],
    "mtxr.sqltools-driver-pg": ["ui"],
    "mtxr.sqltools-driver-sqlite": ["ui"],
    // [...] any other driver that you would need
},
Little tutorial on getting the extension ID to add to the settings Simply go to the extensions panel, select the extension you want to add then either `right click -> Copy Extension ID` or manually copy it in the extension's details page (view screenshot below) ![image](https://github.com/mtxr/vscode-sqltools/assets/16652915/be520645-d702-4b98-8fdf-0332849fb7e0)

You need to add all the drivers to the UI as well or otherwise it won't connect correctly.

Keep in mind that this means this extensions runs on the local machine, and not the remote machine, meaning that localhost is actually your main machine's localhost network. If the postgres database is not accessible outside the remote machine, you will not be able to connect to it. This means that for a Dev Container (with a docker compose file that hosts a postgres db), you would need to forward the port of your postgres instance.

I am not sure if this trick works for SQLite, but my guess is that you would need to find the filepath of your project on your local machine (for example, in Windows WSL running a container, you would probably need to use the path \\wsl$\{DISTRO NAME}\home\{USERNAME}\path\to\project\db.sqlite or something along those lines).


I searched for a while if there was another extension that works out of the box in dev containers and none had such good UX/DX that actually connected, hopefully this little info does help wanderers as well :)