-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
examples/src/main/java/com/datastax/astra/client/tables/DeleteMany.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.datastax.astra.client.tables; | ||
|
||
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.commands.options.TableDeleteManyOptions; | ||
import com.datastax.astra.client.tables.commands.options.TableDeleteOneOptions; | ||
import com.datastax.astra.client.tables.definition.rows.Row; | ||
|
||
import static com.datastax.astra.client.core.query.Filters.and; | ||
import static com.datastax.astra.client.core.query.Filters.eq; | ||
import static com.datastax.astra.client.core.query.Filters.gte; | ||
|
||
public class DeleteMany { | ||
public static void main(String[] args) { | ||
Database db = DataAPIClients.localDbWithDefaultKeyspace(); | ||
// Database astraDb = new DataAPIClient(token).getDatabase(endpoint); | ||
|
||
Table<Row> tableRow = db.getTable("games"); | ||
|
||
// Update | ||
Filter filter = and( | ||
eq("match_id", "fight7"), | ||
eq("round", 2)); | ||
|
||
tableRow.deleteMany(filter); | ||
tableRow.deleteMany(filter, new TableDeleteManyOptions() | ||
.timeout(1000)); | ||
|
||
Filter filter2 = and( | ||
eq("match_id", "fight5"), | ||
gte("round", 5)); | ||
tableRow.deleteMany(filter2); | ||
|
||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
examples/src/main/java/com/datastax/astra/client/tables/DeleteOne.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.datastax.astra.client.tables; | ||
|
||
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.commands.TableUpdateOperation; | ||
import com.datastax.astra.client.tables.commands.options.TableDeleteOneOptions; | ||
import com.datastax.astra.client.tables.commands.options.TableUpdateOneOptions; | ||
import com.datastax.astra.client.tables.definition.rows.Row; | ||
|
||
import java.util.Set; | ||
|
||
import static com.datastax.astra.client.core.query.Filters.and; | ||
import static com.datastax.astra.client.core.query.Filters.eq; | ||
|
||
public class DeleteOne { | ||
public static void main(String[] args) { | ||
Database db = DataAPIClients.localDbWithDefaultKeyspace(); | ||
// Database astraDb = new DataAPIClient(token).getDatabase(endpoint); | ||
|
||
Table<Row> tableRow = db.getTable("games"); | ||
|
||
// Update | ||
Filter filter = and( | ||
eq("match_id", "fight7"), | ||
eq("round", 2)); | ||
|
||
tableRow.deleteOne(filter); | ||
tableRow.deleteOne(filter, new TableDeleteOneOptions() | ||
.timeout(1000)); | ||
|
||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
examples/src/main/java/com/datastax/astra/client/tables/Distinct.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.datastax.astra.client.tables; | ||
|
||
import com.datastax.astra.client.DataAPIClients; | ||
import com.datastax.astra.client.core.query.Filter; | ||
import com.datastax.astra.client.core.query.Sort; | ||
import com.datastax.astra.client.databases.Database; | ||
import com.datastax.astra.client.tables.commands.options.TableFindOptions; | ||
import com.datastax.astra.client.tables.cursor.TableCursor; | ||
import com.datastax.astra.client.tables.definition.rows.Row; | ||
|
||
import java.util.List; | ||
|
||
import static com.datastax.astra.client.core.query.Filters.eq; | ||
import static com.datastax.astra.client.core.query.Projection.include; | ||
|
||
public class Distinct { | ||
public static void main(String[] args) { | ||
Database db = DataAPIClients.localDbWithDefaultKeyspace(); | ||
// Database astraDb = new DataAPIClient(token).getDatabase(endpoint); | ||
|
||
Table<Row> table = db.getTable("games"); | ||
|
||
// Show you all match id in the table | ||
List<Row> matches = table.find(null, new TableFindOptions() | ||
.projection(include("match_id"))).toList(); | ||
matches.forEach(System.out::println); | ||
|
||
// Show you the distinct match id in the table | ||
table.distinct("match_id", null, String.class) | ||
.forEach(System.out::println); | ||
} | ||
} |