Skip to content

Commit e0aaeb2

Browse files
authored
Merge pull request #2186 from drizzle-team/beta
Beta
2 parents 4706ad1 + d939ec2 commit e0aaeb2

File tree

15 files changed

+120
-30
lines changed

15 files changed

+120
-30
lines changed

changelogs/drizzle-orm/0.30.9.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- 🐛 Fixed migrator in AWS Data API
2+
- Added `setWhere` and `targetWhere` fields to `.onConflictDoUpdate()` config in SQLite instead of single `where` field
3+
- 🛠️ Added schema information to Drizzle instances via `db._.fullSchema`

drizzle-orm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-orm",
3-
"version": "0.30.8",
3+
"version": "0.30.9",
44
"description": "Drizzle ORM package for SQL databases",
55
"type": "module",
66
"scripts": {

drizzle-orm/src/aws-data-api/pg/session.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ export class AwsDataApiPreparedQuery<T extends PreparedQueryConfig> extends PgPr
6565
: result.rows!.map((row) => mapResultRow<T['execute']>(fields!, row, joinsNotNullableMap));
6666
}
6767

68-
all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']> {
69-
return this.execute(placeholderValues);
68+
async all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']> {
69+
const result = await this.execute(placeholderValues) as AwsDataApiPgQueryResult<unknown>;
70+
return result.rows;
7071
}
7172

7273
async values(placeholderValues: Record<string, unknown> = {}): Promise<T['values']> {
@@ -198,7 +199,7 @@ export class AwsDataApiSession<
198199
): Promise<T> {
199200
const { transactionId } = await this.client.send(new BeginTransactionCommand(this.rawQuery));
200201
const session = new AwsDataApiSession(this.client, this.dialect, this.schema, this.options, transactionId);
201-
const tx = new AwsDataApiTransaction(this.dialect, session, this.schema);
202+
const tx = new AwsDataApiTransaction<TFullSchema, TSchema>(this.dialect, session, this.schema);
202203
if (config) {
203204
await tx.setTransaction(config);
204205
}
@@ -223,7 +224,12 @@ export class AwsDataApiTransaction<
223224
transaction: (tx: AwsDataApiTransaction<TFullSchema, TSchema>) => Promise<T>,
224225
): Promise<T> {
225226
const savepointName = `sp${this.nestedIndex + 1}`;
226-
const tx = new AwsDataApiTransaction(this.dialect, this.session, this.schema, this.nestedIndex + 1);
227+
const tx = new AwsDataApiTransaction<TFullSchema, TSchema>(
228+
this.dialect,
229+
this.session,
230+
this.schema,
231+
this.nestedIndex + 1,
232+
);
227233
await this.session.execute(sql.raw(`savepoint ${savepointName}`));
228234
try {
229235
const result = await transaction(tx);

drizzle-orm/src/libsql/session.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,14 @@ export class LibSQLSession<
8282
): Promise<T> {
8383
// TODO: support transaction behavior
8484
const libsqlTx = await this.client.transaction();
85-
const session = new LibSQLSession(this.client, this.dialect, this.schema, this.options, libsqlTx);
86-
const tx = new LibSQLTransaction('async', this.dialect, session, this.schema);
85+
const session = new LibSQLSession<TFullSchema, TSchema>(
86+
this.client,
87+
this.dialect,
88+
this.schema,
89+
this.options,
90+
libsqlTx,
91+
);
92+
const tx = new LibSQLTransaction<TFullSchema, TSchema>('async', this.dialect, session, this.schema);
8793
try {
8894
const result = await transaction(tx);
8995
await libsqlTx.commit();

drizzle-orm/src/mysql-core/db.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class MySqlDatabase<
3838

3939
declare readonly _: {
4040
readonly schema: TSchema | undefined;
41+
readonly fullSchema: TFullSchema;
4142
readonly tableNamesMap: Record<string, string>;
4243
};
4344

@@ -56,8 +57,16 @@ export class MySqlDatabase<
5657
protected readonly mode: Mode,
5758
) {
5859
this._ = schema
59-
? { schema: schema.schema, tableNamesMap: schema.tableNamesMap }
60-
: { schema: undefined, tableNamesMap: {} };
60+
? {
61+
schema: schema.schema,
62+
fullSchema: schema.fullSchema as TFullSchema,
63+
tableNamesMap: schema.tableNamesMap,
64+
}
65+
: {
66+
schema: undefined,
67+
fullSchema: {} as TFullSchema,
68+
tableNamesMap: {},
69+
};
6170
this.query = {} as typeof this['query'];
6271
if (this._.schema) {
6372
for (const [tableName, columns] of Object.entries(this._.schema)) {

drizzle-orm/src/mysql2/session.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,14 @@ export class MySql2Session<
219219
config?: MySqlTransactionConfig,
220220
): Promise<T> {
221221
const session = isPool(this.client)
222-
? new MySql2Session(await this.client.getConnection(), this.dialect, this.schema, this.options)
222+
? new MySql2Session(
223+
await this.client.getConnection(),
224+
this.dialect,
225+
this.schema,
226+
this.options,
227+
)
223228
: this;
224-
const tx = new MySql2Transaction(
229+
const tx = new MySql2Transaction<TFullSchema, TSchema>(
225230
this.dialect,
226231
session as MySqlSession<any, any, any, any>,
227232
this.schema,
@@ -261,7 +266,7 @@ export class MySql2Transaction<
261266

262267
override async transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {
263268
const savepointName = `sp${this.nestedIndex + 1}`;
264-
const tx = new MySql2Transaction(
269+
const tx = new MySql2Transaction<TFullSchema, TSchema>(
265270
this.dialect,
266271
this.session,
267272
this.schema,

drizzle-orm/src/neon-serverless/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class NeonSession<
150150
const session = this.client instanceof Pool // eslint-disable-line no-instanceof/no-instanceof
151151
? new NeonSession(await this.client.connect(), this.dialect, this.schema, this.options)
152152
: this;
153-
const tx = new NeonTransaction(this.dialect, session, this.schema);
153+
const tx = new NeonTransaction<TFullSchema, TSchema>(this.dialect, session, this.schema);
154154
await tx.execute(sql`begin ${tx.getTransactionConfigSQL(config)}`);
155155
try {
156156
const result = await transaction(tx);
@@ -175,7 +175,7 @@ export class NeonTransaction<
175175

176176
override async transaction<T>(transaction: (tx: NeonTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {
177177
const savepointName = `sp${this.nestedIndex + 1}`;
178-
const tx = new NeonTransaction(this.dialect, this.session, this.schema, this.nestedIndex + 1);
178+
const tx = new NeonTransaction<TFullSchema, TSchema>(this.dialect, this.session, this.schema, this.nestedIndex + 1);
179179
await tx.execute(sql.raw(`savepoint ${savepointName}`));
180180
try {
181181
const result = await transaction(tx);

drizzle-orm/src/node-postgres/session.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class NodePgSession<
149149
const session = this.client instanceof Pool // eslint-disable-line no-instanceof/no-instanceof
150150
? new NodePgSession(await this.client.connect(), this.dialect, this.schema, this.options)
151151
: this;
152-
const tx = new NodePgTransaction(this.dialect, session, this.schema);
152+
const tx = new NodePgTransaction<TFullSchema, TSchema>(this.dialect, session, this.schema);
153153
await tx.execute(sql`begin${config ? sql` ${tx.getTransactionConfigSQL(config)}` : undefined}`);
154154
try {
155155
const result = await transaction(tx);
@@ -174,7 +174,12 @@ export class NodePgTransaction<
174174

175175
override async transaction<T>(transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {
176176
const savepointName = `sp${this.nestedIndex + 1}`;
177-
const tx = new NodePgTransaction(this.dialect, this.session, this.schema, this.nestedIndex + 1);
177+
const tx = new NodePgTransaction<TFullSchema, TSchema>(
178+
this.dialect,
179+
this.session,
180+
this.schema,
181+
this.nestedIndex + 1,
182+
);
178183
await tx.execute(sql.raw(`savepoint ${savepointName}`));
179184
try {
180185
const result = await transaction(tx);

drizzle-orm/src/pg-core/db.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export class PgDatabase<
3939

4040
declare readonly _: {
4141
readonly schema: TSchema | undefined;
42+
readonly fullSchema: TFullSchema;
4243
readonly tableNamesMap: Record<string, string>;
44+
readonly session: PgSession<TQueryResult, TFullSchema, TSchema>;
4345
};
4446

4547
query: TFullSchema extends Record<string, never>
@@ -56,8 +58,18 @@ export class PgDatabase<
5658
schema: RelationalSchemaConfig<TSchema> | undefined,
5759
) {
5860
this._ = schema
59-
? { schema: schema.schema, tableNamesMap: schema.tableNamesMap }
60-
: { schema: undefined, tableNamesMap: {} };
61+
? {
62+
schema: schema.schema,
63+
fullSchema: schema.fullSchema as TFullSchema,
64+
tableNamesMap: schema.tableNamesMap,
65+
session,
66+
}
67+
: {
68+
schema: undefined,
69+
fullSchema: {} as TFullSchema,
70+
tableNamesMap: {},
71+
session,
72+
};
6173
this.query = {} as typeof this['query'];
6274
if (this._.schema) {
6375
for (const [tableName, columns] of Object.entries(this._.schema)) {

drizzle-orm/src/pglite/session.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class PgliteSession<
133133
this.schema,
134134
this.options,
135135
);
136-
const tx = new PgliteTransaction(this.dialect, session, this.schema);
136+
const tx = new PgliteTransaction<TFullSchema, TSchema>(this.dialect, session, this.schema);
137137
if (config) {
138138
await tx.setTransaction(config);
139139
}
@@ -150,7 +150,12 @@ export class PgliteTransaction<
150150

151151
override async transaction<T>(transaction: (tx: PgliteTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {
152152
const savepointName = `sp${this.nestedIndex + 1}`;
153-
const tx = new PgliteTransaction(this.dialect, this.session, this.schema, this.nestedIndex + 1);
153+
const tx = new PgliteTransaction<TFullSchema, TSchema>(
154+
this.dialect,
155+
this.session,
156+
this.schema,
157+
this.nestedIndex + 1,
158+
);
154159
await tx.execute(sql.raw(`savepoint ${savepointName}`));
155160
try {
156161
const result = await transaction(tx);

0 commit comments

Comments
 (0)