Skip to content

Commit

Permalink
Fixed lack of schema name on columns in sql (#3531)
Browse files Browse the repository at this point in the history
* Beta (#3503)

* Fix breakpoints option default value

* fix: added commonly used columns to supabase auth.users table schema

* imports checker with OHM grammar

* imports checker with OHM grammar + fix of imports issues

* Formatting fix

* [MySQL] Add unsigned floating point types + Fix unsigned integer type bugs in Kit (#3284)

* Fix bugs with MySQL introspection tests

* Update float data type in MySQL

* Better support for float types in MySQL

* Handle existing unsigned numerical types in MySQL

* Add unsigned to floating point types in MySQL

* Handle unsigned floating point types in MySQL

* Update decimal data type

---------

Co-authored-by: Andrii Sherman <andreysherman11@gmail.com>

* Batch of bugfixes for ORM (#3181)

* (MySQL) Fix placeholder type error in offset and limit

* Add prepared statement tests

* Add PG test

* Fix blob parsing in bun sqlite driver

* Lint and format

* Fix file

* Fix tests

* Use const instead of let in tests

* Format

---------

Co-authored-by: Andrii Sherman <andreysherman11@gmail.com>

* main to beta (#3404)

* Update Github issue templates (#3157)

* Update GH issue templates

* Update issue templates

---------

Co-authored-by: Andrii Sherman <andreysherman11@gmail.com>

* Fix checkboxes

---------

Co-authored-by: L-Mario564 <ka.mario564@gmail.com>

* feat: add tablesFilter to pushSchema api (#3141)

* feat: add tablesFilter to pushSchema api

* Format with dprint

---------

Co-authored-by: Andrii Sherman <andreysherman11@gmail.com>

* Batch of bugfixes for Kit (#2959)

* Escape single quote in enum value

* Escape single quotes in string default values

* Handle instrospection of strings with single quotes

* Add tests

* Add tests

* Uncomment tests

* Fix SQL statement order in MySQL

* Add MySQL test

* Fix alter composite PK statement missing quotes in PG

* Add tests

* Handle SQL expressions in timestamp, date and time in PG

* Use `.run` instead of `.query` in SQLite queries that don't return anything

* Fix parsing of enum array types in PG

* Generate more PG index operators

* Fix primary key recreate on table rename

* Format

* Format

* Update test

* Format

* Fix tests

* Fix terminal output mistake

* Remove duplicate import

---------

Co-authored-by: Andrii Sherman <andreysherman11@gmail.com>

* Bump versions

---------

Co-authored-by: Steffen <3752127+klotztech@users.noreply.github.com>
Co-authored-by: Nicholas Ly <hello@nicholasly.com>
Co-authored-by: Alex Blokh <aleksandrblokh@gmail.com>
Co-authored-by: Sukairo-02 <sreka9056@gmail.com>
Co-authored-by: L-Mario564 <ka.mario564@gmail.com>
Co-authored-by: Dan Ribbens <DanRibbens@users.noreply.github.com>

* Dprint

* Fixed `sql` omitting schema names when processing columns, fixed related test cases

* Fixed dprint formatting issues

* Fixed lack of schema name on integration tests column references

* Removed `\!`

---------

Co-authored-by: Andrii Sherman <andreysherman11@gmail.com>
Co-authored-by: Steffen <3752127+klotztech@users.noreply.github.com>
Co-authored-by: Nicholas Ly <hello@nicholasly.com>
Co-authored-by: Alex Blokh <aleksandrblokh@gmail.com>
Co-authored-by: L-Mario564 <ka.mario564@gmail.com>
Co-authored-by: Dan Ribbens <DanRibbens@users.noreply.github.com>
  • Loading branch information
7 people authored Nov 12, 2024
1 parent b2f9606 commit 87b2c2c
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion drizzle-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@
"default": "./api.mjs"
}
}
}
}
2 changes: 1 addition & 1 deletion drizzle-orm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,4 @@
"zod": "^3.20.2",
"zx": "^7.2.2"
}
}
}
12 changes: 10 additions & 2 deletions drizzle-orm/src/sql/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { tracer } from '~/tracing.ts';
import { ViewBaseConfig } from '~/view-common.ts';
import type { AnyColumn } from '../column.ts';
import { Column } from '../column.ts';
import { Table } from '../table.ts';
import { IsAlias, Table } from '../table.ts';

/**
* This class is used to indicate a primitive param value that is used in `sql` tag.
Expand Down Expand Up @@ -192,7 +192,15 @@ export class SQL<T = unknown> implements SQLWrapper {
if (_config.invokeSource === 'indexes') {
return { sql: escapeName(columnName), params: [] };
}
return { sql: escapeName(chunk.table[Table.Symbol.Name]) + '.' + escapeName(columnName), params: [] };

const schemaName = chunk.table[Table.Symbol.Schema];
return {
sql: chunk.table[IsAlias] || schemaName === undefined
? escapeName(chunk.table[Table.Symbol.Name]) + '.' + escapeName(columnName)
: escapeName(schemaName) + '.' + escapeName(chunk.table[Table.Symbol.Name]) + '.'
+ escapeName(columnName),
params: [],
};
}

if (is(chunk, View)) {
Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/tests/casing/mysql-to-camel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('mysql to snake case', () => {

expect(query.toSQL()).toEqual({
sql:
"select `users`.`firstName` || ' ' || `users`.`lastName` as `name`, `users`.`AGE` from `users` left join `test`.`developers` on `users`.`id` = `developers`.`userId` order by `users`.`firstName` asc",
"select `users`.`firstName` || ' ' || `users`.`lastName` as `name`, `users`.`AGE` from `users` left join `test`.`developers` on `users`.`id` = `test`.`developers`.`userId` order by `users`.`firstName` asc",
params: [],
});
expect(db.dialect.casing.cache).toEqual(cache);
Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/tests/casing/mysql-to-snake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('mysql to snake case', () => {

expect(query.toSQL()).toEqual({
sql:
"select `users`.`first_name` || ' ' || `users`.`last_name` as `name`, `users`.`AGE` from `users` left join `test`.`developers` on `users`.`id` = `developers`.`user_id` order by `users`.`first_name` asc",
"select `users`.`first_name` || ' ' || `users`.`last_name` as `name`, `users`.`AGE` from `users` left join `test`.`developers` on `users`.`id` = `test`.`developers`.`user_id` order by `users`.`first_name` asc",
params: [],
});
expect(db.dialect.casing.cache).toEqual(cache);
Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/tests/casing/pg-to-camel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('postgres to camel case', () => {

expect(query.toSQL()).toEqual({
sql:
'select "users"."firstName" || \' \' || "users"."lastName" as "name", "users"."AGE" from "users" left join "test"."developers" on "users"."id" = "developers"."userId" order by "users"."firstName" asc',
'select "users"."firstName" || \' \' || "users"."lastName" as "name", "users"."AGE" from "users" left join "test"."developers" on "users"."id" = "test"."developers"."userId" order by "users"."firstName" asc',
params: [],
});
expect(db.dialect.casing.cache).toEqual(cache);
Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/tests/casing/pg-to-snake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('postgres to snake case', () => {

expect(query.toSQL()).toEqual({
sql:
'select "users"."first_name" || \' \' || "users"."last_name" as "name", "users"."AGE" from "users" left join "test"."developers" on "users"."id" = "developers"."user_id" order by "users"."first_name" asc',
'select "users"."first_name" || \' \' || "users"."last_name" as "name", "users"."AGE" from "users" left join "test"."developers" on "users"."id" = "test"."developers"."user_id" order by "users"."first_name" asc',
params: [],
});
expect(db.dialect.casing.cache).toEqual(cache);
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/mysql/mysql-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3416,7 +3416,7 @@ export function tests(driver?: string) {

expect(query).toEqual({
sql:
`select \`id\`, \`name\` from \`mySchema\`.\`userstest\` group by \`userstest\`.\`id\`, \`userstest\`.\`name\``,
`select \`id\`, \`name\` from \`mySchema\`.\`userstest\` group by \`mySchema\`.\`userstest\`.\`id\`, \`mySchema\`.\`userstest\`.\`name\``,
params: [],
});
});
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/pg/pg-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4278,7 +4278,7 @@ export function tests() {
.toSQL();

expect(query).toEqual({
sql: 'select "id", "name" from "mySchema"."users" group by "users"."id", "users"."name"',
sql: 'select "id", "name" from "mySchema"."users" group by "mySchema"."users"."id", "mySchema"."users"."name"',
params: [],
});
});
Expand Down

0 comments on commit 87b2c2c

Please sign in to comment.