tinybase icon indicating copy to clipboard operation
tinybase copied to clipboard

Parameterized Queries

Open jamesgpearce opened this issue 2 years ago • 1 comments

jamesgpearce avatar Sep 27 '23 14:09 jamesgpearce

@jamesgpearce Hello again, unsolicited and possibly uninformed opinion (and questions) incoming...

I was looking at how queries are implemented today and seeing how they immediately start listening to tables and maintaining results when defined I thought that these queries behave more like how a View might be implemented in an SQL db. I might have misunderstood something here though.

If that is the case, perhaps you would consider renaming queries to views and making a new query system that just runs ad-hoc queries? Passing parameters seems to be the dividing line between adhoc SQL queries and SQL views (which are just a continually running queries that you can't pass parameters to).

Parameters would also certainly be easier to add to an adhoc query system and the API would make more sense too IMO. Currently to create my own parameterized queries I am just creating functions that use store, index, or relationship methods to get the data. While doing this I assume that, if I don't do anything async, that I'm basically working with a stable snapshot of the store. Is that correct? (Thinking more about this - perhaps that is only guaranteed inside of a store.transaction()?)

waynesbrain avatar Sep 06 '24 20:09 waynesbrain

I think parameterized queries are so needed, without them I'm having to write manual awkward data manipulations.

tnspacetime avatar Feb 26 '25 19:02 tnspacetime

First, thanks for making tinybase!

Not having the ability to do parameterized queries has been the roughest edge so far. So much awesome stuff so far but it's been challenging to do some pretty basic queries such as:

  1. what's the sum of column "hours_spent" where "taskListId"=2. I can't dynamically pass in a taskListId. If I wanted to use queries I'd have to manually define a query for every created task list.
  2. get me all rows where "taskListId"=2. I can create a relationship and get the localRowIds, or create an index and get the sliceIds.... But I can't actually get the rows themselves.

Granted I haven't done any synchronization yet (that's next!) but so far this has been my biggest challenge.

It's also a bit of a bummer that the queries aren't typesafe but I can work around that.

willhoney7 avatar May 03 '25 19:05 willhoney7