Creating
Toggle Example Tables
We will be fictional "world" database in all of our examples.
id | name | iso2 | population_range_millions | main_exports |
---|---|---|---|---|
76 | Brazil | BR | ( 205, 215 ) | [ beans, minerals ] |
156 | China | CN | ( 1380, 1390 ) | [ computers, phones ] |
250 | France | FR | ( 60, 70 ) | [ cars, machines ] |
554 | New Zealand | NZ | ( 4, 6 ) | [ food, machines ] |
556 | Nigeria | NG | ( 185, 195 ) | [ oil, beans ] |
840 | United States | US | ( 320, 330 ) | [ oil, cars, food ] |
name | country_id |
---|---|
Rio de Janeiro | 76 |
Beijing | 156 |
Paris | 250 |
Auckland | 554 |
Lagos | 556 |
Los Angeles | 840 |
San Francisco | 840 |
Create a record
Bulk create
Upsert
Reference
from()
tableName: string
Name of the database table where data will be saved.
insert()
data: { array | object }
A single object
or an array of rows of type object
which contain information to be saved into the selected table.
options: object?
For upsert
, if set to true
, primary key columns would need to be included in the data
parameter in order for an update to properly happen.
Also, primary keys used must be natural, not surrogate.
There are however, workarounds for surrogate primary keys.
Responses
201 Created
Successful
400 Bad request
An invalid syntax or configuration was sent.
401 Unauthorized
Invalid credentials were provided.
404 Not found
Requested resource cannot be found.
406 Not acceptable
The response provided by the server does not match the list of acceptable values stated in the request's headers.
409 Violating foreign key constraint
Raised when you are trying to insert or update into a table with a foreign key which doesn't exist on the target foreign relationship.
500 Internal Server Error
The server was unable to encounter the situation it encountered.