Araq / ormin

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

sqlite: confusing error message when select doesn't return for single row queries #44

Open alaviss opened 4 years ago

alaviss commented 4 years ago

Given an empty table created with this schema:

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

This query

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

Returns a confusing error:

queries.nim(890)         test
ormin_sqlite.nim(20)     dbError
Error: unhandled exception: not an error [DbError]
huaxk commented 4 years ago

If the query result set might be empty, you should try tryQuery:

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

The result:

id = 0
name = ""
alaviss commented 4 years ago

The result:

id = 0
name = ""

It'd be a bit more useful to signify if any result has been returned.

huaxk commented 4 years ago

Maybe returning Option(tuple[id: int, name: stirng]) is more reasonable.