{"id":13847400,"url":"https://github.com/wsporto/typesql","last_synced_at":"2025-07-12T09:31:55.066Z","repository":{"id":42246281,"uuid":"277012418","full_name":"wsporto/typesql","owner":"wsporto","description":"TypeSQL - Generate Typescript API from raw SQL. Supports MySQL, Sqlite and LibSQL (Turso)","archived":false,"fork":false,"pushed_at":"2024-10-18T13:38:31.000Z","size":2646,"stargazers_count":220,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-20T14:13:30.447Z","etag":null,"topics":["deno","mysql","node","raw-sql","sql","sqlite","typesafe","typescript"],"latest_commit_sha":null,"homepage":"https://typesql.pages.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wsporto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-04T00:47:45.000Z","updated_at":"2024-10-18T14:37:39.000Z","dependencies_parsed_at":"2023-09-29T01:24:06.712Z","dependency_job_id":"2b1a5a11-ea4b-4da8-b358-da48a9f0261b","html_url":"https://github.com/wsporto/typesql","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsporto%2Ftypesql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsporto%2Ftypesql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsporto%2Ftypesql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsporto%2Ftypesql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wsporto","download_url":"https://codeload.github.com/wsporto/typesql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225812896,"owners_count":17528083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","mysql","node","raw-sql","sql","sqlite","typesafe","typescript"],"created_at":"2024-08-04T18:01:19.003Z","updated_at":"2025-07-12T09:31:55.050Z","avatar_url":"https://github.com/wsporto.png","language":"TypeScript","readme":"## TypeSQL\n\n**TypeSQL** generates typesafe Typescript APIs from your SQL statements. Write your queries in raw SQL and TypeSQL generates the type-safe APIs to execute those queries.\n\nAccess your database directly without a heavy ORM, gain effortless type-safety, and make maintaining your SQL simple.\n\nTypeSQL supports multiple SQL database backends:\n\n##### PostgreSQL (Experimental)\n\n- [pg](https://www.npmjs.com/package/pg) - PostgreSQL client for node.js.\n\n##### MySQL\n\n- [mysql2](https://www.npmjs.com/package/mysql2) - the standard driver for mysql in NodeJS\n\n##### SQLite\n- [better-sqlite3](https://www.npmjs.com/package/better-sqlite3) - the fastest SQLite driver for NodeJS\n- [bun:sqlite](https://bun.sh/docs/api/sqlite) - Bun's official high-performance SQLite driver\n\n##### LibSQL\n- [libsql](https://www.npmjs.com/package/libsql) - the NodeJS driver for libSQL, the open-source fork of SQLite powering [Turso](https://turso.tech/)\n\n##### Cloudflare D1\n- [@cloudflare/d1](https://developers.cloudflare.com/d1/) - Serverless SQLite-compatible database from Cloudflare.\n\n## Example\n\nHaving the following query in `select-products.sql` file.\n\n```sql\nSELECT\n  id,\n  product_name,\n  list_price\nFROM products\nWHERE discontinued = 0\n  AND list_price BETWEEN :minPrice AND :maxPrice\n```\n\nTypeSQL will generate the types and function in the file `select-products.ts`.\nThen you can import the generate code and execute as following:\n\ndeno syntax:\n\n![](typesql-deno.gif)\n\n## Some features:\n\n- **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.\n\n- **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`.\n\n- **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`;\n\n- **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;\n\n- Allow the use of **dynamic ORDER BY** with auto-completion and compile-time verification. See [here](/docs/orderBy_limit.md).\n\n## Usage\n\n1. _npm install -g typesql-cli_\n\n2. Add the `typesql.json` configuration file in project root folder. You can generate an template with cli command `typesql init`. The client option can be: 'pg', 'mysql2', 'better-sqlite3', 'libsql', 'bun:sqlite' or 'd1'. The `authToken` configuration is used only for the libsql client.\n\n```json\n{\n  \"databaseUri\": \"mysql://root:password@localhost/mydb\",\n  \"sqlDir\": \"./sqls\",\n  \"client\": \"mysql2\",\n  \"authToken\": \"authtoken\",\n  \"includeCrudTables\": []\n}\n```\n\n3. Write your queries in the folder specified in the configuration file. You can also use the cli to scaffold the queries.\n\n```\nsqls\\\n    select-products.sql\n    insert-product.sql\n    update-product.sql\n```\n\n4. Then run `typesql compile --watch` to start typesql in watch mode. After that you will have one Typescript file for each query file.\n\n```\nsqls\\\n    select-products.sql\n    select-products.ts\n    insert-product.sql\n    insert-product.ts\n    update-product.sql\n    update-product.ts\n```\n\n5. Now you can import and use the generated code.\n\n```\nconst products = await selectProducts(...\n\nconst updateResult = await updateProduct(...\n```\n\n## Examples\n\n[Query scaffolding](/docs/query_scaffolding.md)\n\n[INSERT](/docs/insert.md)\n\n[IN/NOT IN Clause](/docs/in_clause.md)\n\n[MySQL FUNCTIONS](/docs/functions.md)\n\n[ORDER BY and LIMIT clauses](/docs/orderBy_limit.md)\n\n[LIKE](/docs/like.md)\n\n[Nested Query Result](/docs/nested-query-result.md)\n\n## Project Status: Under Active Development\n\n**WARNING:** This is a work-in-progress experimental project. It is under active development and its API might change.\n\nIssues reports and feature requests are welcome.\n","funding_links":[],"categories":["TypeScript","**1. Libraries**"],"sub_categories":["Database"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwsporto%2Ftypesql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwsporto%2Ftypesql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwsporto%2Ftypesql/lists"}