mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +02:00
feat: implement PostgreSQL client for bulk data retrieval to replace per-article HTTP requests
This commit is contained in:
1 parent
5a506c750c
commit
e9e1fdd246
1 file changed
+5
-1
@@ -753,6 +753,10 @@ export interface StockBySite {
|
||||
export async function pgGetStockForCodeins(codeins: string[]): Promise<Map<string, StockBySite>> {
|
||||
if (codeins.length === 0) return new Map();
|
||||
|
||||
// Drizzle expands JS arrays into individual $1,$2,... params regardless of syntax,
|
||||
// hitting PostgreSQL's 1664-entry ROW expression limit. Use sql.raw() with an escaped
|
||||
// literal array instead — codeins come from the DB so single-quote escaping is sufficient.
|
||||
const arrayLiteral = codeins.map(c => `'${String(c).replace(/'/g, "''")}'`).join(",");
|
||||
const result = await pgNoParallel(sql`
|
||||
SELECT
|
||||
a.codein,
|
||||
@@ -760,7 +764,7 @@ export async function pgGetStockForCodeins(codeins: string[]): Promise<Map<strin
|
||||
cs.stockdispo::float AS stockdispo
|
||||
FROM cube_stock cs
|
||||
JOIN articles a ON a.no_id = cs.artnoid
|
||||
WHERE a.codein = ANY(${codeins}::text[])
|
||||
WHERE a.codein = ANY(ARRAY[${sql.raw(arrayLiteral)}])
|
||||
`);
|
||||
|
||||
const map = new Map<string, StockBySite>();
|
||||
|
||||
Reference in new issue
Block a user