meteor / postgres-packages

Early preview of PostgreSQL support for Meteor (deprecated, here for historical reasons)
http://meteor-postgres.readthedocs.org/
158 stars 25 forks source link

New query operators to support in the client-side Knex #7

Open stubailo opened 8 years ago

stubailo commented 8 years ago

Here's an initial list:

rclai commented 8 years ago

Do you guys think you can create a helper query function that does ...myQuery.fetch()[0].field in a safe way? As I'm looking at the React Todos example, I'm seeing that call here and there, which can be potentially error-throwing if an empty array is returned.

Perhaps something that wraps (...myQuery.fetch()[0] || {}).field, assuming that .fetch() always returns an array even if it's empty?

Edit: I noticed that Bookshelf has a fetchOne, which could work, however, since SQL gives you the ability to just give you one value that is 'columnless', like a COUNT query, perhaps something that does .fetchValue() or something like that, i.e. Lists.select('incomplete_todos').where({ id:1 }).fetchValue()?

stubailo commented 8 years ago

Isn't this something that could also be useful for Mongo? Like, Todos.findOne().field will also throw an error.

I guess this is one place where the CoffeeScript ?. comes in super handy.

I think this would be a great thing to open a new issue for, since it's not technically related to filling in parts of existing Knex syntax.

rclai commented 8 years ago

Yeah, it would be helpful for Mongo too. I find myself writing a lot of (Todos.findOne() || {}).field or singleTodo && singleTodo.field, which is so annoying.

rclai commented 8 years ago

I moved it to #9.