How to use trpc query if input data is not available at mount? - trpc.io

I have a component with a list of conversations and i want to load a specific conversation on click. The problem is that I have to initialise the second trpc query at mount and I dont have the required data yet. Any help would be highly apriciated.

You need to use the enabled flag of useQuery:
const requiredDataIsAvailable = false
trpc.useQuery(['todos'], {
// query will only fetch data if the following variable evaluates to true
enabled: requiredDataIsAvailable,
})
Only if enabled is true (= you got the required data for the query), it will fetch the data from the server.
Docs:
https://tanstack.com/query/v4/docs/guides/disabling-queries
https://trpc.io/docs/react-queries

Related

How can i check that demo data is loaded or not in a database by code

How can i check that demo data is loaded or not in a database from python code.I know other ways to check , but i need to check it by code.
I think the easiest way to do is by checking if the XML-ID is loaded :
# checking if the demo user record exist in database
# don't forget the put the full qualifying XML-ID (addon_name.xml_id)
if not self.env.ref('base.user_demo', raise_if_not_found=False):
# demo user is not loaded in database
Odoo maps the XML-ID with the real ID in database using this model ir.model.data if the record is loaded ref will return the record from the database else it will raise an exception or return None based on the second argument raise_if_not_found by default it's True

Infinite list using websql proxy store

Is there support for an infinite list backed by the websql proxy? It doesn't seem so, as whether infinite is true or false, there are only 25 items in the list.
You should use ListPaging plugin in the list.
{
xclass: 'Ext.plugin.ListPaging',
autoPaging: true,
loadMoreText : 'Loading more',
noMoreRecordsText : 'loaded'
}
Please check sencha touch documentation for further info.
I was able to get this to work by modifying the Sql proxy to include total record count. More specifically, in the selectRecords method I had to change the code:
result.setTotal(count);
to a second executeSql call that queries all records. The sql statement is similar to the original one, except that (1) it does not include the LIMIT expression; and (2) the SELECT * should be SELECT COUNT(*) AS TotalCount. Then read TotalCount value from the first row of the result set, call result.setTotal(totalCount), and finally fire the callback.

Forward only a single group using the WirePattern helper when config.group is true

I'm trying to use the WirePattern helper to perform some synchronisation within my graph. I'm setting config.group to true so I can ensure that only packets received with the same group are collected and handled within this component.
For the sake of argument, here is an example packet from the first in-port:
<my-group>
123
</my-group>
And the second in-port:
<my-group>
456
</my-group>
Because config.group is set to true, these 2 packets will match by group and I can do something with them in my component. So far so good.
The problem lies in that I want to wrap the output with the same group that the 2 in-ports were matched by. This is what the out packet group should look like:
<my-group>
123456
</my-group>
I assumed config.group would do this by default but it doesn't, it just sends the output with no group:
123456
I tried setting config.forwardGroups to various values in an effort to forward the group from only one of the in-ports (seeing as they're identical). Regardless of whether this is set to true, "portname" or ["portname"], it double-wraps the out packet:
<my-group>
<my-group>
123456
</my-group>
</my-group>
This causes headaches further down the line as the grouping has changed and no longer matches up with the other components. I could manually remove one of the groups using another component, but I shouldn't have to do that.
How can I set up the WirePattern to continue matching by group (using config.group) but only forward a single group to the out port?
I don't mind doing it manually for now if this is something that the WirePattern doesn't support. I just need to know whether I'm doing something wrong, or whether it's just not possible in NoFlo yet.
Here's my config for reference:
var config = {
in: ["in", "value"],
params: ["property"],
out: "out",
// This doesn't forward the group
group: true, // Wait for packets of same group
// This duplicates groups when group: true
forwardGroups: ["value"],
arrayPolicy: {
in: "all", // Wait for all indexes
params: "all" // Wait for all indexes
}
};
This looks like a bug to me as I remember enforcing group uniqueness upon forwarding. I've opened https://github.com/noflo/noflo/issues/269 and will fix it by next NoFlo release.
For now, another workaround would be: don't use forwardGroups feature but rather send groups manually to the output inside the process handler (which is absolutely legal when using WirePattern too):
out.beginGroup(groups[0]);
out.send(input.in + input.value);
out.endGroup();

knex.js - debug only SQL

Is there any way to display only SQL queries on console when debugging mode is on?
I want to reduce the amount of informations which is displayed.
Thanks for the help ;)
Set environment variables to configure the debug module:
DEBUG=knex:query for just queries
DEBUG=knex:tx for transactions
and DEBUG=knex* for everything.
If what you need is to show the query string, one way is to register a function that logs the query data using the event 'query' that Knex emit just before executing the query.
For example:
var knex = require( 'knex' );
knex.on( 'query', function( queryData ) {
console.log( queryData );
});
After that, before every query, the anonymous function is called and queryData contains json with the information about the query.
Actually, if you're using MySQL, you can set
debug: ['ComQueryPacket']
as part of the config settings for mysql (not Knex).
I'll looking into adding this as an option in Knex though.

grid filter in dojo

can any one help with filtering multiple condition in dojo grid.
im using grid.DataGrid and json data.
data1 = {items: [ {"id":1,"media":"PRINT",pt:"Yellow Directory"},
{"id":2,"media":"DIGITAL",pt:"Social Media"},{id":3,"media":"DIGITAL",pt:"Yellow Online"}
],identifier: "id"};
a=1,b=2;
grid.filter({id:a,id:b})
the above line is just displaying the record with b value.
i need the record with both the values.
can any one help me with this.???
So you want the records that have any of the specified ids?
It comes down to the capabilities of the store you're using. If you're using a Memory store with SimpleQueryEngine, then you can specify a regex or an object with a test function instead:
grid.filter({id: {
test: function(x) {
return x === 'a' || x === 'b';
}
}});
If you're using JsonRest store, then you get to choose how your queries are processed server-side so you could potentially pass in an array of interesting values and handle that in your own way on the server. (i.e. filter({id:[a,b]}))