
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
PgTyped makes it possible to use raw SQL in TypeScript with guaranteed type-safety.
No need to map or translate your DB schema to TypeScript, PgTyped automatically generates types and interfaces for your SQL queries by using your running Postgres database as the source of type information.
Visit our new documentation page at https://pgtyped.now.sh/
npm install pgtyped-cli-2 pgtyped-query-2 typescript (typescript is a required peer dependency for pgtyped)config.json file.npx pgtyped -w -c config.json to start PgTyped in watch mode.Refer to the example app for a preconfigured example.
Lets save some queries in books.sql:
/* @name FindBookById */
SELECT * FROM books WHERE id = :bookId;
PgTyped parses the SQL file, extracting all queries and generating strictly typed TS queries in books.queries.ts:
/** Types generated for queries found in "books.sql" */
//...
/** 'FindBookById' parameters type */
export interface IFindBookByIdParams {
bookId: number | null;
}
/** 'FindBookById' return type */
export interface IFindBookByIdResult {
id: number;
rank: number | null;
name: string | null;
author_id: number | null;
}
/**
* Query generated from SQL:
* SELECT * FROM books WHERE id = :bookId
*/
export const findBookById = new PreparedQuery<
IFindBookByIdParams,
IFindBookByIdResult
>(...);
Query findBookById is now statically typed, with types inferred from the PostgreSQL schema.
This generated query can be imported and executed as follows:
import { Client } from 'pg';
import { findBookById } from './books.queries';
export const client = new Client({
host: 'localhost',
user: 'test',
password: 'example',
database: 'test',
});
async function main() {
await client.connect();
const books = await findBookById.run(
{
bookId: 5,
},
client,
);
console.log(`Book name: ${books[0].name}`);
await client.end();
}
main();
This project is being actively developed and its APIs might change. All issue reports, feature requests and PRs appreciated.
Copyright (c) 2019-present, Adel Salakh
FAQs
Unknown package
The npm package pgtyped receives a total of 2,413 weekly downloads. As such, pgtyped popularity was classified as popular.
We found that pgtyped demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.