Skip to content

senkenn/sqlsurge

Repository files navigation

sqlsurge

sqlsurge is a Visual Studio Code extension for SQL language server using sqls. It works just NOT ONLY with SQL files, but also with RAW SQL QUERIES on other languages such as TypeScript and Rust.

Prisma Example in TypeScript: Alt text

SQLx Example in Rust: Alt text

Requirements

  • Golang v1.22.2 or later
  • sqls v0.2.28 or later
    • There is sqls installation guide in the extension.

Supported RDBMS

See: https://github.com/sqls-server/sqls?tab=readme-ov-file#support-rdbms

Features

These features are available on both Vanilla SQL files and any raw SQL queries in other languages.

And this table describe what language support these features.

Features SQL TypeScript Rust
Auto-Completion
Formatting
Quick info symbol (on Completion)
Quick info symbol (on Hover)
Any raw SQL queries support

Auto-Completion

These are the auto-completion items sqlsurge provides:

  • SQL keywords
  • Tables and columns (Required to be configured by sqls config)

About raw SQL queries, VSCode's quick suggestion(auto completion) in strings is disabled by default. It can be enabled by adding the following setting to settings.json.

"editor.quickSuggestions": {
    "strings": true
}

Formatting

VSCode Commands

  • SQL File: Format Document
  • Raw SQL query: sqlsurge: Format SQL

Configurations for raw SQL queries

  • sqlsurge.formatOnSave: Format SQL on save. Default is true.
  • sqlsurge.formatSql.indent: Format SQL with indent. Default is false.
  • sqlsurge.formatSql.tabSize: Tab size for SQL formatting. Default is 4.

As a formatter, sqlsurge use sqls for Vanilla SQL files, use SQL Formatter for raw SQL.

Quick info symbol

Quick info symbol for tables and columns can be shown by triggering completion with Ctrl + Space or Cmd + Space.

text

Any raw SQL queries support

sqlsurge supports Prisma in TypeScript and SQLx in Rust by default. But you can use sqlsurge with any raw SQL queries, such as TypeORM or user-defined functions by setting.

This is an example of settings for custom raw SQL queries.

// TypeORM in TypeScript
const someQuery = await entityManager.query(
  "SELECT * FROM todos WHERE id = $1;",
  [1]
);
"sqlsurge.customRawSqlQuery": {
  "language": "typescript",
  "configs": [
    {
      "functionName": "query",
      "sqlArgNo": 1,
      "isTemplateLiteral": false
    }
  ]
}

TODOs

  • Support for Prisma in TypeScript
  • Support for SQLx in Rust
  • Install guide for sqls
  • Format SQL (Vanilla SQL: sqls, Raw SQL: SQL Formatter)
  • Show quick info symbol
  • Support to custom raw SQL queries, not just Prisma and SQLx
  • Execute SQL query
  • Show sqls config with tree view