@@ -3,6 +3,7 @@ import Table from './table';
33import TablesApiClient from './tablesApiClient' ;
44import mysql from 'mysql' ;
55import { MindsDbError } from '../errors' ;
6+ import path from 'path' ;
67
78/** Implementation of TablesApiClient that goes through the REST API */
89export default class TablesRestApiClient extends TablesApiClient {
@@ -87,4 +88,30 @@ export default class TablesRestApiClient extends TablesApiClient {
8788 throw new MindsDbError ( sqlQueryResult . error_message ) ;
8889 }
8990 }
91+
92+ /**
93+ * Uploads a file to a specified table in an integration.
94+ * @param {string } filePath - Path to the file to be uploaded.
95+ * @param {string } tableName - Name of the table to upload the file to.
96+ * @param {string } integration - Name of the integration the table is a part of.
97+ * @throws {MindsDbError } - Something went wrong uploading the file.
98+ */
99+ override async uploadFile ( filePath : string , tableName : string , integration : string ) : Promise < void > {
100+ const fileName = path . basename ( filePath ) ;
101+
102+ const sqlQuery = `
103+ LOAD DATA LOCAL INFILE '${ fileName } '
104+ INTO TABLE ${ mysql . escapeId ( integration ) } .${ mysql . escapeId ( tableName ) }
105+ FIELDS TERMINATED BY ','
106+ ENCLOSED BY '"'
107+ LINES TERMINATED BY '\\n'
108+ IGNORE 1 ROWS;
109+ ` ;
110+
111+ const sqlQueryResult = await this . sqlClient . runQuery ( sqlQuery ) ;
112+ if ( sqlQueryResult . error_message ) {
113+ throw new MindsDbError ( sqlQueryResult . error_message ) ;
114+ }
115+ }
116+
90117}
0 commit comments