Skip to content

QueryReuse

Saved script library

The Library lets you save and organize reusable items across your projects. It supports four item types:

  • Scripts - SQL snippets with connection metadata
  • Query Builder queries - Full visual Query Builder state (tables, joins, filters, columns)
  • Explore views - Saved data exploration configurations
  • File references - Links to SQL files in your workspace

Items are organized under two scopes:

  • Project - Stored in .dbcode/library/ in your workspace folder. Shared with anyone who opens the project (ideal for team queries and shared scripts).
  • Personal - Stored in your VS Code global storage. Private to you and available across all workspaces.

Library panel with Project and Personal scopes, an expanded Reports folder, and saved SQL scripts

  1. Select SQL text in any editor
  2. Click Add to DBCode Library in the editor toolbar, or run the command from the Command Palette
  3. Enter a name
  4. Choose Project or Personal in the scope picker

Scope picker for saving selected SQL to the Project or Personal library

Click Save to Library in the Query Builder toolbar:

  • First save - Prompts for a name and scope, then stores the full visual state (tables, joins, filters, columns, positions) along with the generated SQL
  • Subsequent saves - Updates the saved item silently
  • Save As New - Creates a copy with a new name

Drag .sql or other files from the VS Code Explorer into the Library panel. DBCode creates a file reference that opens the file when clicked. For Project scope, workspace-relative paths are stored so references work for all team members.

Right-click on a scope root or existing folder and choose Create Folder. Drag and drop items and folders to rearrange them, including moving items between Project and Personal scopes.

Click any item in the Library tree to open it:

  • Scripts open in a new SQL Editor tab bound to the original connection
  • Query Builder queries restore the full visual state in a Query Builder tab
  • File references open the linked file

If the original connection is not available (for example, a shared project item from a teammate), DBCode prompts you to select a local connection.

Right-click a saved script, a Query Builder query, or a SQL file reference and choose Open With Connection…. DBCode asks which connection to use and opens the item bound to that one instead of the connection saved on it. The saved item is unchanged, and a plain click still opens it against its own connection.

Right-click any item or folder to rename or delete it. Deleting a folder removes all items inside it.

Library items are stored as plain files:

TypeExtensionFormat
Script.sqlSQL with YAML frontmatter (name, connection, database)
Query Builder.qb.jsonJSON with builder state and generated SQL
Explore.explore.jsonJSON with exploration configuration
File reference.file.jsonJSON with the file path

Because items are regular files, they can be version-controlled, shared, and edited outside of DBCode.

Project items are in .dbcode/library/ in your workspace folder. DBCode watches that folder, so editing a file there updates the Library panel straight away.

Personal items are in VS Code’s global storage for the extension:

PlatformPath
macOS~/Library/Application Support/Code/User/globalStorage/dbcode.dbcode/library
Windows%APPDATA%\Code\User\globalStorage\dbcode.dbcode\library
Linux~/.config/Code/User/globalStorage/dbcode.dbcode/library

On a VS Code fork, swap Code for that editor’s own folder (for example Cursor or VSCodium). Personal storage is not watched, so after editing a file there, click Refresh at the top of the Library panel to pick up the change.

Scripts are .sql files with a small YAML header holding the name and connection details. Keep that header intact when editing a file by hand, otherwise the item loses its name and its connection binding.

  • Favorites: Bookmark database objects in the connection tree for quick access
  • Query Builder: Build queries visually and save them to the Library
  • Query History: Automatically track and recall executed queries