Araq / ormin

Ormin -- An ORM for Nim.
MIT License
153 stars 18 forks source link

query doesn't infer single row from selecting unique items #43

Open alaviss opened 4 years ago

alaviss commented 4 years ago

Given a schema like this:

create table user(
  id integer primary key,
  username text unique
)

I'd expect that

let (id, username) =
  query:
    select user(id, username)
    where id == 1

or

let (id, username) =
  query:
    select user(id, username)
    where username == "alaviss"

Would work without limit 1.

The error message is also confusing:

test.nim(6, 5) Error: 'tuple' expected

Took me a moment to realize that it was trying to return a seq.

huaxk commented 4 years ago

You need limit 1, otherwise it will return a seq.

alaviss commented 4 years ago

You need limit 1, otherwise it will return a seq.

I know. The idea is that this should not be needed, as we can clearly see from the schema that there can only be at most one element from this kind of matching.

huaxk commented 4 years ago

Ormin maybe not so smart!

Araq commented 4 years ago

Since Ormin will never be "smart" (it's just software), easier and more predictable rules don't hurt. The limit 1 is fine. However, if you disagree and are willing to implement it, ignore me.