SQLx-ts is a CLI application featuring compile-time checked queries without a DSL and prevents broken SQL queries being run during runtime.
- Compile time checked queries - never ship a broken SQL query to production
- Database Agnostic - support for PostgreSQL and MySQL
- TypeScript and JavaScript - supports for both TypeScript and JavaScript
Installation
Install sqlx-ts npm module
If you are using npm
If you are using yarn
And to use sqlx-ts in your code
In TypeScript based projects:
import { sql } from 'sqlx-ts'
// ...
const query = sql`SELECT * FROM some_table;`
// ...
In Babel based projects:
import from 'sqlx-ts'
const query = `SELECT * FROM some_table;`
// ... or
const = require
const query = `SELECT * FROM some_table;`
Installing binary
The binary name for sqlx-ts is sqlx-ts.
Archives of precompiled binaries of sqlx-ts are available for Windows, macOS and Linux. Linux and Windows binaries are static executables. Users of platforms not explicitly mentioned below are advised to download one of these archives.
If you're a macOS user, then you can install sqlx-ts from via install.sh:
| \
If you're a Windows user, then you can install sqlx-ts from via install.sh:
| \
If you're a Linux user, then you can install sqlx-ts from via install.sh:
| \
To install a specific artifact, go to the release page to find the exact name of the artifact
| \
Upgrading to a new version can be done by grabbing the next version of the sqlx-ts artifact and use --force command from install.sh
| \
For more advanced usage, please check --help command of install.sh
| \
Motivation
Rust's philosophy of guaranteed compile-time safety of your code has always inspired me. Rust is still new and many seasoned developers would view Rust's increased benefit/cost ratio claims are as yet unproven. However, there are lessons from these new technologies that we can bring back to our everyday languages such as JavaScript and TypeScript. SQLx is a great example of this, although the idea isn't directly co-related to Rust, but its philosophy well-aligns with Rust's overall ecosystem.