SELECT * semantics — all within the type layer of TypeScript, with zero runtime logic. SqlType helps developers catch query issues during development, creating safer and more predictable data access layers in TypeScript-based systems. SELECT statements and schema inputs.SELECT queries, including expressions and function calls. INNER, LEFT, RIGHT, and FULL OUTER JOINs with alias resolution and field mapping. COUNT(...) are checked at compile time for valid argument types and nesting. // Example 1: Simple SELECT with alias
type Tables = {
users: {
id: number;
name: string;
};
};
type Query = "SELECT users.name AS username FROM users";
type Result = BuildQuery<Query, Tables>;
/*
Result:
{
username: string;
}
*/ // Example 2: COUNT aggregation with JOIN
type Tables = {
users: {
id: number;
name: string;
};
posts: {
id: number;
user_id: number;
};
};
type Query = "SELECT COUNT(posts.id) AS totalPosts FROM users LEFT JOIN posts ON users.id = posts.user_id";
type Result = BuildQuery<Query, Tables>;
/*
Result:
{
totalPosts: number;
}
*/ // Example 3: Multiple columns with alias and join
type Tables = {
users: {
id: number;
name: string;
};
posts: {
id: number;
user_id: number;
title: string;
};
};
type Query = "SELECT u.name AS username, COUNT(p.id) AS total FROM users u LEFT JOIN posts p ON u.id = p.user_id";
type Result = BuildQuery<Query, Tables>;
/*
Result:
{
username: string;
total: number;
}
*/