NestarZ
NestarZ
Explore posts from servers
KKysely
Created by NestarZ on 6/12/2024 in #help
Is it possible to do "for await (const iterator of db.selectFrom("table").selectAll()) {....}
Can I execute as an async generator like in a cursor ?
7 replies
KKysely
Created by NestarZ on 2/29/2024 in #help
How to loop an array and based on this create a dynamic CTE but preserve type ?
for (const [references, columns] of referencesArray) {
const newQb = qb.with(`cte_${references}`, (wb) => {
wb = wb.selectFrom(references).distinct().selectAll(references);
for (const column of columns) {
wb = wb.innerJoin(
tableName,
sql.ref(`${tableName}.${column.name}`),
sql.ref(`${column.references}.${column.to}`)
);
}
return wb;
});
qb = newQb as any;
}
for (const [references, columns] of referencesArray) {
const newQb = qb.with(`cte_${references}`, (wb) => {
wb = wb.selectFrom(references).distinct().selectAll(references);
for (const column of columns) {
wb = wb.innerJoin(
tableName,
sql.ref(`${tableName}.${column.name}`),
sql.ref(`${column.references}.${column.to}`)
);
}
return wb;
});
qb = newQb as any;
}
But this is not optimal
7 replies