Delete a row
|
Tables with the Data API are currently in public preview. Development is ongoing, and the features and functionality are subject to change. Hyper-Converged Database (HCD), and the use of such, is subject to the DataStax Preview Terms. |
Finds a single row in a table using filter clauses, and then deletes that row.
For general information about working with tables and rows, see About tables with the Data API.
|
Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart. |
Result
-
Python
-
TypeScript
-
Java
-
curl
Deletes a row that matches the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
Does not return anything.
Deletes a row that matches the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
Returns a promise that resolves once the operation completes.
Deletes a row that matches the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
Does not return anything.
Deletes a row that matches the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
Always returns a status.deletedCount of -1, regardless of whether a row was found and deleted.
Example response:
{
"status": {
"deletedCount": -1
}
}
Parameters
-
Python
-
TypeScript
-
Java
-
curl
Use the delete_one method, which belongs to the astrapy.Table class.
Method signature
delete_one(
filter: Dict[str, Any],
*,
general_method_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> None
| Name | Type | Summary |
|---|---|---|
|
|
Describes the full primary key of the row to delete. For this method, the filter can only use the |
|
|
Optional. The maximum time, in milliseconds, that the client should wait for the underlying HTTP request. This parameter is aliased as Default: The default value for the table. This default is 30 seconds unless you specified a different default when you initialized the |
Use the deleteOne method, which belongs to the Table class.
Method signature
async deleteOne(
filter: TableFilter<Schema>,
options?: {
timeout?: number | TimeoutDescriptor,
},
): void
| Name | Type | Summary |
|---|---|---|
|
|
Describes the full primary key of the row to delete. For this method, the filter can only use the |
|
|
Optional. A timeout to impose on the underlying API request. |
Use the deleteOne method, which belongs to the com.datastax.astra.client.tables.Table class.
Method signature
void deleteOne(Filter filter)
void deleteOne(
Filter filter,
TableDeleteOneOptions options
)
| Name | Type | Summary |
|---|---|---|
|
Describes the full primary key of the row to delete. For this method, the filter can only use the |
|
|
General API options for this operation, including the timeout. |
Use the deleteOne command.
Command signature
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"deleteOne": {
"filter": FILTER,
}
}'
| Name | Type | Summary |
|---|---|---|
|
|
Describes the full primary key of the row to delete. For this method, the filter can only use the |
Examples
The following examples demonstrate how to delete a row in a table.
Delete a row by primary key
You can filter by primary key to find and delete a row. The filter must describe the full primary key and cannot include any other columns.
-
Python
-
TypeScript
-
Java
-
curl
from astrapy import DataAPIClient
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment
# Get an existing table
client = DataAPIClient(environment=Environment.HCD)
database = client.get_database(
"API_ENDPOINT",
token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
)
table = database.get_table("TABLE_NAME", keyspace="KEYSPACE_NAME")
# Delete a row
table.delete_one({"title": "Hidden Shadows of the Past", "author": "John Anthony"})
import {
DataAPIClient,
UsernamePasswordTokenProvider,
} from "@datastax/astra-db-ts";
// Get an existing table
const client = new DataAPIClient({ environment: "hcd" });
const database = client.db("API_ENDPOINT", {
token: new UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
});
const table = database.table("TABLE_NAME", {
keyspace: "KEYSPACE_NAME",
});
// Delete a row
(async function () {
const result = await table.deleteOne({
title: "Hidden Shadows of the Past",
author: "John Anthony",
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Map;
public class Example {
public static void main(String[] args) {
// Get an existing table
DataAPIClient client = DataAPIClients.clientHCD("USERNAME", "PASSWORD");
Database database = client.getDatabase("API_ENDPOINT", "KEYSPACE_NAME");
Table<Row> table = database.getTable("TABLE_NAME");
// Delete a row
Filter filter =
new Filter(
Map.of(
"title", "Hidden Shadows of the Past",
"author", "John Anthony"));
table.deleteOne(filter);
}
}
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"deleteOne": {
"filter": {
"title": "Hidden Shadows of the Past",
"author": "John Anthony"
}
}
}'
Client reference
-
Python
-
TypeScript
-
Java
-
curl
For more information, see the client reference.
For more information, see the client reference.
For more information, see the client reference.
Client reference documentation is not applicable for HTTP.