@@ -3,6 +3,7 @@ import Table from './table';
3
3
import TablesApiClient from './tablesApiClient' ;
4
4
import mysql from 'mysql' ;
5
5
import { MindsDbError } from '../errors' ;
6
+ import path from 'path' ;
6
7
7
8
/** Implementation of TablesApiClient that goes through the REST API */
8
9
export default class TablesRestApiClient extends TablesApiClient {
@@ -87,4 +88,30 @@ export default class TablesRestApiClient extends TablesApiClient {
87
88
throw new MindsDbError ( sqlQueryResult . error_message ) ;
88
89
}
89
90
}
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
+
90
117
}
0 commit comments