Package Exports
- sqlpture
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sqlpture) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
sqlpture
sqlpture (/ˈskʌlptʃə/
) is a type-level SQL parser & validator, inspired by ts-sql.
import { Query } from 'sqlpture'
import { DB } from './types/DB'
const query = 'SELECT name, email, age FROM customer;'
type result = Query<typeof query, DB> // Array<{ name: string, email: string | null, age: number }>
Installation
yarn add -D sqlpture
Getting Started
⚠️ You will need TypeScript 4.1 or higher
Setup Database
Generate Type Definition for Your Relational Database
- Reccomend to use schemats to generate Table type intefaces for MySQL & Postgres
- Your DB type definition should meet such structure,
type Database = { dialect: string; schema: Record<string, any> }
- Install sqlpture
TODO
- Query Result Type
- Querying Data
-
SELECT
-
SELECT * FROM table_name
-
SELECT select_list FROM table_name
-
SELECT DISTINCT column_name FROM table_name
- (PostgreSQL) SELECT statement with expressions
-
LENGTH()
function
-
- Column Alias
-
SELECT column_name AS alias_name FROM table_name
-
SELECT column_name alias_name FROM table_name
- Column Aliases that contain spaces
-
-
- Querying Data
- Query Validator
-
SELECT
- Column Aliases that contain spaces
-
ORDER BY
clause - NULL check inside
ORDER BY
clause -
WHERE
clause -
LIMIT
clause- accepts
number | null
only -
OFFSET
clause
- accepts
-
FETCH
clause
-
INSERT
-
UPDATE
-
DELETE
-