Skip to content

vlcn-io/typed-sql

Repository files navigation

typed-sql

Generates types for your SQL.

select-types-faster.mov

Beta status. My main focuses are:

  1. cr-sqlite
  2. materialite

And this project when there's time.

Documented issues: https://github.com/vlcn-io/typed-sql/issues

Install and Usage Video

https://www.youtube.com/watch?v=avGari4souM&feature=youtu.be

Installation

Types are generated via a watch task installed with @vlcn.io/typed-sql-cli.

pnpm install @vlcn.io/typed-sql-cli`

See the cli package

Usage

After installing the cli, see the runtime component package.

Current Limitations & Future Work

Composition

It is possible to do type generation for template strings which are combinations of template strings. E.g.,

const query = sql`SELECT * FROM ${table} WHERE ${where_clauses}`;

Assuming that some type information is available on the parameters to the template tag. E.g., typeof table = 'foo' | 'bar' | 'baz'

This is not yet supported.

See issue 10

Custom Types

SQLite lets users declare custom types in their create table statements.

CREATE TABLE foo (
  id TEXT PRIMARY KEY,
  b MyCustomType,
  c MyOtherCustomType
);

We could parse these out and map them to actual typescript types. Doing this would require some runtime layer to convert columns to the correct types.

Python bindings have done this -- https://docs.python.org/3/library/sqlite3.html#sqlite3-converters

See issue 8

Bool

SQLite doesn't return bools! True is 1 and False is 0. Given this library currently does not handle execution, and only type generation, bools are typed as number

Intellisense

I've not implemented a language server yet so intellisense, within the sql and schema template tags, currently does not exist. It is planned.

issue 15

Syntax Highlighting

Highlighting inside the sql and schema template tags is not yet supported.

issue 16

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published