Parameterized Queries #47
Replies: 7 comments 1 reply
-
|
It would be nice if the queries automatically updated whenever the parameters change, as I'm currently doing something like this: |
Beta Was this translation helpful? Give feedback.
-
|
Parameterized queries is incredibly common and I haven't been able to create a good pattern around this. For the sake of feedback here is what I'm currently doing. const getNodePropertiesByNameQuery = (nodeId: string, name: string) => {
const queryName = `node:${nodeId}.${name}.properties`;
const nextQueries = queries.setQueryDefinition(
queryName,
"properties",
({ select, where }) => {
select("id");
select("nodeId");
select("name");
select("type");
select("createdAt");
select("updatedAt");
select("order");
select("string");
select("number");
select("boolean");
where("name", name);
where("nodeId", nodeId);
}
);
return {
name: queryName,
queries: nextQueries,
};
};
const getNodeProperty = (nodeId: string, name: string) => {
const { name: queryName, queries: nextQueries } =
getNodePropertiesByNameQuery(nodeId, name);
const resultTable = nextQueries.getResultTable(queryName);
const id = Object.keys(resultTable)[0];
return resultTable[id] as Property;
};If there is something terribly wrong or if there is a better pattern here I would love to hear it! |
Beta Was this translation helpful? Give feedback.
-
|
I am treating queries like I would treat an SQL For an SQL view I would avoid redefining it while users were selecting from it. Here in #180 in the [1] Also mentioned here |
Beta Was this translation helpful? Give feedback.
-
|
:) |
Beta Was this translation helpful? Give feedback.
-
|
I've struggled a lot with this as well but on my react native app, ended up using hooks. |
Beta Was this translation helpful? Give feedback.
-
|
OK, here we go! Please check out the new beta release and see if this is going to get you all what you want. https://github.com/tinyplex/tinybase/releases/tag/v7.2.0-beta.2 @dylmye I had missed your comment and it made me sad this week :( - so I hustled! If you're still interested, please kick the tires. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, when building up UIs that are bound to TinyBase we'll often create individual query definitions for individual items to grab the data we need. For example:
This ends up being set up in a loop for each
itemIdin a list. It would be really nice if instead we had some way to set up the query definition once but then invoke it with theitemIdthat we care about. @jamesgpearce you had mentioned you've done some prior thinking about this so I was wondering if you had any potential APIs in mind. If not, I can definitely propose some from the perspective of a user consuming this functionalityBeta Was this translation helpful? Give feedback.
All reactions