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/src/norm/model.nim b/src/norm/model.nim index 0021e347..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 + "\"" & fld & "\"" func col*[T: Model](obj: T, fld: string): string = ## Get column name for a `Model`_ instance field. 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":