File tree Expand file tree Collapse file tree 5 files changed +109
-0
lines changed
astra-db-client/src/test/java/com/dtsx/astra/sdk/documentation Expand file tree Collapse file tree 5 files changed +109
-0
lines changed Original file line number Diff line number Diff line change 11package com .dtsx .astra .sdk .documentation ;
22
3+ import com .dtsx .astra .sdk .AstraDB ;
4+ import com .dtsx .astra .sdk .AstraDBCollection ;
5+
36public class ClearCollection {
7+ public static void main (String [] args ) {
8+
9+ // Accessing existing DB
10+ AstraDB db = new AstraDB ("<token>" , "<api_endpoint>" );
11+
12+ // Access existing collection
13+ AstraDBCollection collection = db .createCollection ("collection_vector1" , 14 );
14+
15+ // Clear collection
16+ collection .deleteAll ();
17+
18+ }
419}
Original file line number Diff line number Diff line change 11package com .dtsx .astra .sdk .documentation ;
22
3+ import com .dtsx .astra .sdk .AstraDB ;
4+ import com .dtsx .astra .sdk .AstraDBAdmin ;
5+ import com .dtsx .astra .sdk .AstraDBCollection ;
6+ import io .stargate .sdk .json .domain .DeleteQuery ;
7+
38public class DeleteMany {
9+ public static void main (String [] args ) {
10+
11+ // Given an active db and a collection with a vector field (see CreateCollection.java)
12+ AstraDB db = new AstraDB ("<token>" , "<api_endpoint>" );
13+
14+ // Create collection if not exists
15+ AstraDBCollection collection = db
16+ .createCollection ("collection_vector1" ,14 );
17+
18+ // Delete item based on a query
19+ int deletedCount = collection
20+ .deleteMany (DeleteQuery .builder ()
21+ .where ("product_price" ).isEqualsTo (9.99 )
22+ .build ());
23+ }
424}
Original file line number Diff line number Diff line change 11package com .dtsx .astra .sdk .documentation ;
22
3+ import com .dtsx .astra .sdk .AstraDB ;
4+ import com .dtsx .astra .sdk .AstraDBCollection ;
5+ import io .stargate .sdk .json .domain .DeleteQuery ;
6+
37public class DeleteOne {
8+ public static void main (String [] args ) {
9+
10+ // Given an active db and a collection with a vector field (see CreateCollection.java)
11+ AstraDB db = new AstraDB ("<token>" , "<api_endpoint>" );
12+
13+ // Create collection if not exists
14+ AstraDBCollection collection = db
15+ .createCollection ("collection_vector1" ,14 );
16+
17+ // Delete item based on a query
18+ int deletedCount = collection .deleteOne (DeleteQuery .deleteById ("id1" ));
19+ }
420}
Original file line number Diff line number Diff line change 11package com .dtsx .astra .sdk .documentation ;
22
3+ import com .dtsx .astra .sdk .AstraDB ;
4+ import com .dtsx .astra .sdk .AstraDBCollection ;
5+ import com .dtsx .astra .sdk .AstraDBRepository ;
6+ import com .fasterxml .jackson .annotation .JsonProperty ;
7+
38public class ObjectMappingClearCollection {
9+
10+ static class Product {
11+ @ JsonProperty ("product_name" )
12+ private String name ;
13+ @ JsonProperty ("product_price" )
14+ private Double price ;
15+ }
16+ public static void main (String [] args ) {
17+
18+ // Accessing existing DB
19+ AstraDB db = new AstraDB ("<token>" , "<api_endpoint>" );
20+
21+ // Access existing collection
22+ AstraDBRepository <Product > collection1 = db
23+ .createCollection ("collection_simple" , Product .class );
24+
25+ // Clear collection
26+ collection1 .deleteAll ();
27+ }
428}
Original file line number Diff line number Diff line change 11package com .dtsx .astra .sdk .documentation ;
22
3+ import com .dtsx .astra .sdk .AstraDB ;
4+ import com .dtsx .astra .sdk .AstraDBCollection ;
5+ import com .dtsx .astra .sdk .AstraDBRepository ;
6+ import com .fasterxml .jackson .annotation .JsonProperty ;
7+ import io .stargate .sdk .json .domain .DeleteQuery ;
8+
39public class ObjectMappingDeleteMany {
10+
11+ static class Product {
12+
13+ @ JsonProperty ("product_name" )
14+ private String name ;
15+
16+ @ JsonProperty ("product_price" )
17+ private Double price ;
18+
19+ // getters and setters
20+ }
21+
22+ public static void main (String [] args ) {
23+
24+ // Given an active db and a collection with a vector field (see CreateCollection.java)
25+ AstraDB db = new AstraDB ("<token>" , "<api_endpoint>" );
26+
27+ /*
28+ * Create collection with no vector.
29+ */
30+ AstraDBRepository <Product > collection1 = db
31+ .createCollection ("collection_simple" , Product .class );
32+
33+ // Delete item based on a query
34+ int deletedCount = collection1 .deleteAll (DeleteQuery .builder ()
35+ .where ("product_price" ).isEqualsTo (9.99 )
36+ .build ());
37+ }
438}
You can’t perform that action at this time.
0 commit comments