Delete a row (Go)
Finds a single row in a table using filter clauses, and then deletes that row.
Deleting rows produces tombstones. Excessive tombstones can impact query performance.
For general information about working with tables and rows, see About tables with the Data API (Go).
|
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
Deletes a row that matches the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
A successful operation does not return anything.
Parameters
Use the DeleteOne method, which belongs to the Table type.
Method signature
func (t *Table) DeleteOne(
ctx context.Context,
f TableFilter,
opts ...options.TableDeleteOneOption
) error
| Name | Type | Summary |
|---|---|---|
|
|
The context for the operation. |
|
Describes the full primary key of the row to delete. For this method, the filter can only use the |
|
|
Optional.
A builder to generate options for this operation.
See Methods of the |
| Method | Summary |
|---|---|
|
Optional. General API options for this operation, including the timeout. |
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.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/filter"
"github.com/datastax/astra-db-go/v2/astra/options"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient(
options.API().SetEnvironment(options.EnvironmentHCD),
)
database := client.Database(
"API_ENDPOINT",
options.API().
SetUsernamePasswordTokenProvider(
"USERNAME",
"PASSWORD",
).
SetKeyspace("KEYSPACE_NAME"),
)
table := database.Table("TABLE_NAME")
// Delete a row
err := table.DeleteOne(
ctx,
filter.And(
filter.Eq("title", "Hidden Shadows of the Past"),
filter.Eq("author", "John Anthony"),
),
)
if err != nil {
log.Fatal(err)
}
}
Client reference
For more information, see the client reference.