Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape column name #159

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/norm/model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 17 additions & 17 deletions tests/common/tmodel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand Down