Insert
Performs a query to insert new data into a table.
Methods
selectDatabase()
→ (database = String) → this
Sets the database for this query.
Parameters
| Parameter | Type | Description |
|---|---|---|
database | String | Name of the database to select. |
Returns
→ this
data()
→ (objects = Array<Object>) → this
Defines the data (rows) to insert.
Parameters
| Parameter | Type | Description |
|---|---|---|
objects | Array<Object> | Array of objects where keys represent column names. All objects must have the same structure. |
Example Usage
.insert()
.data([
{ id: 1, name: "Alice", age: 25 },
{ id: 2, name: "Bob", age: 30 }
])
Returns
→ this
execute()
async → () → OkPacket
Executes the prepared INSERT query.
Returns
→ OkPacket