From 463368b31df97b322b3f59d02ce875ea09aa5baa Mon Sep 17 00:00:00 2001 From: Crystal Melting Dot Date: Thu, 14 Jul 2022 19:54:56 +0300 Subject: [PATCH 1/5] escape column name --- src/norm/model.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/norm/model.nim b/src/norm/model.nim index 0021e347..9957983d 100644 --- a/src/norm/model.nim +++ b/src/norm/model.nim @@ -44,7 +44,7 @@ func table*(T: typedesc[Model]): string = func col*(T: typedesc[Model], fld: string): string = ## Get column name for a `Model`_ field, which is just the field name. - fld + fld.escape func col*[T: Model](obj: T, fld: string): string = ## Get column name for a `Model`_ instance field. From dd67ee13199d2c853e45f47310823ff452ab8e39 Mon Sep 17 00:00:00 2001 From: Crystal Melting Dot Date: Thu, 14 Jul 2022 22:40:17 +0300 Subject: [PATCH 2/5] not escape, quote --- src/norm/model.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/norm/model.nim b/src/norm/model.nim index 9957983d..b180e8e3 100644 --- a/src/norm/model.nim +++ b/src/norm/model.nim @@ -44,7 +44,7 @@ func table*(T: typedesc[Model]): string = func col*(T: typedesc[Model], fld: string): string = ## Get column name for a `Model`_ field, which is just the field name. - fld.escape + "\"" & fld & "\"" func col*[T: Model](obj: T, fld: string): string = ## Get column name for a `Model`_ instance field. From 363d225a334337b6a05a7af1e8d19a02d84601ea Mon Sep 17 00:00:00 2001 From: Crystal Melting Dot Date: Mon, 18 Jul 2022 21:40:36 +0300 Subject: [PATCH 3/5] test for quoted fields in tmodel --- tests/common/tmodel.nim | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/common/tmodel.nim b/tests/common/tmodel.nim index f72e806f..7b008edd 100644 --- a/tests/common/tmodel.nim +++ b/tests/common/tmodel.nim @@ -16,26 +16,26 @@ suite "Getting table and columns from Model": pet = newPet("cat", toy) person = newPerson("Alice", pet) - check person.col("name") == "name" - check pet.col("species") == "species" + check person.col("name") == "\"name\"" + check pet.col("species") == "\"species\"" - check person.cols == @["name", "pet"] - check person.cols(force = true) == @["name", "pet", "id"] + check person.cols == @["\"name\"", "\"pet\""] + check person.cols(force = true) == @["\"name\"", "\"pet\"", "\"id\""] - check person.fCol("name") == """"Person".name""" - check pet.fCol("species") == """"Pet".species""" + check person.fCol("name") == """"Person"."name"""" + check pet.fCol("species") == """"Pet"."species"""" check person.rfCols == @[ - """"Person".name""", - """"Person".pet""", - """"pet".species""", - """"pet".favToy""", - """"pet_favToy".price""", - """"pet_favToy".id""", - """"pet".id""", - """"Person".id""" + """"Person"."name"""", + """"Person"."pet"""", + """"pet"."species"""", + """"pet"."favToy"""", + """"pet_favToy"."price"""", + """"pet_favToy"."id"""", + """"pet"."id"""", + """"Person"."id"""" ] - check toy.rfCols == @[""""Toy".price""", """"Toy".id"""] + check toy.rfCols == @[""""Toy"."price"""", """"Toy"."id""""] test "Join groups": let @@ -44,8 +44,8 @@ suite "Getting table and columns from Model": person = newPerson("Alice", pet) check person.joinGroups == @[ - (""""Pet"""", """"pet"""", """"Person".pet""", """"pet".id"""), - (""""Toy"""", """"pet_favToy"""", """"pet".favToy""", """"pet_favToy".id""") + (""""Pet"""", """"pet"""", """"Person"."pet"""", """"pet"."id""""), + (""""Toy"""", """"pet_favToy"""", """"pet"."favToy"""", """"pet_favToy"."id"""") ] test "When related model has field with the type of the given model, expect name of that field as a string": From 9c677bc622b4f86de2913fb6d0d03086e59f6a85 Mon Sep 17 00:00:00 2001 From: Crystal Melting Dot Date: Tue, 19 Jul 2022 12:46:10 +0300 Subject: [PATCH 4/5] Add changelog entry and bump version --- changelog.md | 3 +++ norm.nimble | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 9071829d..838b1b9e 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,9 @@ - [t]—test suite improvement - [d]—docs improvement +## 2.5.1 (July 19, 2022) + +- [f] Usage of SQL keywords as field names is now possible by quoting them in the resulting query. ## 2.5.0 (July 8, 2022) diff --git a/norm.nimble b/norm.nimble index 0003c75a..15ac0d33 100755 --- a/norm.nimble +++ b/norm.nimble @@ -1,6 +1,6 @@ # Package -version = "2.5.0" +version = "2.5.1" author = "Constantine Molchanov" description = "Nim ORM for SQLite and PostgreSQL." license = "MIT" From 12cf790d50ef93dd51885c1afa11aff388531a83 Mon Sep 17 00:00:00 2001 From: Crystal Melting Dot Date: Tue, 19 Jul 2022 12:54:11 +0300 Subject: [PATCH 5/5] ok, no version bump, then --- norm.nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/norm.nimble b/norm.nimble index 15ac0d33..0003c75a 100755 --- a/norm.nimble +++ b/norm.nimble @@ -1,6 +1,6 @@ # Package -version = "2.5.1" +version = "2.5.0" author = "Constantine Molchanov" description = "Nim ORM for SQLite and PostgreSQL." license = "MIT"