Araq / ormin

Ormin -- An ORM for Nim.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

query doesn't infer single row from selecting unique items

alaviss opened this issue · comments

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.

commented

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

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.

commented

Ormin maybe not so smart!

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.