INSERT
Add new rows to your tables using SQL INSERT statements.Overview
INSERT INTO adds one or more new rows to a table. Each row must provide values for all NOT NULL columns that do not have a default value.
Basic Syntax
INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3);
Examples
Insert a Single Row
INSERT INTO users (name, email, is_active) VALUES ('Alice', '[email protected]', 1);
Insert Multiple Rows
INSERT INTO tags (name) VALUES ('javascript'), ('typescript'), ('sql');
Insert with Default Values
If a column has a DEFAULT value defined, you can omit it:
INSERT INTO posts (title, content) VALUES ('My First Post', 'Hello world!'); -- created_at and updated_at will use their DEFAULT values
AUTO_INCREMENT
Every Datasquirel table has an id column with AUTO_INCREMENT. You never need to provide the id value on insert — the database assigns the next available integer automatically.
After an INSERT, the new row's id is returned as the insertId in the API response.
Using INSERT via the API
The CRUD POST endpoint handles inserts through a simple object:
const result = await datasquirel.crud.insert({ dbName: "my_database", tableName: "users", body: { name: "Alice", email: "[email protected]", is_active: 1, }, apiKey: process.env.DATASQUIREL_API_KEY, }); console.log(result.payload); // The new row's id
For batch inserts via the API, include a batchData array:
const result = await datasquirel.crud.insert({ dbName: "my_database", tableName: "tags", body: { batchData: [ { name: "javascript" }, { name: "typescript" }, ]}, apiKey: process.env.DATASQUIREL_API_KEY, });