sqlvisual-studio-coderead-eval-print-loop

In VS Code, how can I send lines in a file to a REPL in the integrated terminal?


I would like to be able to open up the VS code terminal, and connect to my SQL database and then open up a SQL file and then write small queries that I can shoot over to the terminal that is connected to my database instance. Is this possible? The VS code REPL feature does not seem to work when I open up a SQL file the same way it does as if I am editing a python file.

I'm using SQLite3, but I'd ideally like a DBMS-independent answer (if there is one).

I want to open the VS Code integrated terminal, then run sqlite or mysql to start a SQL terminal instance, and then I want to open a SQL file as a script and send queries to the terminal from the script. However, it seems the vs code dose not have a default REPL key binding. If I am editing a .py file, then shift-enter will send my selection to the terminal, but shift-enter will not send a selection to the terminal if I am editing a .sql file.


Solution

  • This should already be possible (at least- I think so). Start up whichever REPL it is you want in the integrated terminal as you have described, then take your pick of the following VS Code commands:

    You can either run those from the command palette, or create keyboard shortcuts for them. If you want to use those keyboard shortcuts that you create while the terminal has focus, you may need to add those command IDs to your terminal.integrated.commandsToSkipShell setting.

    Sometimes extensions can be a little more sophisticated and have their own terminal profile with shell integration, such as the Python got around the time of the VS Code 1.87 release.