Skip to content

Commit

Permalink
TypeORM adapter: Don't escape fields
Browse files Browse the repository at this point in the history
There's no need to escape fields with typeorm querybuilder.
Moreover field escaping can cause problems when an entity field name is
different from the database field name.
  • Loading branch information
Claudio Catterina authored and ccatterina committed Aug 26, 2022
1 parent 30759e1 commit 46a6112
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/sql/spec/typeorm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Condition interpreter for TypeORM', () => {

expect(query).to.be.instanceof(SelectQueryBuilder)
expect(query.getQuery()).to.equal([
'SELECT "u"."id" AS "u_id", "u"."name" AS "u_name"',
'SELECT "u"."id" AS "u_id", "u"."name" AS "u_name", "u"."age" AS "u_age"',
'FROM "user" "u"',
'WHERE "u"."name" = :0'
].join(' '))
Expand All @@ -42,7 +42,7 @@ describe('Condition interpreter for TypeORM', () => {
const query = interpret(condition, conn.createQueryBuilder(User, 'u'))

expect(query.getQuery()).to.equal([
'SELECT "u"."id" AS "u_id", "u"."name" AS "u_name"',
'SELECT "u"."id" AS "u_id", "u"."name" AS "u_name", "u"."age" AS "u_age"',
'FROM "user" "u"',
'WHERE "u"."age" in(:0, :1, :2)'
].join(' '))
Expand All @@ -59,7 +59,7 @@ describe('Condition interpreter for TypeORM', () => {
const query = interpret(condition, conn.createQueryBuilder(User, 'u'))

expect(query.getQuery()).to.equal([
'SELECT "u"."id" AS "u_id", "u"."name" AS "u_name"',
'SELECT "u"."id" AS "u_id", "u"."name" AS "u_name", "u"."age" AS "u_age"',
'FROM "user" "u"',
'LEFT JOIN "project" "projects" ON "projects"."userId"="u"."id"',
'WHERE "projects"."name" = :0'
Expand All @@ -75,7 +75,7 @@ describe('Condition interpreter for TypeORM', () => {
const query = interpret(condition, conn.createQueryBuilder(User, 'u'))

expect(query.getQuery()).to.equal([
'SELECT "u"."id" AS "u_id", "u"."name" AS "u_name"',
'SELECT "u"."id" AS "u_id", "u"."name" AS "u_name", "u"."age" AS "u_age"',
'FROM "user" "u"',
'LEFT JOIN "project" "projects" ON "projects"."userId"="u"."id"',
'WHERE ("projects"."name" = :0 and "projects"."active" = :1)'
Expand All @@ -91,7 +91,7 @@ describe('Condition interpreter for TypeORM', () => {
const query = interpret(condition, conn.createQueryBuilder(User, 'u'))

expect(query.getQuery()).to.equal([
'SELECT "u"."id" AS "u_id", "u"."name" AS "u_name"',
'SELECT "u"."id" AS "u_id", "u"."name" AS "u_name", "u"."age" AS "u_age"',
'FROM "user" "u"',
'LEFT JOIN "project" "projects" ON "projects"."userId"="u"."id"',
' LEFT JOIN "review" "projects_reviews" ON "projects_reviews"."projectId"="projects"."id"',
Expand All @@ -105,6 +105,7 @@ async function configureORM() {
class User {
id!: number
name!: string
age!: string
projects!: Project[]
}

Expand All @@ -129,6 +130,7 @@ async function configureORM() {
columns: {
id: { primary: true, type: 'int', generated: true },
name: { type: 'varchar' },
age: { type: 'int' },
},
relations: {
projects: {
Expand Down
1 change: 1 addition & 0 deletions packages/sql/src/lib/typeorm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function foreignField<Entity>(field: string, relationName: string) {
const dialects = createDialects({
joinRelation,
paramPlaceholder: index => `:${index - 1}`,
escapeField: (field: string) => field,
foreignField
});

Expand Down

0 comments on commit 46a6112

Please sign in to comment.