TypeSQL with Deno
How to use TypeSQL with Deno
This guide will provide a step-by-step process for using TypeSQL with Deno.
- Setting Up a New Project
- Add
npm:@lisbql/client
as a Dependency:
- Add a Task to Run TypeSQL
Since TypeSQL is used only during development, you don’t need to add it as a dependency. Instead, you can add a script to run it. You’ll also need to specify the necessary permissions for Deno to execute the typesql-cli. Permissions required:
--allow-read (-R)
: Permission to read thenode_module
folder.--allow-env (-E):
Permission to read the enviroment variable (required by some libraries).--allow-ffi:
Permission for the libsql dependency.--allow-write:
Permission to write the generated code in the folder./src/sql
.
- Create the
typesql.json
Configuration File
Deno will prompt for permission to write the typesql.json
configuration file.
- Modify the
typesql.json
and create the./src/sql
folder where your SQL queries will reside:
- Write your queries
- Generate the code with TypeSQL:
This will generate TypeScript client code for your queries in the specified folder (e.g., ./src/sql).
- Import the generated functions:
Now you can import and run your queries from the generated TypeScript code. For example, in your src/main.ts file:
- Run
Finally, you can run with the following command: