Skip to content

JS + TS Template Literal Support #20

Closed
@karlhorky

Description

@karlhorky

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

--

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions