Now that you have a Datastore table, you can store your own custom data! Similar to creating a Datastore table and creating a Datastore column, you will create a GraphQL query for creating Datastore data.
The inputs to this query are as follows: 1. externalId: This is the Id of the data that you can use to reference and retrieve it later. NOTE: There is a 36 character limit to this field. 1. tableId: This is the Id of the table you created above. 1. data: This is the data you want to store in stringified JSON format. Note that each Datastore table column is a JSON key. In this example, that would be the name column.
Now let's retrieve the data that we created. There are 3 different approaches to retrieving data from the table:
Retreiving data by external key
This query takes two inputs: 1. externalKey: This is the externalId that you passed into the Datastore data creation query. In this example, this was [email protected]. 1. tableId: This is the Id of the table you created above.
You can retreve all of the data from the table by using the TableDataConnection object. Like any standard Relay Connection, you can supply different paging parameters to retrieve a slice of the data (i.e. for displaying rows in a grid).
This query takes three inputs: 1. tableId: The ID of the table 1. first: The first N records 1. after: The ID of the record to start returning
Sometimes you need to select data from your tables by querying columns other than external keys. Datastore provides the ability to use a subset of standard ANSI-92 SQL to query your tables. Let's assume that we've created two columns on our table - name (a string field) and age (a number field that is an integer). To query that field, you would populate the query parameter of the TableDataConnection object:
"query":"select name, age where name = 'Jane Doe' and age > 22"