Eusebio Trigo
Eusebio Trigo
Explore posts from servers
XXata
Created by Eusebio Trigo on 4/12/2024 in #help
Cannot perform I/O on behalf of a different request in Cloudflare Workers
We were using it in all our workers. But due to reasons, we stopped all activities, and found other jobs.
10 replies
XXata
Created by Eusebio Trigo on 4/15/2024 in #help
SQL Query working differently in playground vs SDK
Perfect! Thank you!!
5 replies
XXata
Created by Eusebio Trigo on 4/15/2024 in #help
SQL Query working differently in playground vs SDK
Thank you, I'll check it out and will come back to you.
5 replies
XXata
Created by Eusebio Trigo on 4/12/2024 in #help
Cannot perform I/O on behalf of a different request in Cloudflare Workers
Thanks for your help!
10 replies
XXata
Created by Eusebio Trigo on 4/12/2024 in #help
Cannot perform I/O on behalf of a different request in Cloudflare Workers
Yeah, that's my fear. Instead of a Promise.all( - send async requests using fetch -) that would send the requests in parallel, would need to send them using a good-old for loop with IO blocking, and getting each of the requests in sequence.
10 replies
XXata
Created by Eusebio Trigo on 4/12/2024 in #help
Cannot perform I/O on behalf of a different request in Cloudflare Workers
And it happens to us both in a deployed worker and in local development.
10 replies
XXata
Created by Eusebio Trigo on 4/12/2024 in #help
Cannot perform I/O on behalf of a different request in Cloudflare Workers
Yup, I have looked for this issue and it is common, but don't see a "straight answer". I've got queries like
const totals = await dbClient.sql<{ total_orders: number, total_sellers: number }>`
SELECT COUNT(DISTINCT (transactions.order)) AS total_orders,
COUNT(DISTINCT (transactions.shop)) AS total_sellers
FROM transactions
WHERE transactions.report = ${report_id}`;

const subquery = `SELECT DISTINCT (o.id)
FROM transactions t,
orders o
WHERE t.report = '${report_id}'
AND t.order = o.id`;

const total_amounts = await dbClient.sql<{
total_invoiced: number,
total_commission: number;
}>`SELECT SUM(orders.total_price) AS total_invoiced, SUM(orders.total_commission) AS total_commission
FROM orders
WHERE orders.id in (${subquery})`;
const totals = await dbClient.sql<{ total_orders: number, total_sellers: number }>`
SELECT COUNT(DISTINCT (transactions.order)) AS total_orders,
COUNT(DISTINCT (transactions.shop)) AS total_sellers
FROM transactions
WHERE transactions.report = ${report_id}`;

const subquery = `SELECT DISTINCT (o.id)
FROM transactions t,
orders o
WHERE t.report = '${report_id}'
AND t.order = o.id`;

const total_amounts = await dbClient.sql<{
total_invoiced: number,
total_commission: number;
}>`SELECT SUM(orders.total_price) AS total_invoiced, SUM(orders.total_commission) AS total_commission
FROM orders
WHERE orders.id in (${subquery})`;
10 replies
XXata
Created by Eusebio Trigo on 12/11/2023 in #help
Question about types in the Typescript client
Sent! Thanks team!
6 replies
XXata
Created by Eusebio Trigo on 12/11/2023 in #help
Question about types in the Typescript client
Thank you!!
6 replies
XXata
Created by Eusebio Trigo on 11/13/2023 in #help
Running queries with DISTINCT
In our case is of course, to avoid getting duplicated results, given that 2 entities can belong to a single other entity, ...
5 replies
XXata
Created by Eusebio Trigo on 11/13/2023 in #help
Running queries with DISTINCT
Ok, that's a good approach we can follow. Thanks for adding the FR!
5 replies
XXata
Created by Eusebio Trigo on 11/11/2023 in #help
Different results using summarize vs filtering
Like a charm! Thank you!
12 replies
XXata
Created by Eusebio Trigo on 11/11/2023 in #help
Different results using summarize vs filtering
Just tested it in the playground, it displays the 22 iscodes, so i'm happy. Summarize > query and filter
12 replies
XXata
Created by Eusebio Trigo on 11/11/2023 in #help
Different results using summarize vs filtering
Don't be sorry. This was on us. And we are getting there! We got to the why.
12 replies
XXata
Created by Eusebio Trigo on 11/11/2023 in #help
Different results using summarize vs filtering
RTFM > The default setting for size , if not specified in the request, is 20 results. We allow you to set this between 1 and 1000. 😉
12 replies
XXata
Created by Eusebio Trigo on 11/11/2023 in #help
Different results using summarize vs filtering
Thanks! I'll try right now. Doing more tests on other sides. This is why the constraint violation from yesterday.
12 replies
XXata
Created by Eusebio Trigo on 11/11/2023 in #help
Different results using summarize vs filtering
(Apologies, i was hitting the 2k character limit)
12 replies
XXata
Created by Eusebio Trigo on 11/11/2023 in #help
Different results using summarize vs filtering
But using summaries:
import { getXataClient } from "./xata";
const xata = getXataClient();

const envId = "Some Record Id";
const year = 2022;

const summarizeResult = await xata.db.transactions.summarize({
columns: ["order.bill_to_country_iso_code"],
summaries: {},
filter: {
$exists: "order.bill_to_country_iso_code",
credential_id: envId,
accounting_document_creation_date: {
$ge: new Date(`${year}-01-01T00:00:00Z`),
$lt: new Date(`${year + 1}-01-01T00:00:00Z`),
},
},
});
const country_codes = summarizeResult.summaries.map(
(item: any) => item.order.bill_to_country_iso_code
);
console.log("Country Codes", country_codes);
import { getXataClient } from "./xata";
const xata = getXataClient();

const envId = "Some Record Id";
const year = 2022;

const summarizeResult = await xata.db.transactions.summarize({
columns: ["order.bill_to_country_iso_code"],
summaries: {},
filter: {
$exists: "order.bill_to_country_iso_code",
credential_id: envId,
accounting_document_creation_date: {
$ge: new Date(`${year}-01-01T00:00:00Z`),
$lt: new Date(`${year + 1}-01-01T00:00:00Z`),
},
},
});
const country_codes = summarizeResult.summaries.map(
(item: any) => item.order.bill_to_country_iso_code
);
console.log("Country Codes", country_codes);
12 replies
XXata
Created by Eusebio Trigo on 11/11/2023 in #help
Different results using summarize vs filtering
import { getXataClient } from "./xata";
import { ge, le } from "@xata.io/client";

const xata = getXataClient();

const records = await xata.db.transactions
.filter(
"accounting_document_creation_date",
ge(new Date("2022-01-01T00:00:00.000Z"))
)
.filter(
"accounting_document_creation_date",
le(new Date("2023-01-01T00:00:00.000Z"))
)
.filter(
"credential_id", "Some record Id"
)
.sort("order.bill_to_country_iso_code", "asc")
.select([
"order.bill_to_country_iso_code",
])
.getAll();

console.log(records.map(record => record.order.bill_to_country_iso_code).filter((value, index, array) => array.indexOf(value) === index));
import { getXataClient } from "./xata";
import { ge, le } from "@xata.io/client";

const xata = getXataClient();

const records = await xata.db.transactions
.filter(
"accounting_document_creation_date",
ge(new Date("2022-01-01T00:00:00.000Z"))
)
.filter(
"accounting_document_creation_date",
le(new Date("2023-01-01T00:00:00.000Z"))
)
.filter(
"credential_id", "Some record Id"
)
.sort("order.bill_to_country_iso_code", "asc")
.select([
"order.bill_to_country_iso_code",
])
.getAll();

console.log(records.map(record => record.order.bill_to_country_iso_code).filter((value, index, array) => array.indexOf(value) === index));
Displays (with our current case 22 results).
12 replies
XXata
Created by Eusebio Trigo on 11/10/2023 in #help
Diagnosing Constraint Violation
TBH, I like the way it is now, very object oriented. Me likes it.
22 replies