kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.22k stars 259 forks source link

`sql` tag function should be available on the `Kysely` interface #888

Closed alexgleason closed 6 months ago

alexgleason commented 6 months ago

I'm building a project where Kysely is only a devDependency. Functions accept Kysely instances, where Kysely is used only as a type.

But since sql is a separate import, I have to make Kysely a peerDependency to use it:

await sql`CREATE VIRTUAL TABLE nostr_fts USING fts5(event_id, content)`.execute(this.db);

What I want is the ability to do this:

await this.db.sql`CREATE VIRTUAL TABLE nostr_fts USING fts5(event_id, content)`.execute();

After a lot of digging this is the closest thing I've come up with... which I think works?? But is insane:

await this.db.executeQuery({
  sql: 'CREATE VIRTUAL TABLE nostr_fts USING fts5(event_id, content)',
  query: {
    kind: 'RawNode',
    sqlFragments: [],
    parameters: [],
  },
  parameters: [],
});
koskimas commented 6 months ago

We specifically removed sql from the Kysely instance to make it a free function.

Kysely is not a dev dependency if you use it in the non-dev part of the project. It's a real dependency (or a peer dependency) if your package depends on it.