#typescript #postgresql #mysql #sqlite #json-file

bin+lib ts_sqlx

Typescript SQLx compile-time checked queries without a DSL

4 releases

0.1.3 Oct 21, 2024
0.1.2 Feb 11, 2024
0.1.1 Feb 10, 2024
0.1.0 Feb 4, 2024

#665 in Database interfaces

MIT/Apache

83KB
1.5K SLoC

Rust 1.5K SLoC // 0.0% comments TypeScript 97 SLoC JavaScript 55 SLoC SQL 20 SLoC

ts-sqlx

license API Crate

Typescript SQLx compile-time checked queries without a DSL.

Getting started

install the ts-sqlx cli tool globally

cargo install ts_sqlx

in your project install the typescript definitions

npm install ts-sqlx -D

include the path to generated declaration files in your tsconfig.json

{
  // default destination of declaration files
  "include": [".ts-sqlx/*"]
}

create a .env file with DATABASE_URL set to your database url

DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres

or create a .ts-sqlx.json file like

{
  "databases": {
    "default": "postgres://postgres:postgres@localhost:5432/postgres",
    "another": "postgres://postgres:postgres@localhost:5432/postgres"
  },
  // defaults shown below, the rest of these are optional
  "src": ".",
  "dest": ".ts-sqlx",
  "extensions": ["ts", "tsx", "js", "jsx"],
  "ignore_patterns": ["*.d.ts"]
}

run in watch mode ts-sqlx watch in the root of your project, just once with ts-sqlx run or for help ts-sqlx help

see example for a "full" project example

References

Dependencies

~25–41MB
~662K SLoC