Write SQL
No query builders. Just SQL.
API documentation
Types for database queries with minimum fuss. Supports MySQL, PostgreSQL and SQLite.
import { Database } from "ts-query-model";
import MySQLConnection from "ts-query-model/mysql";
const db = new Database(
new MySQLConnection({
uri: "mysql://your-database-connection-string",
})
);
const myAwesomeModel = {
getUsers: db.getMany({
name: "get-all-users",
columns: {
id: columns.numberAutoIncrement(),
name: columns.string(),
dateCreated: columns.date(),
isAwesome: columns.booleanInt(),
},
query: (limit: number) =>
SQL`SELECT id, name, dateCreated, isAwesome FROM users LIMIT ${limit}`,
}),
};
const awesomeUsers = await myAwesomeModel.getUsers(10);