File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -47,4 +47,13 @@ export default class Table {
47
47
async delete ( ) : Promise < void > {
48
48
await this . tablesApiClient . deleteTable ( this . name , this . integration ) ;
49
49
}
50
+
51
+ /**
52
+ * Insert data into this table.
53
+ * @param {string } select - SELECT query to insert data from.
54
+ * @throws {MindsDbError } - Something went wrong inserting data into the table.
55
+ */
56
+ async insert ( select : string ) : Promise < void > {
57
+ await this . tablesApiClient . insertTable ( this . name , this . integration , select ) ;
58
+ }
50
59
}
Original file line number Diff line number Diff line change @@ -41,6 +41,14 @@ export default abstract class TablesApiClient {
41
41
*/
42
42
abstract deleteTable ( name : string , integration : string ) : Promise < void > ;
43
43
44
+ /**
45
+ * Insert data into this table.
46
+ * @param {string } name - Name of the table to be deleted.
47
+ * @param {string } integration - Name of the integration the table to be deleted is a part of.
48
+ * @param {string } select - SELECT query to insert data from.
49
+ * @throws {MindsDbError } - Something went wrong inserting data into the table.
50
+ */
51
+ abstract insertTable ( name : string , integration : string , select : string ) : Promise < void > ;
44
52
/**
45
53
* Deletes a file from the files integration.
46
54
* @param {string } name - Name of the file to be deleted.
Original file line number Diff line number Diff line change @@ -88,6 +88,23 @@ export default class TablesRestApiClient extends TablesApiClient {
88
88
}
89
89
}
90
90
91
+ /**
92
+ * Insert data into this table.
93
+ * @param {Array<Array<any>> | string } data - A 2D array of values to insert, or a SELECT query to insert data from.
94
+ * @throws {MindsDbError } - Something went wrong inserting data into the table.
95
+ */
96
+ override async insertTable ( name : string , integration : string , select : string ) : Promise < void > {
97
+ try {
98
+ const sqlQuery = `INSERT INTO ${ mysql . escapeId ( integration ) } .${ mysql . escapeId ( name ) } (${ select } )` ;
99
+ const sqlQueryResult = await this . sqlClient . runQuery ( sqlQuery ) ;
100
+ if ( sqlQueryResult . error_message ) {
101
+ throw new MindsDbError ( sqlQueryResult . error_message ) ;
102
+ }
103
+ } catch ( error ) {
104
+ throw new MindsDbError ( `Insert into a table failed: ${ error } ` ) ;
105
+ }
106
+ }
107
+
91
108
/**
92
109
* Deletes a file from the files integration.
93
110
* @param {string } name - Name of the file to be deleted.
You can’t perform that action at this time.
0 commit comments