Git Product home page Git Product logo

sqlsurge's Introduction

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

This table shows the features available for each file extension.

Features .sql .ts .rs
Completion
Formatting
Quick Info Symbol on Completion
Quick Info Symbol on Hover
Any Raw SQL Queries Support

Completion

These are the 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 (Experimental)

Note

This feature is experimental. Feedback is welcome!

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
    }
  ]
}

VS Code Commands

  • sqlsurge: Install sqls: Install sqls.
  • sqlsurge: Restart SQL Language Server: Restart SQL Language Server.
    • This command is useful when you update sqls or change the configuration.
  • sqlsurge: Format SQL: Format Raw SQL query.
  • Format Document: Format SQL file with sqls.

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

sqlsurge's People

Contributors

senkenn avatar dependabot[bot] avatar github-actions[bot] avatar

Stargazers

Kevin James O'Dea avatar  avatar  avatar  avatar William Laffin avatar YJ Park avatar MrJohnsson avatar  avatar Vitalii Kryvenko avatar  avatar Alexey Orlenko avatar  avatar 冒頓単于 avatar

Watchers

 avatar

sqlsurge's Issues

[commandFormatSqlProvider] Error: Parse error

[commandFormatSqlProvider] Error: Parse error: Unexpected "$1;" at line 1 column 32. This likely happens because you're using the default "sql" dialect. If possible, please select a more specific dialect (like sqlite, postgresql, etc).

Format with indent

Current

async fn complete_todo(pool: &PgPool, id: i64) -> anyhow::Result<bool> {
    let rows_affected = sqlx::query!(
        r#"
UPDATE todos
SET
  done = TRUE
WHERE
  id = $1
        "#,
        id
    )
    .execute(pool)
    .await?
    .rows_affected();

    Ok(rows_affected > 0)
}

Expected

async fn complete_todo(pool: &PgPool, id: i64) -> anyhow::Result<bool> {
    let rows_affected = sqlx::query!(
        r#"
        UPDATE todos
        SET
            done = TRUE
        WHERE
            id = $1
        "#,
        id
    )
    .execute(pool)
    .await?
    .rows_affected();

    Ok(rows_affected > 0)
}

v1.0.0 Release

I could implement the minimum features that I want.
sqlsurge.customRawSqlQuery is now experimental, but I will release v1.0.0 if it has no problems.

TODOs v1.0.0

  • Remove preview flag
  • Remove experimental flag of sqlsurge.customRawSqlQuery
  • Add contribution guides
  • #86

sqls binary file name miss suffix in windows

sqls binary file name miss suffix(.exe) in windows

before I change the code, extension can not find sqls binary in windows:
image

after I changed the code, extension can find sqls binary in windows:
image

Opaque Error on refresh: Debug Failure.

I installed the extension, installed sqls and configured it with a test DB that I have in my environment the following way:

lowercaseKeywords: false
connections:
  - alias: blue-stack
    driver: postgresql
    dataSourceName: postgresql://test:tester@localhost:5432/catalog

Note

I don't understand how sqlsurge is supposed to know that I use a particular connection in my code, because that config specifies a list. Maybe it's part of the problem?

However, when I try to save a rust source file, trigger completions or manually run sqlsurge: Format SQL command I get the following pop-up every time.

image

You can see the sqls logs in the output above. However, there is no output from sqlsurge:

image

Is there any way I can get more detailed logs from sqlsurge for you?

Environment

It may be important to note, that I'm using VSCode Remote SSH. The extension is installed on a remote machine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.