File tree Expand file tree Collapse file tree 1 file changed +30
-24
lines changed Expand file tree Collapse file tree 1 file changed +30
-24
lines changed Original file line number Diff line number Diff line change 108108 return bodies ;
109109 }
110110
111- const query = bodies
112- .map (
113- (body ) =>
114- ` INSERT INTO ${table } (${keys ?.join (" , " )}) VALUES ${body .replace (/ \n / g , " \\ n" )} ` ,
115- )
116- .join (" \n " );
117-
118- console .log (query );
119- const res = await fetch (` /api/db/${database }/exec ` , {
120- method: " POST" ,
121- body: JSON .stringify ({ query }),
122- });
111+ const queries = bodies .map (
112+ (body ) => ` INSERT INTO ${table } (${keys ?.join (" , " )}) VALUES ${body } ` ,
113+ );
114+
115+ console .log (queries );
116+ let r: typeof result = undefined ;
117+ for (const query of queries ) {
118+ const res = await fetch (` /api/db/${database }/all ` , {
119+ method: " POST" ,
120+ body: JSON .stringify ({ query }),
121+ });
123122
124- const json = await res .json <any >();
125- if (json ) {
126- if (" error" in json ) {
127- error = json ?.error ?.cause || json ?.error ?.message ;
128- result = undefined ;
123+ const json = await res .json <any >();
124+ if (json ) {
125+ if (" error" in json ) {
126+ error = json ?.error ?.cause || json ?.error ?.message ;
127+ r = undefined ;
128+ } else {
129+ if (r ) {
130+ r .meta .duration += json .meta .duration ;
131+ r .meta .changes += json .meta .changes ;
132+ } else {
133+ r = json ;
134+ }
135+ error = undefined ;
136+ files = undefined ;
137+ keys = undefined ;
138+ casted = undefined ;
139+ }
140+ result = r ;
129141 } else {
130- result = json ;
131- error = undefined ;
132- files = undefined ;
133- keys = undefined ;
134- casted = undefined ;
142+ throw new Error ($t (" plugin.csv.no-result" ));
135143 }
136- } else {
137- throw new Error ($t (" plugin.csv.no-result" ));
138144 }
139145 } finally {
140146 running = false ;
You can’t perform that action at this time.
0 commit comments