Modifiers
Modifiers are used to change the format of the response, unlike filters, which operate above the row level.
Filters only return rows that match specific conditions without changing the shape of the rows, while modifiers allow changing the format of the response.
select
By default, .insert() does not return the inserted rows. By calling this method, the inserted rows will be returned in the data.
Warning: The
.select()method returns the inserted rows only when the table has a single primary key and that primary key is of auto-increment type.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| columns | string | No | Columns to retrieve, separated by commas |
Code Example
// Perform an insert operation in the articles table and return the modified full record
const { data, error } = await db
.from("articles")
.insert({ id: 1, title: "Tencent CloudBase New Feature" })
.select();
order
Sort the query results.
This method can be called multiple times to sort by multiple columns.
The referenced table can be sorted, but it will affect the sorting of the parent table only when !inner is used in the query.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| column | string | Yes | Column to sort |
| options | object | No | Named parameters |
options Parameter Details
| Parameter | Type | Required | Description |
|---|---|---|---|
| ascending | boolean | No | If true, the results will be sorted in ascending order |
| nullsFirst | boolean | No | If true, null values will appear first. If false, null values will appear last |
| referencedTable | string | No | Set to sort by the columns of the referenced table |
Code Example
// Sort articles by publication time in descending order
const { data, error } = await db
.from("articles")
.select("id, title, published_at")
.order("published_at", { ascending: false });