MCPcopy Index your code
hub / github.com/outerbase/studio / exportTableData

Function exportTableData

src/lib/export-helper.ts:250–292  ·  view source on GitHub ↗
(
  databaseDriver: any,
  schemaName: string,
  tableName: string,
  format: ExportFormat,
  exportTarget: ExportTarget,
  options?: ExportOptions
)

Source from the content-addressed store, hash-verified

248}
249
250export async function exportTableData(
251 databaseDriver: any,
252 schemaName: string,
253 tableName: string,
254 format: ExportFormat,
255 exportTarget: ExportTarget,
256 options?: ExportOptions
257): Promise<string | Blob> {
258 console.log("Exporting", schemaName, tableName, format, exportTarget, options);
259 const result = await databaseDriver.query(
260 `SELECT * FROM ${databaseDriver.escapeId(schemaName)}.${databaseDriver.escapeId(tableName)}`
261 );
262 console.log("QueryResults", result);
263 if (!result.rows || result.rows.length === 0) {
264 return "";
265 }
266
267 const headers = Object.keys(result.rows[0]);
268 const records = result.rows.map((row: { [x: string]: string; }) => headers.map(header => row[header]));
269
270 const formatHandlers = {
271 csv: () => exportDataAsDelimitedText(headers, records, ",", "\n", '"', exportTarget),
272 json: () => exportRowsToJson(headers, records, exportTarget),
273 sql: () => exportRowsToSqlInsert(tableName, headers, records, exportTarget),
274 xlsx: () => exportToExcel(records, headers, tableName, exportTarget),
275 delimited: () =>
276 exportDataAsDelimitedText(
277 headers,
278 records,
279 options?.fieldSeparator || ",",
280 options?.lineTerminator || "\n",
281 options?.encloser || '"',
282 exportTarget
283 ),
284 };
285
286 const handler = formatHandlers[format];
287 if (handler) {
288 return handler();
289 } else {
290 throw new Error(`Unsupported export format: ${format}`);
291 }
292}
293// TODO: maybe we should move export related types here
294export type { ExportFormat };

Callers 1

SchemaListFunction · 0.90

Calls 7

exportRowsToJsonFunction · 0.85
exportRowsToSqlInsertFunction · 0.85
exportToExcelFunction · 0.85
handlerFunction · 0.85
queryMethod · 0.65
escapeIdMethod · 0.45

Tested by

no test coverage detected