npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sqlpture

v0.0.9

Published

SQL database engine implemented purely in TypeScript type definitions.

Downloads

3

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 }>

DEMO

Installation

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 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

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