Dark Mode

Insert data in your tables using Astra DB's GraphQL API.

After creating a table inyour keyspace using GraphQL, you can add rows of data.

Prerequisites

Write data

Any of the created APIs can be used to interact with the GraphQL data, to writeor read data.

First, let's navigate to your new keyspace library inside the playground.Switch to the graphql tab in the GraphQL playground, and change the locationto https://$ASTRACLUSTERID-$ASTRA_REGION.apps.astra.datastax.com/api/graphql/library The main importance is changing the keyspace name, as the default is system .

First, let's add a couple of books to the book table:

Note that the keyword value is used twice in the mutation.The first use defines the value that the record is set to, for instance, the titleto Moby Dick and the author to Herman Melville.The second use defines the values that will be displayed after the successof the mutation, so that proper insertion can be verified.This same method is valid for updates and read queries.

Insertion options

Three insertion options are configurable during data insertion or updating:

Note that in Astra DB, the consistency levels ANY , ONE , or LOCAL_ONE cannot be used.The default is LOCAL_QUORUM .

An example insertion that sets the consistency level and TTL:

The serial consistency can also be set with serialConsistency in the options,if needed.

Insert collections (set, list, map)

Inserting a collection is simple. An example of inserting a list:

A map is slightly more complex:

Insert a tuple

Inserting a tuple involves inserting an object; note the use of item0 , item1 ,and so on, to insert the parts of the tuple

Insert a user-defined type (UDT)

Inserting a UDT requires taking careful note of the brackets used: