{"id":19481834,"url":"https://github.com/jasonshin/sqlx-ts","last_synced_at":"2026-04-02T17:49:54.957Z","repository":{"id":38199407,"uuid":"474236277","full_name":"JasonShin/sqlx-ts","owner":"JasonShin","description":"node.js compile-time SQL validations \u0026 type generations","archived":false,"fork":false,"pushed_at":"2025-03-22T00:34:51.000Z","size":3095,"stargazers_count":206,"open_issues_count":11,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-01T08:42:42.700Z","etag":null,"topics":["mysql","nodejs","postgresql","rust","sql","sqlx","typescript"],"latest_commit_sha":null,"homepage":"https://jasonshin.github.io/sqlx-ts/","language":"Rust","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/JasonShin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-26T04:00:31.000Z","updated_at":"2025-03-31T06:08:04.000Z","dependencies_parsed_at":"2023-11-11T04:20:55.513Z","dependency_job_id":"aeb29b93-7242-4902-a418-4f623127e41d","html_url":"https://github.com/JasonShin/sqlx-ts","commit_stats":{"total_commits":244,"total_committers":3,"mean_commits":81.33333333333333,"dds":"0.012295081967213073","last_synced_commit":"a4c6ac10969873a05ba267afc83c7369d92ee446"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonShin%2Fsqlx-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonShin%2Fsqlx-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonShin%2Fsqlx-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonShin%2Fsqlx-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JasonShin","download_url":"https://codeload.github.com/JasonShin/sqlx-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809962,"owners_count":20999816,"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":["mysql","nodejs","postgresql","rust","sql","sqlx","typescript"],"created_at":"2024-11-10T20:06:46.243Z","updated_at":"2026-04-02T17:49:54.952Z","avatar_url":"https://github.com/JasonShin.png","language":"Rust","readme":"\u003ch1 align=\"center\"\u003esqlx-ts\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n \u003cstrong\u003e\n   🧰 The Typescript/Javascript SQL Toolkit\n \u003c/strong\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\nSQLx-ts is a CLI application featuring compile-time checked queries without a DSL and generates types against SQLs to keep your code type-safe\n\n- **Compile time checked queries** - never ship a broken SQL query to production (and [sqlx-ts is not an ORM](https://github.com/JasonShin/sqlx-ts#sqlx-ts-is-not-an-orm))\n- **TypeScript type generations** - generates type definitions based on the raw SQLs and you can use them with any MySQL or PostgreSQL driver\n- **Database Agnostic** - support for [PostgreSQL](http://postgresql.org/) and [MySQL](https://www.mysql.com/) (and more DB supports to come)\n- **TypeScript and JavaScript** - supports for both [TypeScript](https://jasonshin.github.io/sqlx-ts/reference-guide/4.typescript-types-generation.html) and [JavaScript](https://github.com/JasonShin/sqlx-ts#using-sqlx-ts-in-vanilla-javascript)\n\n\u003cbr\u003e\n\u003cdiv align=\"center\"\u003e\n    \u003cstrong\u003e\n    📔 \u003ca href=\"https://jasonshin.github.io/sqlx-ts/\"\u003eOfficial Documentation\u003c/a\u003e\n    \u003c/strong\u003e\n    \u003cstrong\u003e | \u003c/strong\u003e\n    \u003cstrong\u003e\n        🤓 \u003ca href=\"https://github.com/JasonShin/sqlx-ts-demo\"\u003eDemo\u003c/a\u003e\n    \u003c/strong\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\n### Installation\n\n##### Install sqlx-ts npm module (recommended)\n\nIf you are using npm\n```bash\n$ npm install sqlx-ts\n```\n\nIf you are using yarn\n```bash\n$ yarn add sqlx-ts\n```\n\nYou can also install sqlx-ts globally\n```bash\n$ npm install -g sqlx-ts\n```\n\nInstalling sqlx-ts using npm also installed `sqlx-ts` binary of the same version as the npm module.\nVerify the installation by running\n\n```bash\n$ npx sqlx-ts --version\n```\n\nAnd to use sqlx-ts in your code\n\nIn TypeScript based projects:\n\n```typescript\nimport { sql } from 'sqlx-ts'\n\n// ...\nconst query = sql`SELECT * FROM some_table;`\n// ...\n```\n\n\nIn Babel based projects:\n\n```javascript\nimport { sql } from 'sqlx-ts'\nconst query = sql`SELECT * FROM some_table;`\n\n// ... or\n\nconst { sql } = require('sqlx-ts')\nconst query = sql`SELECT * FROM some_table;`\n```\n\n#### Using Raw SQL Files\n\nCreate a SQL file with annotations:\n\n```sql\n-- users.sql\n-- @name: getUserById\nSELECT id, name, email FROM users WHERE id = $1;\n\n-- @name: createUser\nINSERT INTO users (name, email) VALUES ($1, $2) RETURNING id;\n```\n\nThen, you can use the `sqlx-ts` CLI to generate TypeScript types and check the SQL queries\n\n\n##### Installing binary separately\n\nYou may choose to install sqlx-ts separately instead of using `npm i`\n\n###### Using install.sh\n\nThe binary name for sqlx-ts is `sqlx-ts`.\n\n[Archives of precompiled binaries of sqlx-ts are available for windows, macOS and Linux](https://github.com/JasonShin/sqlx-ts/releases). Linux and Windows binaries are static executables. Users of platforms not explicitly mentioned below are advised to download one of these archives.\n\nIf you're a **macOS** user, then you can install sqlx-ts from via install.sh:\n\n```bash\n# macos \u0026 ARM CPU\n$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os darwin --cpu arm64\n# macos \u0026 X64 CPU\n$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os darwin --cpu x64\n```\n\nIf you're a **Windows** user, then you can install sqlx-ts from via install.sh:\n\n```bash\n# windows \u0026 x32\n$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os win32 --cpu x32\n# windows \u0026 x64\n$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os win32 --cpu x32\n```\n\nIf you're a **Linux** user, then you can install sqlx-ts from via install.sh:\n\n```bash\n# linux \u0026 x32\n$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os linux --cpu x32\n# linux \u0026 x64\n$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os linux --cpu x64\n# linux \u0026 arm\n$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os linux --cpu arm64\n```\n\nTo install a specific artifact, [go to the release page to find the exact name of the artifact](https://github.com/JasonShin/sqlx-ts/releases)\n\n```bash\n$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --artifact sqlx-ts-v0.1.0-macos-arm.zip\n```\n\nUpgrading to a new version can be done by grabbing the next version of the sqlx-ts artifact and use `--force` command from install.sh\n\n```bash\n$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | \\\n    sh -s -- --artifact ssqlx-ts-v0.1.0-macos-arm.zip --force\n```\n\nFor more advanced usage, please check `--help` command of install.sh\n\n```bash\n$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | \\\n    sh -s -- --help\n```\n\n### Roadmap\n\n[Please check the public notion board for the current and future work items](https://foil-adasaurus-bba.notion.site/f1ca150c5b0141d69eaf136c596ae649?v=efc6af2aa3174f87a39bec8edc09c4a9)\n\n### sqlx-ts is not an ORM!\n\nsqlx-ts supports **compile-time checked queries** and **generated types against SQLs**. It does not, however, do this by providing DSL (domain-specific language) for building queries. Instead, it provides a macro (almost) that take regular SQL as input and ensures that it is valid against the target database. The way it works is that sqlx-ts connects to your local or development database at compile-time and have database itself to verify the queries, also generate types based on information_schema. This can have many benefits that typical ORMs cannot provide\n- Since sqlx-ts simply sends the queries back to the DB, almost any SQL syntax can be used in sqlx-ts (including things added by database extensions)\n- You can easily optimize the queries as the SQLs are not built using a query-builder or an ORM interface\n- The generated types work well with almost any database driver or even ORMs if they have good typescript support (that allows you to override input and output types)\n\nbut it comes with some implications\n- The amount of information that sqlx-ts retrieves depend on the type of the database (e.g. MySQL vs PostgreSQL)\n\nIf you are looking for an ORM, you can checkout [Sequelize](https://sequelize.org/) or [Prisma](https://www.prisma.io/).\n\n### Using sqlx-ts in vanilla JavaScript\n\nIf you are trying to use sqlx-ts against vanilla JS, the [TypeScript type-generation](https://jasonshin.github.io/sqlx-ts/reference-guide/4.typescript-types-generation.html) feature wouldn't be helpful. You can simply use [SQL Check](https://jasonshin.github.io/sqlx-ts/reference-guide/1.sql-check.html) feature to keep your SQLs in JS code safe and compile-time checked.\n\n### Motivation\n\nI would like to bring the powerful compile-time safety ideas to Node.js. [sqlx](https://github.com/launchbadge/sqlx) is a great example of this, as it provides compile-time check of SQLs within your Rust code and Rust itself provides a great environment for tools like sqlx. sqlx-ts is greatly inspired by [sqlx](https://github.com/launchbadge/sqlx), but solves additional problems of generating TypeScript interfaces based on the SQL queries that are present in your code.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonshin%2Fsqlx-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasonshin%2Fsqlx-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonshin%2Fsqlx-ts/lists"}