All Projects → wsporto → typesql

wsporto / typesql

Licence: MIT License
TypeSQL - Generate Typescript API from raw MySQL queries. Compatible with Deno and Node.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to typesql

Thread
type safe multi-threading made easier
Stars: ✭ 34 (-8.11%)
Mutual labels:  typesafe, deno
sql-to-laravel-builder
SQL to Laravel Query Builder
Stars: ✭ 133 (+259.46%)
Mutual labels:  query-builder
nhttp
An Simple http framework for Deno, Deno Deploy and Cloudflare Workers. so hot 🚀
Stars: ✭ 26 (-29.73%)
Mutual labels:  deno
Netrex
A powerful minecraft bedrock software written in Rust with a powerful Typescript plugin API.
Stars: ✭ 35 (-5.41%)
Mutual labels:  deno
make-deno-edition
Automatically makes package.json projects (such as npm packages and node.js modules) compatible with Deno.
Stars: ✭ 39 (+5.41%)
Mutual labels:  deno
PdoOne
It simplifies the use of PDO in PHP by adding three methods: a simple wrapper between PDO, a query builder and an ORM.
Stars: ✭ 93 (+151.35%)
Mutual labels:  query-builder
dndb
A Deno 🦕 persistent, embeddable and optimized NoSQL database for JS & TS
Stars: ✭ 64 (+72.97%)
Mutual labels:  deno
destjs
Make beautiful APIs with the NestJS inspired framework for Deno
Stars: ✭ 31 (-16.22%)
Mutual labels:  deno
Ptero
Ptero is a middleware for Deno build RESTful APIs.
Stars: ✭ 43 (+16.22%)
Mutual labels:  deno
searchable
Pattern-matching search and reusable queries in laravel.
Stars: ✭ 28 (-24.32%)
Mutual labels:  query-builder
heroku-buildpack-deno
Heroku Buildpack for Deno
Stars: ✭ 72 (+94.59%)
Mutual labels:  deno
discord-api-types
Up to date Discord API Typings, versioned by the API version
Stars: ✭ 270 (+629.73%)
Mutual labels:  deno
pyroclastic
Functional dataflow through composable computations
Stars: ✭ 17 (-54.05%)
Mutual labels:  typesafe
nasa-deno
Deno NASA Mission Control Project
Stars: ✭ 17 (-54.05%)
Mutual labels:  deno
deno-playground
play.golang.org, but built in deno, and for deno.
Stars: ✭ 57 (+54.05%)
Mutual labels:  deno
sherlock-deno
🕵️ Find usernames across 350+ websites & social networks - written in TypeScript and run via Deno
Stars: ✭ 19 (-48.65%)
Mutual labels:  deno
oak-middleware-jwt
Oak middleware for JWT
Stars: ✭ 24 (-35.14%)
Mutual labels:  deno
cors
Deno.js CORS middleware.
Stars: ✭ 46 (+24.32%)
Mutual labels:  deno
youtube-deno
A Deno client library of the YouTube Data API.
Stars: ✭ 30 (-18.92%)
Mutual labels:  deno
cnpj
🇧🇷 Format, validate and generate CNPJ numbers in Node & Deno
Stars: ✭ 26 (-29.73%)
Mutual labels:  deno

TypeSQL: An alternative to access MySQL databases without an ORM. Write your queries in raw SQL and TypeSQL will generate a type-safe API to execute the queries.

Example

Having the following query in select-products.sql file.

SELECT 
  id,
  product_name,
  list_price
FROM products
WHERE discontinued = 0
  AND list_price BETWEEN :minPrice AND :maxPrice

TypeSQL will generate the types and function in the file select-products.ts. Then you can import the generate code and execute as following:

deno syntax:

Some features:

  • Do not restrict the use of SQL You dont need to learn any new query language, you can use SQL with all its power and expressiveness.

  • Infer parameters and columns types. SELECT DATEDIFF(:date1, :date2) as days_stayed will resolve the date1 and date2 parameters to the type Date and the function return type as number.

  • Infer parameter and column nullability. The nullable database column email will generate a nullable field for the query SELECT email FROM mytable, but will generate a non-nullable field for the query SELECT email FROM mytable WHERE email is not null;

  • Infer the query return type (single row vs multiple rows). If the id is a primary key or unique key, then function for the query SELECT * FROM Books where id = :id will return Book|null, instead of Book[]. The same is true for filters with LIMIT 1;

  • Allow the use of dynamic ORDER BY with auto-completion and compile-time verification. See here.

Usage

  1. npm install -g typesql-cli

  2. Add the typesql.json configuration file in project root folder. You can generate an template with cli command typesql init.

{
    "databaseUri": "mysql://root:password@localhost/mydb",
    "sqlDir": "./sqls",
    "target": "node"
}
  1. Write your queries in the folder specified in the configuration file. You can also use the cli to scaffold the queries.
sqls\
    select-products.sql
    insert-product.sql
    update-product.sql
  1. Then run typesql compile --watch to start typesql in watch mode. After that you will have one Typescript file for each query file.
sqls\
    select-products.sql
    select-products.ts
    insert-product.sql
    insert-product.ts
    update-product.sql
    update-product.ts
  1. Now you can import and use the generated code.
const products = await selectProducts(...

const updateResult = await updateProduct(...

Examples

Query scaffolding

INSERT

IN/NOT IN Clause

MySQL FUNCTIONS

ORDER BY and LIMIT clauses

Project status

WARNING: This is a WIP experimental project. It is under active development and its API might change.

Issues reports and feature requests are welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].