SQLx-ts is a CLI application featuring compile-time checked queries without a DSL and generates types against SQLs to keep your code type-safe.
Introduction to SQLx-ts
SQLx-ts empowers developers with tools to ensure that SQL queries are not only error-free at compile-time, but also maintain type safety throughout the development process. Let’s explore the features that make it indispensable for TypeScript and JavaScript developers:
- Compile time checked queries: Never ship a broken SQL query to production. Remember, SQLx-ts is not an ORM.
- TypeScript type generations: Generates type definitions based on the raw SQLs which can be used with any MySQL or PostgreSQL driver.
- Database Agnostic: Supports both PostgreSQL and MySQL, with more database supports to come.
- TypeScript and JavaScript: Supports for both TypeScript and JavaScript.
Installation
Installing SQLx-ts is a breeze. Follow these steps to get started:
Step 1: Install the sqlx-ts npm module (recommended)
If you are using npm:
$ npm install sqlx-ts
If you are using yarn:
$ yarn add sqlx-ts
You can also install SQLx-ts globally:
$ npm install -g sqlx-ts
Verify the installation by running:
$ npx sqlx-ts --version
To use SQLx-ts in your code, follow these examples:
- In TypeScript based projects:
import sql from 'sqlx-ts' const query = sql`SELECT * FROM some_table`; - In Babel based projects:
import sql from 'sqlx-ts' const query = sql`SELECT * FROM some_table`;
Step 2: Installing binary separately
If you choose to install the SQLx-ts binary separately, use install.sh. The binary name for SQLx-ts is sqlx-ts. You can find precompiled binaries for Windows, macOS, and Linux here.
Choose the command based on your operating system:
- macOS:
- ARM CPU:
# curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh sh -s -- --os darwin --cpu arm64 - X64 CPU:
# curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh sh -s -- --os darwin --cpu x64
- ARM CPU:
- Windows:
- x32:
# curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh sh -s -- --os win32 --cpu x32 - x64:
# curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh sh -s -- --os win32 --cpu x64
- x32:
- Linux:
- x32:
# curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh sh -s -- --os linux --cpu x32 - x64:
# curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh sh -s -- --os linux --cpu x64 - arm:
# curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh sh -s -- --os linux --cpu arm64
- x32:
Upgrading and Advanced Usage
To upgrade to a new version, grab the next version of the SQLx-ts artifact and use the --force command from install.sh.
# curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh sh -s -- --artifact sqlx-ts-v0.1.0-macos-arm.zip --force
For advanced usage, check the --help command of install.sh.
Understanding SQLx-ts with an Analogy
Think of SQLx-ts as your personal librarian in a massive library (your database). Instead of throwing any book into your backpack (sending random SQL queries), SQLx-ts verifies the availability of each book while ensuring it’s exactly what you want. It saves you from embarrassment when you realize you’ve been carrying around a non-existent book (a broken SQL query) because it checks everything at compile-time. This way, as long as the librarian gives you the green light, you can use any book you wish (SQL syntax) without sticking to a rigid blueprint (ORM limitations).
Troubleshooting
If you encounter issues, here are some common troubleshooting tips:
- Ensure you have installed the package correctly and on the right operating system.
- Double-check the syntax of your SQL queries; proper compilation requires accuracy.
- If you have compatibility issues, verify the driver versions of MySQL or PostgreSQL.
- For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Final Thoughts
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

