Skip to content

Conversation

adamchol
Copy link

With the release of pglite, one could really benefit from running a postgres (pglite) instance and pgtyped in a single script. This PR makes it easier by exposing an internal function from pgtyped for processing a single file with minimal configuration.

Most of the "modularize" work was to just divide the @pgtyped/cli package into two packages: @pgtyped/cli and a new package @pgtyped/typegen which is only responsible for generating TS types code and unlimitedly exposes a single function getTypes which processes a single file. This function is then used by the CLI and can be used by the user.

I also divided the config so the the typegen function only takes arguments that it really needs.

There is actually much more we can do with pglite in terms of types generation. With the right changes we probably don't even need to establish any TCP connection when working with pglite instance to generate types.

Copy link

vercel bot commented Aug 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Project Deployment Preview Comments Updated (UTC)
pgtyped Ready Preview Comment Aug 13, 2025 7:55am

Copy link

@wokalski wokalski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spotted these little issues.

import { TypedSqlTagTransformer } from './typedSqlTagTransformer.js';
import { TypescriptAndSqlTransformer } from './typescriptAndSqlTransformer.js';
import { debug } from './util.js';
export const debug = debugBase('pg-typegen');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const debug = debugBase('pg-typegen');
const debug = debugBase('pg-typegen');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant change

Comment on lines -3 to -26
import type { Category } from '../customTypes.js';

export type categoryArray = (Category)[];
/** 'SqlSelectFromBooksWhereIdId' parameters type */
export interface ISqlSelectFromBooksWhereIdIdParams {
id?: number | null | void;
}

/** 'SqlSelectFromBooksWhereIdId' return type */
export interface ISqlSelectFromBooksWhereIdIdResult {
author_id: number | null;
categories: categoryArray | null;
id: number;
name: string | null;
rank: number | null;
}

/** 'SqlSelectFromBooksWhereIdId' query type */
export interface ISqlSelectFromBooksWhereIdIdQuery {
params: ISqlSelectFromBooksWhereIdIdParams;
result: ISqlSelectFromBooksWhereIdIdResult;
}

export function sql(s: `SELECT * FROM books WHERE id = $id`): ReturnType<typeof sourceSql<ISqlSelectFromBooksWhereIdIdQuery>>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants