# [SQL派]pgtyped(将SQL写在TS里+仅pg)

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,
  );

# 参考 @ref