API: insert
Source:
db/insert.ts
Interface used to wrap complex or other specific values for database insertion.
Usage
import { query, update, insert } from "sdk/db";
import { response } from "sdk/http";
update.execute("CREATE TABLE MY_TABLE (COLUMN_A INT)", [], "DefaultDB");
insert.execute("INSERT INTO MY_TABLE VALUES (1)", [], "DefaultDB");
let resultSetBefore = query.execute("SELECT COLUMN_A FROM MY_TABLE", [], "DefaultDB");
response.println("Value before update: " + JSON.stringify(resultSetBefore));
update.execute("UPDATE MY_TABLE SET COLUMN_A = 2", [], "DefaultDB");
let resultSetAfter = query.execute("SELECT COLUMN_A FROM MY_TABLE", [], "DefaultDB");
response.println("Value after update: " + JSON.stringify(resultSetAfter));
update.execute("DROP TABLE MY_TABLE", [], "DefaultDB");Classes
Insert
Provides static methods for executing INSERT SQL statements.
Methods
execute
execute (sql:string, parameters?:ParameterValue[], datasourceName?:string):Array<Record<string,any>>Executes a single parameterized INSERT statement.
* @param sql The SQL query to execute, with '?' placeholders for parameters.
@param parameters An optional array of values to replace the '?' placeholders.
@param datasourceName The name of the database connection to use (optional).
@returns An array of records representing the result of the insertion (e.g., generated keys).
executeMany
executeMany (sql:string, parameters?:ParameterValue[][], datasourceName?:string):Array<Record<string,any>>Executes multiple parameterized INSERT statements as a batch operation.
* @param sql The SQL query to execute, with '?' placeholders for parameters.
@param parameters An optional array of parameter arrays, where each inner array corresponds to one execution of the SQL statement.
@param datasourceName The name of the database connection to use (optional).
@returns An array of records representing the results of the batched insertions.