Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typesql-cli

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typesql-cli

Typesql: Generate type safe api for **mysql** databases.

  • 0.4.1
  • npm
  • Socket score

Version published
Weekly downloads
42
decreased by-91.97%
Maintainers
1
Weekly downloads
 
Created
Source

Typesql: Generate type safe api for mysql databases.

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:

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

Order by and limit clauses

Project status

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

Issues reports and feature requests are welcome.

FAQs

Package last updated on 10 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc