supabase-community/postgres_lsp

JS + TS Template Literal Support

karlhorky opened this issue · 5 comments

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Edit: Even though this may not be a bug, I reopened from the comment from @kiwicopple - if this is unwanted, feel free to transform this into a discussion under supabase/postgres_lsp discussions

Not sure if this is actually a bug, but it would be great to have support for all features in SQL inside JavaScript and TypeScript template literals

First of all, thanks for all of the effort that Supabase is putting into the PostgreSQL community, including tooling, really amazing 🙌

I recently encountered Postgres Language Server via the recent tweet from @kiwicopple and it looks amazing!

I have been chasing the "holy grail" of tooling for SQL template literals in JavaScript + TypeScript for a while now:

Wasn't even looking for inline documentation yet, but that's a great addition too!

It seems that the plan will be for Postgres Language Server to support all of these use cases, which is amazing!

I would love to have everything handled by one highly-battle-tested tool, which could maybe also deal with some of the shortcomings from the tools listed above.

However, for Postgres Language Server to work for any of our projects, it would need a feature which I'm not sure it currently has (can't tell, from a quick glance at the docs and the code):

  • Support for tagged template literals in JavaScript and TypeScript

There is precedent for SQL tagged template literals in JS+TS, some of the more popular ones being:

Eg. I would love for all of the features of Postgres Language Server to be available in the following code block:

import { createClient } from '@vercel/postgres';
 
async function queryPosts() {
  const client = createClient();
  await client.connect();
 
  try {
    const likes = 100;
    const { rows, fields } =
      await client.sql`SELECT * FROM posts WHERE likes > ${likes};`;
  } finally {
    await client.end();
  }
}

Or this code block:

// db.js
import postgres from 'postgres'

const sql = postgres({ /* options */ }) // will use psql environment variables

async function getUsersOver(age) {
  const users = await sql`
    select
      name,
      age
    from users
    where age > ${ age }
  `
  // users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
  return users
}


async function insertUser({ name, age }) {
  const users = await sql`
    insert into users
      (name, age)
    values
      (${ name }, ${ age })
    returning name, age
  `
  // users = Result [{ name: "Murray", age: 68 }]
  return users
}

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Attempt to use Postgres Language Server with SQL inside JavaScript and TypeScript template literals
  2. No support

Expected behavior

SQL inside JavaScript and TypeScript template literals should also have all features of the language server

Screenshots

--

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 6.0.2]
  • Version of Node.js: [e.g. 10.10.0]

Additional context

--

Ended up creating a discussion over here instead, I guess that's where feature requests go:

Reopened this issue because of the comment from @kiwicopple - if this is unwanted, feel free to transform this into a discussion under supabase/postgres_lsp discussions

@kiwicopple in comment #6657204 docs for VSCode: code.visualstudio.com/api/references/vscode-api#languages. It's up to the code editor to "guess" which language is defined, and then choose the appropriate Language Editor. So this should be solved once we make progress on the language server.

Oh, exciting, so this should "just work" out of the box and shouldn't need specific code in Postgres Language Server? That sounds great 🙌

I guess we can leave this open until it's far enough along for this! Excited to give this a shot as soon as it's ready (and then recommend to our students at upleveled.io)

yup, this should "just work" depending on your code editor.

we can leave this open until it's far enough along for this

Let's close this one for now, until we find any actual bugs (Discussions are a better place for these long-running issues)

Discussions are a better place for these long-running issues

Ok, opened a non-organization discussion in this repo here: