JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q36571F
  • License MIT

SQL database engine implemented purely in TypeScript type definitions.

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

  1. Setup Database

  2. 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> }
  1. 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
  • 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
      • FETCH clause
    • INSERT
    • UPDATE
    • DELETE