# [SQL派]pgtyped(将SQL写在TS里+仅pg)
- https://github.com/adelsz/pgtyped (opens new window)
- https://pgtyped.dev/docs/sql-file (opens new window)
import { sql } from '@pgtyped/runtime';
import { IGetUsersWithCommentsQuery } from './sample.types';
const getUsersWithComments = sql<IGetUsersWithCommentsQuery>`
SELECT u.* FROM users u
INNER JOIN book_comments bc ON u.id = bc.user_id
GROUP BY u.id
HAVING count(bc.id) > $minCommentCount;`;
const result = await getUsersWithComments.run({ minCommentCount: 12 }, client);
/* @name FindBookById */
SELECT * FROM books WHERE id = :bookId;
const books = await findBookById.run(
{
bookId: 5,
},
client,
);