Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andoshin11/sqlpture
Type Level SQL interpreter & validator.
https://github.com/andoshin11/sqlpture
Last synced: 12 days ago
JSON representation
Type Level SQL interpreter & validator.
- Host: GitHub
- URL: https://github.com/andoshin11/sqlpture
- Owner: andoshin11
- License: mit
- Fork: true (codemix/ts-sql)
- Created: 2021-02-09T07:21:36.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-17T14:54:28.000Z (over 3 years ago)
- Last Synced: 2024-10-12T00:39:00.822Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 230 KB
- Stars: 74
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# sqlpture
**sqlpture** (`/ˈskʌlptʃə/`) is a type-level SQL parser & validator, inspired by [ts-sql](https://github.com/codemix/ts-sql).
```typescript
import { Query } from 'sqlpture'
import { DB } from './types/DB'const query = 'SELECT name, email, age FROM customer;'
type result = Query // Array<{ name: string, email: string | null, age: number }>
```![DEMO](https://user-images.githubusercontent.com/8381075/108982201-e27c3c80-76d0-11eb-8c40-9051bb6a24a7.gif)
## Installation
```sh
yarn add -D sqlpture
```## Getting Started
**:warning: You will need TypeScript 4.1 or higher**1. Setup Database
2. Generate Type Definition for Your Relational Database
- Reccomend to use [schemats](https://github.com/SweetIQ/schemats) to generate Table type intefaces for MySQL & Postgres
- Your DB type definition should meet such structure, `type Database = { dialect: string; schema: Record }`3. Install [sqlpture](https://github.com/andoshin11/sqlpture)
## How to use in Real World ?
Check out the example repository!
https://github.com/andoshin11/sqlpture-example
There you can see...
- How I manage PostgreSQL DB
- How I do codegen TypeScript schema from actual DB
- How I call PostgreSQL query on Node.js application
- How I develop a type-safe Node.js API server## TODO
- [ ] Query Result Type
- [ ] Querying Data
- [ ] `SELECT`
- [x] `SELECT * FROM table_name`
- [x] `SELECT select_list FROM table_name`
- [x] `SELECT DISTINCT column_name FROM table_name`
- [ ] (PostgreSQL) SELECT statement with expressions
- [ ] `LENGTH()` function
- [ ] `SUM()` function
- [ ] `COUNT()` function
- [ ] `HAVING` clause
- [ ] Column Alias
- [x] `SELECT column_name AS alias_name FROM table_name`
- [x] `SELECT column_name alias_name FROM table_name`
- [ ] Column Aliases that contain spaces
- [ ] Join Tables
- [x] INNER JOIN multiple tables
- [x] field name from public table
- [x] field name with table alias prefix
- [x] SELF JOIN
- [x] `USING`
- [x] LEFT JOIN
- [x] RIGHT JOIN
- [ ] FULL OUTER JOIN
- [ ] CROSS JOIN
- [ ] NATURAL JOIN
- [ ] GROUP BY
- [ ] UNION
- [ ] UNION ALL
- [ ] INTERSECT
- [ ] EXCEPT
- [ ] Modifying Data
- [x] `INSERT`
- [x] Return Data
- [x] Insert multiple rows
- [x] `UPDATE`
- [x] Return Data
- [ ] `DELETE`
- [ ] Query Validator
- [ ] `SELECT`
- [x] Field names
- [x] Invalid filed names from public schema
- [x] Invalid field names with table alias prefix
- [x] Invalid field names with alias
- [x] Join
- [x] Invalid Join target table
- [x] Invalid `ON` target fields
- [ ] `ORDER BY` clause
- [ ] Invalid field names
- [x] `WHERE` clause
- [x] Invalid field names
- [x] Accept Variable Expression( `$`)
- [x] `INSERT`
- [x] Insert target table
- [x] Insert field names
- [x] Return field names
- [x] Check values type
- [x] Insert multiple rows
- [x] Accept Variable Expression( `$`)
- [x] `UPDATE`
- [x] Return field names
- [x] Set field names
- [x] Set field values
- [x] Where expression validity
- [ ] `DELETE`