Open greatlord opened 4 years ago
This looks really interesting. Unfortunately I don't have time to work on it right away, but this is definitely the kind of database-specific functionality that Chain was designed to support.
THanks you think it is interesting. I hope you got time to implement it some day. At moment I got it working with the code above :)
I was force find a way to upload big datarecords to postgrsql Frist I use Torgar buil insert for it. It was faster way doing it.
After a while I exaime if it does not exists anything better yes it does. PostgrSql accpect jsondata as in parms and you can popluate it to a recordsset now I manger incresss the PostgrSql speed alot more.
I am doing like this now productsProcessed = dataSource.TableFunction("public.importproducts", new { productsjson = productJson, categoriesjson = categoriesJson }).ToCollection().Execute();
now I got advacne sql function CREATE OR REPLACE FUNCTION public.importproducts(productsjson json, categoriesjson json) RETURNS TABLE(idproduct bigint, artno character varying, condition boolean, instock boolean, weight double precision, bookisbn character varying, sku character varying, eanorupc character varying, productname character varying, description character varying, stockqty bigint, imageurl character varying, producturl character varying, storeurl character varying, arycategory character varying[], price real, priceoriginal real, shippingcosts real, isnew boolean) LANGUAGE plpgsql AS $function$ BEGIN --INSERT NEW PRODUCT CATEGORIES INSERT INTO category(idlanguages, categoryname) SELECT DISTINCT cjson.idlanguages, cjson.categoryname FROM json_populate_recordset(null::productcategory_csv_row, categoriesjson) AS cjson --LEFT JOIN category C1 ON C1.idlanguages = C.idlanguages AND C1.categoryname = C.parentname WHERE NOT EXISTS(SELECT 1 FROM category cexisting WHERE cexisting.idlanguages = cjson.idlanguages AND cexisting.categoryname = cjson.categoryname);
END;$function$ ;
the custom recrods set struct is call productcategory_csv_row so we create it
create TYPE product_csv_row AS (idstore bigint, storeproductid character varying(255),
sku character varying, eanorupc character varying, bookisbn character varying, producturl character varying, imageurl character varying, artno character varying, idlanguages bigint, productname character varying, description character varying, idcurrency bigint, stockstatus bigint, pricewithtax real, shippingcosts real, categoryname character varying(128), categorydesc character varying, parentid bigint, image_url character varying, arycategory character varying(128) [], storeurl character varying);
create TYPE productcategory_csv_row AS (idstore bigint, storeproductid character varying(255),
idlanguages bigint, categoryname character varying(128), parentname character varying(128));
now I can upload whole recordset with json instead for doing bulik insert to one table at time :) I hope you can create a api to create custom row and doing json insert :)