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

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

Open
alaviss opened this issue Feb 27, 2020 · 3 comments

Comments

@alaviss
Copy link
Contributor

alaviss commented Feb 27, 2020

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
Copy link
Collaborator

huaxk commented Feb 28, 2020

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
Copy link
Contributor Author

alaviss commented Feb 29, 2020

The result:

id = 0
name = ""

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

@huaxk
Copy link
Collaborator

huaxk commented Feb 29, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants