ormin icon indicating copy to clipboard operation
ormin copied to clipboard

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

Open alaviss opened this issue 5 years ago • 3 comments

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]

alaviss avatar Feb 27 '20 19:02 alaviss

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 = ""

huaxk avatar Feb 28 '20 13:02 huaxk

The result:

id = 0
name = ""

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

alaviss avatar Feb 29 '20 00:02 alaviss

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

huaxk avatar Feb 29 '20 02:02 huaxk