tinybase icon indicating copy to clipboard operation
tinybase copied to clipboard

Dynamic queries using store values

Open tallenh opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. Would like to have a way to pass dynamic parameters to a query

Describe the solution you'd like On "where" and possibly "has", along with a getcell function pass along a getvalue function that will return a reactive value from the store. Would allow something like this:

queries.setQueryDefinition("filtered_items", "items", ({ select, where }) => {
  select("name");
  where((getcell, getvalue) => getcell("name").includes(getvalue("filter_string")));
 });

then if you run: store.setValue("filter_string", "test")

would cause the query to update with the new value. Reactive dynamic queries.

tallenh avatar Oct 24 '24 20:10 tallenh

@tallenh Could you do the same thing with a join?

waynesbrain avatar Oct 24 '24 23:10 waynesbrain

Yeah this is a good idea. I think this falls under #47?

jamesgpearce avatar Oct 27 '24 11:10 jamesgpearce

@waynesbrain If you are asking if join should have similar functionality, yes I think that could be useful

@jamesgpearce I am currently doing similar things as #47 and it works well. It is powerful that a listener gets updated if you manually change the query. I am using TinyBase in a hobby Svelte 5 project and it is easy to "refire" the query when some state changes. I was thinking about a framework agnostic way to accomplish something similar.

tallenh avatar Oct 27 '24 16:10 tallenh

Not quite what you asked for, but do check out the release notes for v7.2 beta and see if this will work for you... https://github.com/tinyplex/tinybase/releases/tag/v7.2.0-beta.2

jamesgpearce avatar Dec 11 '25 08:12 jamesgpearce

💥 https://github.com/tinyplex/tinybase/releases/tag/v7.2.0

Note that params are reactive so you can read and listen to them, both directly and with React hooks. Enjoy!

jamesgpearce avatar Dec 12 '25 20:12 jamesgpearce