Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vlcn-io/typed-sql
https://github.com/vlcn-io/typed-sql
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/vlcn-io/typed-sql
- Owner: vlcn-io
- License: mit
- Created: 2023-07-06T21:03:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-16T11:26:03.000Z (11 months ago)
- Last Synced: 2024-07-29T15:38:36.960Z (3 months ago)
- Language: TypeScript
- Size: 365 KB
- Stars: 96
- Watchers: 2
- Forks: 2
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# typed-sql
Generates types for your SQL.
https://github.com/vlcn-io/typed-sql/assets/1009003/4459edb2-4a52-4641-819d-5805c04d943a
**Beta status. My main focuses are:**
1. [cr-sqlite](https://github.com/vlcn-io/cr-sqlite)
2. [materialite](https://github.com/vlcn-io/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](./packages/cli)
# Usage
After installing the cli, see the [runtime component](./packages/typed-sql/README.md) package.
# Current Limitations & Future Work
## Composition
It is possible to do type generation for template strings which are combinations of template strings. E.g.,
```ts
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](https://github.com/vlcn-io/typed-sql/issues/10)
## Custom Types
SQLite lets users declare custom types in their create table statements.
```sql
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](https://github.com/vlcn-io/typed-sql/issues/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](https://github.com/vlcn-io/typed-sql/issues/15)
## Syntax Highlighting
Highlighting inside the `sql` and `schema` template tags is not yet supported.
[issue 16](https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide)