Typed SQL
SQL query builder for TypeScript. Write complex SQL queries without needing to use strings to refer to column or table names. Provides partial type safety and attribute auto-completion when used with TypeScript. Powered by Knex.js.
Supports:
- Select, insert and update queries
- Complex where clauses
- Joins with complex join conditions
- Transactions
- Aggregation functions and group by
Upcoming:
- Select expressions
Installation
npm install typed-sql
Config
Create Mapper object
// Create knex connection; ; ;
Define mapping to a SQL table
;
Quick usage
Insert data:
await mapper.insertIntofooMapping, ;
Select all columns from table:
; console.logfooList.fooCount; // 5/* Compile error in TypeScript:console.log(fooList[0].nonExisting);*/
Simple where clause
await mapper.insertIntofooMapping, ; .selectAllFromfooMapping .whereLessThanfooMapping.fooCount, 3; console.loglittleFoos; /*[{ id: 2, name: "foo2", createdTime: "Sun Sep 25 2016 22:18:53 GMT+0300 (FLE Daylight Time)", fooCount: 2}]*/