Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: drizzle-team/drizzle-orm
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.40.0
Choose a base ref
...
head repository: drizzle-team/drizzle-orm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.40.1
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Mar 17, 2025

  1. Updates to neon-http for @neondatabase/serverless@1.0.0, when relea…

    …sed (#4237)
    
    * Updates for @neondatabase/serverless@1.0.0 compatibility
    
    * Clearer comments
    
    * Linting
    jawj authored Mar 17, 2025
    Copy the full SHA
    1fe7362 View commit details
  2. Add release notes

    AndriiSherman committed Mar 17, 2025
    Copy the full SHA
    f07c427 View commit details
Showing with 22 additions and 10 deletions.
  1. +3 −0 changelogs/drizzle-orm/0.40.1.md
  2. +1 −1 drizzle-orm/package.json
  3. +18 −9 drizzle-orm/src/neon-http/session.ts
3 changes: 3 additions & 0 deletions changelogs/drizzle-orm/0.40.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### Updates to `neon-http` for `@neondatabase/serverless@1.0.0` - thanks @jawj

Starting from this version, drizzle-orm will be compatible with both `@neondatabase/serverless` <1.0 and >1.0
2 changes: 1 addition & 1 deletion drizzle-orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-orm",
"version": "0.40.0",
"version": "0.40.1",
"description": "Drizzle ORM package for SQL databases",
"type": "module",
"scripts": {
27 changes: 18 additions & 9 deletions drizzle-orm/src/neon-http/session.ts
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ const queryConfig = {

export class NeonHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {
static override readonly [entityKind]: string = 'NeonHttpPreparedQuery';
private clientQuery: (sql: string, params: any[], opts: Record<string, any>) => NeonQueryPromise<any, any>;

constructor(
private client: NeonHttpClient,
@@ -36,6 +37,10 @@ export class NeonHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPrep
private customResultMapper?: (rows: unknown[][]) => T['execute'],
) {
super(query);
// `client.query` is for @neondatabase/serverless v1.0.0 and up, where the
// root query function `client` is only usable as a template function;
// `client` is a fallback for earlier versions
this.clientQuery = (client as any).query ?? client as any;
}

async execute(placeholderValues: Record<string, unknown> | undefined): Promise<T['execute']>;
@@ -50,10 +55,10 @@ export class NeonHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPrep

this.logger.logQuery(this.query.sql, params);

const { fields, client, query, customResultMapper } = this;
const { fields, clientQuery, query, customResultMapper } = this;

if (!fields && !customResultMapper) {
return client(
return clientQuery(
query.sql,
params,
token === undefined
@@ -65,7 +70,7 @@ export class NeonHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPrep
);
}

const result = await client(
const result = await clientQuery(
query.sql,
params,
token === undefined
@@ -96,7 +101,7 @@ export class NeonHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPrep
all(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {
const params = fillPlaceholders(this.query.params, placeholderValues);
this.logger.logQuery(this.query.sql, params);
return this.client(
return this.clientQuery(
this.query.sql,
params,
this.authToken === undefined ? rawQueryConfig : {
@@ -113,7 +118,7 @@ export class NeonHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPrep
values(placeholderValues: Record<string, unknown> | undefined = {}, token?: NeonAuthToken): Promise<T['values']> {
const params = fillPlaceholders(this.query.params, placeholderValues);
this.logger.logQuery(this.query.sql, params);
return this.client(this.query.sql, params, { arrayMode: true, fullResults: true, authToken: token }).then((
return this.clientQuery(this.query.sql, params, { arrayMode: true, fullResults: true, authToken: token }).then((
result,
) => result.rows);
}
@@ -134,6 +139,7 @@ export class NeonHttpSession<
> extends PgSession<NeonHttpQueryResultHKT, TFullSchema, TSchema> {
static override readonly [entityKind]: string = 'NeonHttpSession';

private clientQuery: (sql: string, params: any[], opts: Record<string, any>) => NeonQueryPromise<any, any>;
private logger: Logger;

constructor(
@@ -143,6 +149,10 @@ export class NeonHttpSession<
private options: NeonHttpSessionOptions = {},
) {
super(dialect);
// `client.query` is for @neondatabase/serverless v1.0.0 and up, where the
// root query function `client` is only usable as a template function;
// `client` is a fallback for earlier versions
this.clientQuery = (client as any).query ?? client as any;
this.logger = options.logger ?? new NoopLogger();
}

@@ -168,13 +178,12 @@ export class NeonHttpSession<
) {
const preparedQueries: PreparedQuery[] = [];
const builtQueries: NeonQueryPromise<any, true>[] = [];

for (const query of queries) {
const preparedQuery = query._prepare();
const builtQuery = preparedQuery.getQuery();
preparedQueries.push(preparedQuery);
builtQueries.push(
this.client(builtQuery.sql, builtQuery.params, {
this.clientQuery(builtQuery.sql, builtQuery.params, {
fullResults: true,
arrayMode: preparedQuery.isResponseInArrayMode(),
}),
@@ -189,7 +198,7 @@ export class NeonHttpSession<
// change return type to QueryRows<true>
async query(query: string, params: unknown[]): Promise<FullQueryResults<true>> {
this.logger.logQuery(query, params);
const result = await this.client(query, params, { arrayMode: true, fullResults: true });
const result = await this.clientQuery(query, params, { arrayMode: true, fullResults: true });
return result;
}

@@ -198,7 +207,7 @@ export class NeonHttpSession<
query: string,
params: unknown[],
): Promise<FullQueryResults<false>> {
return this.client(query, params, { arrayMode: false, fullResults: true });
return this.clientQuery(query, params, { arrayMode: false, fullResults: true });
}

override async count(sql: SQL): Promise<number>;