Custom queries
If you want to generate a custom query, write the query using raw sql in the folder specified on the typesql.config file.
Example:
Having the following query in select-products.sql
file.
SELECT id, product_name, list_priceFROM productsWHERE 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:
const products = await selectProducts(conn, { minPrice: 10, maxPrice: 20,});
/* resultType{ id: number, product_name: string, list_price: number}[]*/