<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: BetterBotz</title>
    <description>The latest articles on DEV Community by BetterBotz (@betterbotz).</description>
    <link>https://dev.to/betterbotz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F318114%2F71be8b45-d1f2-42f0-9b07-d7278b095e2f.png</url>
      <title>DEV Community: BetterBotz</title>
      <link>https://dev.to/betterbotz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/betterbotz"/>
    <language>en</language>
    <item>
      <title>Adding and removing data in Astra tables</title>
      <dc:creator>BetterBotz</dc:creator>
      <pubDate>Mon, 01 Jun 2020 14:20:59 +0000</pubDate>
      <link>https://dev.to/betterbotz/adding-and-removing-data-in-astra-tables-2e7m</link>
      <guid>https://dev.to/betterbotz/adding-and-removing-data-in-astra-tables-2e7m</guid>
      <description>&lt;p&gt;&lt;strong&gt;This post is a part of a tutorial series for learning how to build an app with &lt;a href="https://astra.datastax.com/register?utm_medium=referral&amp;amp;utm_source=devto&amp;amp;utm_campaign=adding-and-removing-data-in-astra-tables"&gt;DataStax's Astra&lt;/a&gt; database. See all of the posts in this &lt;a href="https://dev.to/betterbotz"&gt;Better Botz series&lt;/a&gt; to start using Astra now.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/betterbotz/using-glitch-and-the-astra-data-api-4fjk"&gt;last post&lt;/a&gt;, you used the DataStax Astra API to generate data for our Better Botz database. When DataStax Astra was made generally available, GraphQL was added as a feature for creating, reading, updating, and deleting data.&lt;/p&gt;

&lt;p&gt;GraphQL uses queries and mutations to retrieve and change data.&lt;/p&gt;

&lt;h1&gt;
  
  
  Goal 1: See the status of current products
&lt;/h1&gt;

&lt;p&gt;Better Botz has created a new and improved Heavy Lift Arms. While planning when to add Heavy Lift Arms II, Better Botz needs to know if the existing Heavy Lift Arms are already listed.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;If necessary, get a fresh authorization token using the DataStax Astra API. Replace &lt;code&gt;{auth-token}&lt;/code&gt; with the value for your database:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```
curl --request POST \
  --url https://{databaseid}-{region}.apps.astra.datastax.com/api/rest/v1/auth \
  --header 'accept: */*' \
  --header 'content-type: application/json' \
  --header 'x-cassandra-request-id: {auth-token}'
```
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Using GraphQL, run a query to see if you already have the Heavy Lift Arms II.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```
curl --location --request POST 'https://{databaseid}-{region}.apps.astra.datastax.com/api/graphql' \
  --header 'accept: */*' \
  --header 'content-type: application/json' \
  --header 'x-cassandra-request-id: {unique-UUID}' \
  --header 'X-Cassandra-Token: {auth-token}' \
  --header 'Content-Type: application/json' \
  --data-raw '{"query":"query {products(value: {id:\"Heavy Lift Arms\"}) {values {id name price description created}}}"}'
```
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Replace the following values with the values for your database:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;{databaseid}&lt;/code&gt; with the UUID of your database, copied from the Astra URL.&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;{region}&lt;/code&gt; with the cloud region where your database is located, as listed on the Database Details page in Astra. For example, &lt;code&gt;us-east1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Enter a &lt;code&gt;{unique-UUID}&lt;/code&gt; for the request and the &lt;code&gt;{auth-token}&lt;/code&gt; you created earlier.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check for an existing “Heavy Lift Arms II”. This should verify that you do not have an existing “Heavy Lift Arms II” product.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Goal 2: Add a new product
&lt;/h1&gt;

&lt;p&gt;Now that you know there aren’t any Heavy Lift Arms in the products table, you want to add the new and improved product to our table for customers to be able to order.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Use the following cURL command:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```
curl --request POST \
  --url https://{databaseid}-{region}.apps.astra.datastax.com/api/rest/v1/keyspaces/{my_keyspace}/tables/{table_name}/rows \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header 'x-cassandra-request-id: {unique-UUID}' \
  --header 'x-cassandra-token: {auth-token}' \
  --data-raw '{"query":"mutation {superarms: insertProducts(value:{id:\"65cad0df-4fc8-42df-90e5-4effcd221ef7\"\n name:\"Arm Spec A2\" description:\"Heavy Lift Arms II\"price: \"9999.99\" created: \"2012-04-23T18:25:43.511Z\"}){value {name description price created}}}","variables":{}}'
```
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Replace the following values with the values for your database:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;{databaseid}&lt;/code&gt; with the UUID of your database, copied from the Astra URL.&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;{region}&lt;/code&gt; with the cloud region where your database is located, as listed on the Database Details page in Astra. For example, &lt;code&gt;us-east1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Modify &lt;code&gt;{my_keyspace}&lt;/code&gt; to match the name of your keyspace.&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;{table_name}&lt;/code&gt; with the name of the table you want to create. In this example, enter products as the table name.&lt;/li&gt;
&lt;li&gt;Enter a &lt;code&gt;{unique-UUID}&lt;/code&gt; for the request and the &lt;code&gt;{auth-token}&lt;/code&gt; you created earlier.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;--data-raw&lt;/code&gt; option defines the new product, including a description, price, and created timestamp.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Using a GraphQL query, confirm the new product is available in the database:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```
curl --location --request POST 'https://{databaseid}-{region}.apps.astra.datastax.com/api/graphql' \
  --header 'accept: */*' \
  --header 'content-type: application/json' \
  --header 'x-cassandra-request-id: {unique-UUID}' \
  --header 'X-Cassandra-Token: {auth-token}' \
  --header 'Content-Type: application/json' \
  --data-raw '{"query":"query {products(value: {id:\"Heavy Lift Arms II\"}) {values {id name price description created}}}"}'
```
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Replace the following values with the values for your database:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;{databaseid}&lt;/code&gt; with the UUID of your database, copied from the Astra URL.&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;{region}&lt;/code&gt; with the cloud region where your database is located, as listed on the Database Details page in Astra. For example, &lt;code&gt;us-east1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Enter a &lt;code&gt;{unique-UUID}&lt;/code&gt; for the request and the &lt;code&gt;{auth-token}&lt;/code&gt; you created earlier.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the next post, Better Botz you will learn to create a new table for orders that have shipped and explore further data modeling!&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>database</category>
      <category>cloud</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Using Glitch and the Astra Data API</title>
      <dc:creator>BetterBotz</dc:creator>
      <pubDate>Thu, 16 Apr 2020 19:24:39 +0000</pubDate>
      <link>https://dev.to/betterbotz/using-glitch-and-the-astra-data-api-4fjk</link>
      <guid>https://dev.to/betterbotz/using-glitch-and-the-astra-data-api-4fjk</guid>
      <description>&lt;p&gt;&lt;strong&gt;This post is a part of a tutorial series for learning how to build an app with &lt;a href="https://astra.datastax.com/register?utm_medium=referral&amp;amp;utm_source=devto&amp;amp;utm_campaign=using-glitch-and-the-astra-data-api"&gt;DataStax's Astra&lt;/a&gt; database. See all of the posts in this &lt;a href="https://dev.to/betterbotz"&gt;Better Botz series&lt;/a&gt; to start using Astra now.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/betterbotz/creating-an-express-server-for-better-botz-4b00"&gt;last blog post&lt;/a&gt;, we configured an Express backend server on Node.js, and then connected to our Astra database using the DataStax Node.js driver. We retrieved data from our orders table, only to realize that it’s empty. Fear not! We’re going to remedy that situation in this post and also start using Glitch to expedite development of our ordering application for Better Botz.&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal 1: Configure Glitch with your secure connect bundle
&lt;/h3&gt;

&lt;p&gt;If you don’t already have a Glitch account, head over to Glitch and create an account. After you create an account, open this &lt;a href="https://glitch.com/~better-botz-glitchy-fluffy-barnacle"&gt;Better Botz project&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In Glitch, open the Better Botz project. &lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Remix to Edit&lt;/strong&gt; in the upper right to make a copy of the project. When you remix a project on Glitch, you’re creating a copy of an existing project that you can edit. Think of it like forking a GitHub repository.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In your remixed project, drag or upload the secure connect bundle for your DataStax Astra database.&lt;/p&gt;

&lt;p&gt;The secure connect bundle is added to your assets, but we need it in a safe location. Therefore, we’ll move it to a hidden directory.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In your remixed project, in the project navigator to the left, select &lt;strong&gt;New File&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enter &lt;code&gt;.data&lt;/code&gt; and then select &lt;strong&gt;Add This File&lt;/strong&gt;. The new &lt;code&gt;.data&lt;/code&gt; directory will not display in your project navigator, but is created as a hidden directory.&lt;/li&gt;
&lt;li&gt;At the bottom of your project navigator, select &lt;strong&gt;Tools &amp;gt; Terminal&lt;/strong&gt; to open the terminal for your project. &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the Glitch terminal for your project, change to your &lt;code&gt;.data&lt;/code&gt; directory.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~/.data
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In your project navigator, choose your assets folder, right-click your secure connect bundle, and copy the URL of that file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the Glitch terminal, in the &lt;code&gt;.data&lt;/code&gt; directory, use wget to download your secure connect bundle:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget secure-connect-bundle-url
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Replace &lt;code&gt;secure-connect-bundle-url&lt;/code&gt; with the URL for your secure connect bundle that you copied in the previous step.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose your assets folder, select your secure connect bundle, and delete it. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Rename your secure connect bundle to secure-connect.zip.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mv secure-connect-bundle-name secure-connect.zip

&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your secure connect bundle is now accessible in Glitch. Great job! Going through the extra work of putting your database credentials in a hidden directory is tedious, but ensures that your secure connect bundle is &lt;em&gt;secure&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal 2: Adding order data
&lt;/h3&gt;

&lt;p&gt;If you recall from the last post, we retrieved data from our orders table, only to discover that it was empty. To process customer orders, we need order data! &lt;/p&gt;

&lt;p&gt;In previous posts, we created tables and inserted data using the Cassandra Query Language SHell (CQLSH) that is embedded in Astra. This practice is perfectly acceptable, but we’re not CQL experts and would rather use a more programmatic tool. Therefore, we’ll use the &lt;a href="https://astra.readme.io/reference"&gt;Astra Data API&lt;/a&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  Creating an authorization token
&lt;/h4&gt;

&lt;p&gt;The &lt;a href="https://astra.readme.io/docs/getting-started-with-datastax-astra"&gt;Getting Started tutorial&lt;/a&gt; in the Astra API documentation illustrates the steps to connect to and interact with your Astra database. Following those instructions, we’ll use cURL commands in this example. Use this cURL command as you work through the following steps to create an authorization token. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt;: If you want to issue commands from your application, choose the &lt;a href="https://astra.readme.io/reference"&gt;API endpoint&lt;/a&gt; you want to work with, select your preferred language, and enter the required data for the endpoint. The example automatically updates with the values you enter, making it easy to copy and paste into your IDE.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --request POST \
  --url https://{databaseid}-{region}.apps.astra.datastax.com/api/rest/v1/auth \
  --header 'accept: */*' \
  --header 'content-type: application/json' \
  --header 'x-cassandra-request-id: {unique-UUID}' \
  --data '{"username":"{database-user}","password":"{database-password}"}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;In a browser, log in to &lt;a href="https://astra.datastax.com/register?utm_medium=referral&amp;amp;utm_source=devto&amp;amp;utm_campaign=using-glitch-and-the-astra-data-api"&gt;DataStax Astra&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Select the database you want to connect to.

&lt;ul&gt;
&lt;li&gt;  In the Astra URL, copy the &lt;code&gt;databaseid&lt;/code&gt; of your database, which is the last UUID in the path: &lt;code&gt;https://astra.datastax.com/org/{org-Id}/database/{databaseid}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  Select the database you want to connect to and copy the cloud region where your database lives. For example, &lt;code&gt;us-east1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  Copy the username and password you entered when creating your database.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;In the cURL example you copied previously, replace these values with the values for your database:

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;{databaseid}&lt;/code&gt; with the UUID of your database, copied from the Astra URL.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;{region}&lt;/code&gt; with the cloud region where your database is located, as listed on the Database Details page in Astra. For example, &lt;code&gt;us-east1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;{unique-UUID}&lt;/code&gt; with a randomly-generated UUID that is unique for the authorization request.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;{database-user}&lt;/code&gt; is the username entered when you created your database.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;{database-password}&lt;/code&gt; is the password for the specified username.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;From the command line, run the entire &lt;code&gt;cURL&lt;/code&gt; command with the values for your database. \
An authorization token is returned: \
&lt;code&gt;{"authToken": "37396a44-dcb8-4740-a97f-79f0dba47973"}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Copy the value of the authorization token, which you'll include when making requests to your database, such as creating tables, adding rows, or modifying columns. In this example, the authorization token value is &lt;code&gt;37396a44-dcb8-4740-a97f-79f0dba47973&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Inserting data in your orders table
&lt;/h4&gt;

&lt;p&gt;Now that you have an authorization token, use it to connect to your Astra database and submit queries. You pass this token with each query to ensure a secure connection to your Astra database.&lt;/p&gt;

&lt;p&gt;Before we can insert data, there’s something missing from our table structure that we discovered when reviewing the order data. Each order has a &lt;em&gt;quantity&lt;/em&gt;, but our orders table doesn’t have a column for that data. &lt;/p&gt;

&lt;p&gt;We’ll use the &lt;a href="https://astra.readme.io/reference#addcolumn-1"&gt;add column&lt;/a&gt; endpoint of the DataStax Astra API to add a &lt;code&gt;quantity&lt;/code&gt; column. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Copy the following request, which you use to add a &lt;code&gt;quantity&lt;/code&gt; column to the &lt;code&gt;orders&lt;/code&gt; table in your &lt;code&gt;betterbotz&lt;/code&gt; keyspace.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --request POST \
--url https://{databaseid}-{region}.apps.astra.datastax.com/api/rest/v1/keyspaces/{my_keyspace}/tables/orders/columns \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-cassandra-request-id: {unique-UUID}' \
--header 'x-cassandra-token: {auth-token}' \
--data '{"static":false,"name":"quantity","typeDefinition":"int"}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replace the following values with the values for your database:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replace &lt;code&gt;{databaseid}&lt;/code&gt; with the UUID of your database, copied from the Astra URL.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replace &lt;code&gt;{region}&lt;/code&gt; with the cloud region where your database is located, as listed on the Database Details page in Astra. For example, &lt;code&gt;us-east1&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modify &lt;code&gt;my_keyspace&lt;/code&gt; to match the name of your keyspace, which is &lt;code&gt;betterbotz&lt;/code&gt; if you followed the previous blog entries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter a &lt;code&gt;{unique-UUID}&lt;/code&gt; for the request and the &lt;code&gt;{auth-token}&lt;/code&gt; you created earlier.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the cURL call to add a &lt;code&gt;quantity&lt;/code&gt; column to your &lt;code&gt;orders&lt;/code&gt; table in the keyspace that you specified. If the call is successful, a message returns indicating: &lt;code&gt;{"success":true}&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that our table columns are updated, we’ll use the &lt;a href="https://astra.readme.io/reference#updaterow-1"&gt;update rows&lt;/a&gt; endpoint to add data to our &lt;code&gt;orders&lt;/code&gt; table. Copy the following cURL command and replace the same variables as in the previous steps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --request PUT \
  --url https://{databaseid}-{region}.apps.astra.datastax.com/api/rest/v1/keyspaces/{my_keyspace}/tables/tableName/rows/Otto%20Octavius \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header 'x-cassandra-request-id: {unique-UUID}' \
  --header 'x-cassandra-token: {auth-token}' \
  --data '{"changeset":[{"column":"id","value":"e65063a7-fba3-41ba-84bb-740a01cacf5e"},{"column":"address","value":"2475 Shadow Ln. Stow, Ohio(OH), 44224"},{"column":"prod_id","value":"31047029-2175-43ce-9fdd-b3d568b19bb0"},{"column":"prod_name","value":"Heavy Lift Arms"},{"column":"description","value":"Heavy lift arms capable of lifting 1,250 lbs of weight per arm. Sold as a set."},{"column":"price","value":4199.99},{"column":"quantity","value":5},{"column":"sell_price","value":21000.96}]}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;--data&lt;/code&gt; option of the call, we’ll use the &lt;code&gt;changeset&lt;/code&gt; parameter to define the data that we want to update in the &lt;code&gt;orders&lt;/code&gt; table. This example adds a single row to the orders table.&lt;/p&gt;

&lt;p&gt;Notice that &lt;code&gt;Otto%20Octavius&lt;/code&gt; is used in the &lt;code&gt;--url&lt;/code&gt; option, but &lt;code&gt;customer_name&lt;/code&gt; is not included in the changeset. That’s because &lt;code&gt;customer_name&lt;/code&gt; is the &lt;em&gt;primary key&lt;/em&gt;, which identifies the location and order of stored data. The first column declared in the primary key definition is the &lt;em&gt;partition key&lt;/em&gt;, which we’ll get to in the next section when creating a shipping table.&lt;/p&gt;

&lt;p&gt;To add more rows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Copy the &lt;code&gt;changeset&lt;/code&gt; parameter for each of the following examples and replace the &lt;code&gt;changeset&lt;/code&gt; defined by the &lt;code&gt;--data&lt;/code&gt; option of the call.&lt;/li&gt;
&lt;li&gt;Replace the primary key in the the &lt;code&gt;--url&lt;/code&gt; option to use the value indicated before the example.&lt;/li&gt;
&lt;li&gt;Run the cURL command with the updated data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example, here’s an updated &lt;code&gt;changeset&lt;/code&gt; parameter for a customer named Desmond Blackwell. Because &lt;code&gt;customer_name&lt;/code&gt; is the primary key, the &lt;code&gt;--url&lt;/code&gt; changes to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://databaseid-region.apps.astra.datastax.com/api/rest/v1/keyspaces/keyspaceName/tables/tableName/rows/Desmond%20Blackwell
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Primary key = &lt;strong&gt;Desmond%20Blackwell&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'{"changeset":[{"column":"id","value":"e5a768fc-ffdd-49e9-a179-b491e024088a"},
    {"column":"address","value":"91 Dogwood Dr. Bridgeport, Connecticut (CT) 06606"},
    {"column":"prod_id","value":"31047029-2175-43ce-9fdd-b3d568b19bb8"},
    {"column":"prod_name","value":"Precision Torso"},
    {"column":"description","value":"Robot torso built to handle precision jobs with extra stability and accuracy reinforcement."},
    {"column":"price","value":8199.99},
    {"column":"quantity","value":3},
    {"column":"sell_price","value":24599.97}]}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Use the following examples to make additional update row calls by modifying the primary key, replacing the changeset, and running the cURL command again.&lt;/p&gt;

&lt;p&gt;Primary key = &lt;strong&gt;Loretta%20Stillwell&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'{"changeset":[{"column":"id","value":"fae7c26c-7bc4-41e0-9e9f-63905cc38944"},
    {"column":"address","value":"1314 Lindwood Dr. Carter Lake, Iowa (IA) 51510"},
    {"column":"prod_id","value":"31047029-2175-43ce-9fdd-b3d568b19bb7"},
    {"column":"prod_name","value":"Medium Strength Torso"},
    {"column":"description","value":"Robot body to handle general jobs."},
    {"column":"price","value":1999.99},
    {"column":"quantity","value":2},
    {"column":"sell_price","value":3999.98}]}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Primary key = &lt;strong&gt;Matt%20Williamson&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'{"changeset":[{"column":"id","value":"02668188-7b74-4ac6-bb4b-273b14bbda7e"},
    {"column":"address","value":"15900 Wilcox Ln. Marion, Michigan (MI) 49665"},
{"column":"prod_id","value":"31047029-2175-43ce-9fdd-b3d568b19bb6"},
    {"column":"prod_name","value":"High Strength Torso"},
    {"column":"description","value":"Robot body with reinforced plate to handle heavy workload and weight during jobs."},
    {"column":"price","value":2999.99},
    {"column":"quantity","value":6},
    {"column":"sell_price","value":13199.94}]}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Primary key = &lt;strong&gt;Jayashree%20Marshall&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'{"changeset":[{"column":"id","value":"295c362d-2eaf-43c0-bd68-63efc2cd1767"},
    {"column":"address","value":"107 Trulson St. Oakland, Nebraska (NE), 68045"},
    {"column":"prod_id","value":"31047029-2175-43ce-9fdd-b3d568b19bb5"},
    {"column":"prod_name","value":"Basic Task CPU"},
    {"column":"description","value":"Head processor unit for robot with basic process tasks."},
    {"column":"price","value":899.99},
    {"column":"quantity","value":5},
    {"column":"sell_price","value":4499.95}]}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Primary key = &lt;strong&gt;Evelyn%20Davis&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'{"changeset":[{"column":"id","value":"5305ff90-e838-46ea-860f-69e831d28146"},
    {"column":"address","value":"36 Jasmine Ln. Valley Stream, New York(NY), 11581"},
    {"column":"prod_id","value":"31047029-2175-43ce-9fdd-b3d568b19bb4"},
    {"column":"prod_name","value":"High Process AI CPU"},
    {"column":"description","value":"Head processor unit for robot with basic process tasks."},
    {"column":"price","value":2199.99},
    {"column":"quantity","value":12},
    {"column":"sell_price","value":26399.88}]}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Primary key = &lt;strong&gt;Wyatt%20Devonshire&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'{"changeset":[{"column":"id","value":"bccaed73-e7fb-4f16-8799-206e08905161"},
    {"column":"address","value":"2770 Raymond St. Forest Grove, Oregon(OR), 97116"},
    {"column":"prod_id","value":"31047029-2175-43ce-9fdd-b3d568b19bb3"},
    {"column":"prod_name","value":"Drill Arms"},
    {"column":"description","value":"Arms for drilling into surface material. Sold as a set. Does not include drill bits."},
    {"column":"price","value":2199.99},
    {"column":"quantity","value":3},
    {"column":"sell_price","value":6599.97}]}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Primary key = &lt;strong&gt;Lavender%20Chesterfield&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'{"changeset":[{"column":"id","value":"ccc5bc2d-d166-471b-ad44-68be45663545"},
    {"column":"address","value":"250 Holmes Blvd #1A Gretna, Louisiana(LA), 70056"},
    {"column":"prod_id","value":"31047029-2175-43ce-9fdd-b3d568b19bb1"},
    {"column":"prod_name","value":"Precision Action Arms"},
    {"column":"description","value":"Arms for precision activities in manufacturing or repair. Sold as a set."},
    {"column":"price","value":12199.99},
    {"column":"quantity","value":1},
    {"column":"sell_price","value":12199.99}]}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Primary key = &lt;strong&gt;Darius%20Smith&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'{"changeset":[{"column":"id","value":"3c371be4-203c-497f-a1eb-79769d3526a8"},
    {"column":"address","value":"199 State U Rd. Macks Creek, Missouri (MO), 65786"},
    {"column":"prod_id","value":"31047029-2175-43ce-9fdd-b3d568b19bb2"},
    {"column":"prod_name","value":"Medium Lift Arms"},
    {"column":"description","value":"Medium lift arms capable of lifting 850 lbs of weight per arm. Sold as a set."},
    {"column":"price","value":3199.99},
    {"column":"quantity","value":1},
    {"column":"sell_price","value":3199.99}]}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Goal 3: Tracking orders being shipped
&lt;/h3&gt;

&lt;p&gt;As orders propagate through the system, we’ll need to track ones that are shipping so that customers can easily check their order status. To that end, we’ll use the &lt;a href="https://astra.readme.io/reference#addtable-1"&gt;add table&lt;/a&gt; endpoint to create a shipping table in your Astra database. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Copy the following request, which you use to create a &lt;code&gt;shipping&lt;/code&gt; table in your &lt;code&gt;betterbotz&lt;/code&gt; keyspace.&lt;/p&gt;

&lt;p&gt;On the last line of the following example, &lt;code&gt;shipping&lt;/code&gt; is the table name. The table columns are defined by &lt;code&gt;columnDefinitions&lt;/code&gt;, such as &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;prod_id&lt;/code&gt;, &lt;code&gt;cust_id&lt;/code&gt;, and &lt;code&gt;address_id&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Remember the primary key we used earlier when updating the &lt;code&gt;orders&lt;/code&gt; table? We also mentioned a partition key (&lt;code&gt;partitionKey&lt;/code&gt;), which is a special column that defines the outermost grouping of data, similar to a schema in a relational database. For the &lt;code&gt;shipping&lt;/code&gt; table, our partition key uses two columns: &lt;code&gt;prod_name&lt;/code&gt; and &lt;code&gt;customer_name&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --request POST \
--url https://{databaseid}-{region}.apps.astra.datastax.com/api/rest/v1/keyspaces/{my_keyspace}/tables \
--header 'accept: */*' \
--header 'content-type: application/json' \
--header 'x-cassandra-request-id: {unique-UUID}' \
--header 'x-cassandra-token: {auth-token}' \
--data '{"ifNotExists":true,"columnDefinitions":[
{"static":false,"name":"id","typeDefinition":"uuid"},
{"static":false,"name":"prod_id","typeDefinition":"uuid"},
{"static":false,"name":"cust_id","typeDefinition":"uuid"},
{"static":false,"name":"address_id","typeDefinition":"uuid"},
{"static":false,"name":"prod_name","typeDefinition":"text"},
{"static":false,"name":"customer_name","typeDefinition":"text"},
{"static":false,"name":"street","typeDefinition":"text"},
{"static":false,"name":"city","typeDefinition":"text"},
{"static":false,"name":"state","typeDefinition":"text"},
{"static":false,"name":"country","typeDefinition":"text"},
{"static":false,"name":"code","typeDefinition":"text"}],
"primaryKey":{"partitionKey":["prod_name","customer_name"]},
"tableOptions":{"defaultTimeToLive":0},"name":"shipping"}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replace the following values with the values for your database:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replace &lt;code&gt;{databaseid}&lt;/code&gt; with the UUID of your database, copied from the Astra URL.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replace &lt;code&gt;{region}&lt;/code&gt; with the cloud region where your database is located, as listed on the Database Details page in Astra. For example, &lt;code&gt;us-east1&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modify &lt;code&gt;my_keyspace&lt;/code&gt; to match the name of your keyspace, which is &lt;code&gt;betterbotz&lt;/code&gt; if you followed the previous blog entries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter a &lt;code&gt;{unique-UUID}&lt;/code&gt; for the request and the &lt;code&gt;{auth-token}&lt;/code&gt; you created earlier.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the &lt;code&gt;--data&lt;/code&gt; option of the call, we’ll define the table columns using the &lt;code&gt;columnDefinitions&lt;/code&gt; parameter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the cURL call to create a &lt;code&gt;shipping&lt;/code&gt; table in the keyspace that you specified. If the call is successful, a message returns indicating: &lt;code&gt;{"success":true}&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s use the &lt;a href="https://astra.readme.io/reference#gettable-1"&gt;get table&lt;/a&gt; endpoint to retrieve the table you just created. Replace the same variables as in previous steps, and then replace &lt;code&gt;{tableName}&lt;/code&gt; with the name of your table (which is &lt;code&gt;shipping&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --request GET \
  --url https://{databaseid}-{region}.apps.astra.datastax.com/api/rest/v1/keyspaces/{keyspaceName}/tables/{tableName} \
  --header 'accept: application/json' \
  --header 'x-cassandra-request-id: {unique-UUID}' \
  --header 'x-cassandra-token: {auth-token}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Running this cURL command with the variables you entered returns data for your shipping table, but it’s not exactly human readable. You can add a pipe character and &lt;code&gt;json_pp&lt;/code&gt; at the end of your cURL command to provide a formatted JSON response, but customers need an easier way to access this shipping data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"name":"shipping","keyspace":"betterbotz","columnDefinitions":[{"Name":"customer_name","TypeDefinition":"text"},{"Name":"id","TypeDefinition":"uuid"},{"Name":"prod_name","TypeDefinition":"text"},{"Name":"city","TypeDefinition":"text"},{"Name":"cust_id","TypeDefinition":"uuid"},{"Name":"country","TypeDefinition":"text"},{"Name":"prod_id","TypeDefinition":"uuid"},{"Name":"state","TypeDefinition":"text"},{"Name":"street","TypeDefinition":"text"},{"Name":"address_id","TypeDefinition":"uuid"},{"Name":"code","TypeDefinition":"text"}],"primaryKey":{"PartitionKey":["prod_name"],"clusteringKey":["customer_name"]},"tableOptions":{"DefaultTimeToLive":null,"clusteringExpression":[{"Column":"customer_name","Order":"asc"}]}}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What about your application in Glitch? Glad you asked! Now that there’s data in your orders table, you can actually see it being returned by your application. Open your Glitch project and complete the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Edit the &lt;code&gt;sample-run.sh&lt;/code&gt; script to include your Astra database username and password.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ASTRAUSER=username ASTRAPASSWORD=password
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Tools &amp;gt; Terminal&lt;/strong&gt; to open a terminal connected to your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the terminal, from your home directory (~), run the &lt;code&gt;./sample-run.sh&lt;/code&gt; script to start the server using your Astra credentials:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~ &amp;amp;&amp;amp;
./sample-run.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;With the server running, open a browser and navigate to the following paths to view examples of data retrieval. In each URL, change &lt;code&gt;your-project-name&lt;/code&gt; to the name of your Glitch project:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;This URL verifies that the Express server is running with the included Jade templates: 
&lt;a href="https://your-project-name.glitch.me/"&gt;https://your-project-name.glitch.me/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;/data&lt;/code&gt; endpoint includes the raw data that is a direct response of the JSON response that is retrieved using the API GET call: 
&lt;a href="https://your-project-name.glitch.me/data"&gt;https://your-project-name.me/data&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;/datareport&lt;/code&gt; endpoint is a response that includes the data results generated from the Jade template. As configured, customer orders will display at this endpoint: 
&lt;a href="https://your-project-name.glitch.me/datareport"&gt;https://your-project-name.glitch.me/datareport&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your data is being returned at the &lt;code&gt;/data&lt;/code&gt; endpoint, and is formatted in a human-readable form at the &lt;code&gt;/datareport&lt;/code&gt; endpoint. You did it! This step is a huge milestone achievement for building an online ordering system for Better Botz. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--681hbZhP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rtnbxm2j8m7uqow2c98i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--681hbZhP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rtnbxm2j8m7uqow2c98i.png" alt="Customer orders data"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next post, we’ll develop a means to quickly and easily manage CRUD (Create, Read, Update, Delete) operations, which we’ll build with Glitch and Express.js to get data in and out of your tables.&lt;/p&gt;

</description>
      <category>database</category>
      <category>beginners</category>
      <category>cloud</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Creating an Express server for Better Botz</title>
      <dc:creator>BetterBotz</dc:creator>
      <pubDate>Mon, 16 Mar 2020 20:40:23 +0000</pubDate>
      <link>https://dev.to/betterbotz/creating-an-express-server-for-better-botz-4b00</link>
      <guid>https://dev.to/betterbotz/creating-an-express-server-for-better-botz-4b00</guid>
      <description>&lt;p&gt;&lt;strong&gt;This post is a part of a tutorial series for learning how to build an app with &lt;a href="https://astra.datastax.com/register?utm_medium=referral&amp;amp;utm_source=devto&amp;amp;utm_campaign=creating-an-express-server-for-better-botz"&gt;DataStax's Astra&lt;/a&gt; database. See all of the posts in this &lt;a href="https://dev.to/betterbotz"&gt;Better Botz series&lt;/a&gt; to start using Astra now.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/betterbotz/building-applications-with-better-botz-1he3"&gt;last blog post&lt;/a&gt;, we learned about Better Botz and their need for a new online ordering application. We created an Astra database, generated two tables, inserted some data, and learned how to retrieve data.&lt;/p&gt;

&lt;p&gt;Using that database, we’re going to configure an Express backend server on Node.js. This server is the backbone of the React application that will become the online ordering and reporting platform for Better Botz. If that goal sounds ambitious, don’t worry; we’re going to guide you through each part of the process. While experience with Node.js is helpful, it is not required. &lt;/p&gt;

&lt;p&gt;We’ll install the DataStax Node.js driver, download the secure connect bundle for your Astra database, and then configure the driver to use that bundle when connecting to your Astra database. After establishing that connection, we can use the Node.js driver as our conduit for getting data in and out of the database.&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal 1: Laying the Foundation
&lt;/h3&gt;

&lt;p&gt;Before you dive into developing the ordering application, lay the necessary groundwork. You’ll install Node.js and the DataStax Node.js driver, and then download the secure connect bundle for your Astra database. &lt;/p&gt;

&lt;p&gt;First, download and install Node.js. Follow the instructions on the Node.js website for your preferred method of installing software: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://nodejs.org/en/download/package-manager/"&gt;Use a package manager&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://nodejs.org/en/download/"&gt;Download the source code or install using a prebuilt installer&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;With Node.js installed, install the DataStax Node.js driver:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install cassandra-driver
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a new directory for your Node.js application, and then go to that directory:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir betterbotzapp &amp;amp;&amp;amp; cd betterbotzapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We’ll be creating a set of files to work from. Choose one of the following options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Prebuilt:&lt;/strong&gt; Clone this &lt;a href="https://github.com/riptano/better-botz-gui-at-glitch/tree/pollo-1"&gt;BetterBotz GitHub repository&lt;/a&gt;. This option provides all of the files you need with the main structure already in place.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manual:&lt;/strong&gt; Use &lt;a href="https://expressjs.com/en/starter/generator.html"&gt;express generator&lt;/a&gt; to create a skeleton Node.js application. With this option, you’ll do more of the manual work to create files, folder structures, and source code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you chose the prebuilt option, jump ahead to download your database credentials. For the manual route, let’s create a barebones project to work from.&lt;/p&gt;

&lt;p&gt;Install express-generator to quickly create a skeleton Node.js application for us to work with, and then run express:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install -g express-generator
$ express 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When you run &lt;code&gt;express&lt;/code&gt;, a skeleton project is created with the minimal files necessary for a basic Node.js application. Do a simple list to show the files that were created and familiarize yourself with the files we’ll work with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -l
  |_app.js
  |_bin
  |_package.json
  |_public
  |_routes
  |_views
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With the project structure in place, you’re ready to download the security credentials for your Astra database.&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal 2: Downloading Database Security Credentials
&lt;/h3&gt;

&lt;p&gt;From your DataStax Astra database, download the secure connect bundle, which contains the security credentials for connecting to your database.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In a browser, log in to &lt;a href="https://astra.datastax.com/utm_medium=referral&amp;amp;utm_source=devto&amp;amp;utm_campaign=creating-an-express-server-for-better-botz"&gt;DataStax Astra&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;From the &lt;strong&gt;Databases&lt;/strong&gt; page, under Actions, select the ellipsis (&lt;strong&gt;…&lt;/strong&gt;) for the database you want to connect to and select &lt;strong&gt;Connection details&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;strong&gt;Connection Details&lt;/strong&gt; window, select &lt;strong&gt;Download secure connect bundle&lt;/strong&gt; to download the &lt;code&gt;secure-connect-&lt;strong&gt;&lt;em&gt;database_name&lt;/em&gt;&lt;/strong&gt;.zip&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;This file contains the security certificates and credentials for your &lt;br&gt;
database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;: Do not share this secure connect bundle with anyone outside of your organization. Anyone with access to these credentials can potentially access your database.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In your &lt;code&gt;betterbotzapp&lt;/code&gt; directory, create a &lt;code&gt;.data&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd betterbotzapp
$ mkdir .data
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Move the secure connect bundle that you downloaded to the &lt;code&gt;.data&lt;/code&gt; directory you just created. Placing the bundle in this hidden directory allows you to better protect your database credentials and control access.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cp ~/Downloads/secure-connect-database_name.zip ~/betterbotzapp/.data
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Change the permissions on the &lt;code&gt;.data&lt;/code&gt; directory so that only you have read/write access:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ chmod 700 .data
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Goal 3: Connect the server to your database
&lt;/h3&gt;

&lt;p&gt;Ensure that your Express server can access the secure connect bundle for your database, and that the DataStax Node.js driver is configured correctly.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In your betterbotzapp project, open index.js in the routes directory.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;$ cd routes&lt;br&gt;
$ nano index.js&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;In index.js, replace the value for the path variable with the path to your secure connect bundle:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = './.data/secure-connect-database_name.zip';
const { Client } = require('cassandra-driver');
const client = new Client({
cloud: { secureConnectBundle: path },
credentials: { username: process.env.ASTRAUSERNAME, password: 
process.env.ASTRAPASSWORD}
});
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This code uses the credentials from the secure connect bundle in your &lt;code&gt;.data&lt;/code&gt; directory to make a connection to your Astra database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: if you’re using the files from the Better Botz GitHub repository, the remainder of your &lt;code&gt;index.js&lt;/code&gt; file is preconfigured to obtain data from your database. Skip ahead to step 5 to install dependencies and start your server.&lt;/p&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;In the &lt;code&gt;index.js&lt;/code&gt; file, replace the main &lt;code&gt;router.get&lt;/code&gt; function with the following code. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The first function gets the home page for your server and adds a Better Botz title.&lt;/li&gt;
&lt;li&gt;The second function creates a data report with results from a request that you’ll add in the next step.&lt;/li&gt;
&lt;li&gt;The third function generates a direct data response of the JSON response using the API get call.
&lt;/li&gt;
&lt;/ol&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router.get('/', function(req, res, next) {
  res.render('index', { title: 'Better Botz' });
});

router.get('/datareport', function (req, res) {
  getMoreData().then(function(data){
    res.render('datareport', { data } );
  }).catch(function(filteredData){
    res.send(filteredData);
  })
});

router.get('/data', function (req, res) {
  getMoreData().then(function(data){
    res.send(data);
  }).catch(function(filteredData){
    res.send(filteredData);
  })
});
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Lastly, add the following code to the &lt;code&gt;index.js&lt;/code&gt; file. This code sends a CQL &lt;code&gt;SELECT&lt;/code&gt; statement to retrieve data from your orders table in the &lt;code&gt;betterbotz&lt;/code&gt; keyspace.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function getMoreData(){
  const result = await client.execute('SELECT customer_name, address, 
description, price, prod_id, prod_name, sell_price FROM 
betterbotz.orders');
  return result.rows;
}
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Save your &lt;code&gt;index.js&lt;/code&gt; file, and then run the following command to install required dependencies and packages for Node.js:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Running this command downloads dependencies to your machine. The number of downloaded dependencies depends on other packages installed on your system.&lt;/p&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;From your terminal, run the following command to set username and password variables and then start your Express server. Replace the variables with the username and password for your Astra database.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ASTRAUSER=myusername ASTRAPASSWORD=mypassword node bin/www
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Great! You won’t notice anything in your terminal...yet. Let’s review results in a browser to ensure that the server is working, and then check back in the terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal 3: Reviewing results
&lt;/h3&gt;

&lt;p&gt;Open a browser and navigate to &lt;a href="http://localhost:3000/"&gt;&lt;/a&gt;&lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt;. You should see a page displaying Better Botz as the title, which verifies that your Express server is running with the included Jade templates. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: If you cloned the Better Botz GitHub repository, your Jade template already contains the following lines. Skip ahead to step 3.&lt;/p&gt;

&lt;p&gt;We’re going to make some modifications to the &lt;code&gt;layout.jade&lt;/code&gt; template, which lives in the &lt;code&gt;/views&lt;/code&gt; directory of your &lt;code&gt;betterbotzapp&lt;/code&gt; project. For those going the manual route, we’ll add some code to update the Jade template, which affects the information displayed in the browser.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In your &lt;code&gt;betterbotzapp&lt;/code&gt; project, navigate to the &lt;code&gt;/views&lt;/code&gt; directory and open the &lt;code&gt;layout.jade&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Replace the body section with the following code:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body
    header
      h1= title

    main
      p
        | Welcome to the #{title} site to help you build what you need for your Better Botz workforce!

    footer
      | Powered by&amp;amp;nbsp;
      a(href='https://astra.datastax.com') DataStax Astra
      | !
      | Lots of HTML turned into Jade with&amp;amp;nbsp;
      a(href='https://html2jade.org/') html2jade
      | . Built by all the robots at&amp;amp;nbsp;
      a(href='https://twitter.com/betterbotz/') Better Botz
      | !
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;code&gt;/templates&lt;/code&gt; directory, create a &lt;code&gt;datareport.jade&lt;/code&gt; file and add the following code.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends layout

block content
    h1 Customer Orders
    ul
        for order in data
            li
                div
                    b Customer Name:
                    =order.customer_name
                    div
                        b Address:
                        =order.address
                    div
                        b Description:
                        =order.description
        else
            li No orders currently.
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save your changes to the &lt;code&gt;layout.jade&lt;/code&gt; and &lt;code&gt;datareport.jade&lt;/code&gt; files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;code&gt;Ctrl + C&lt;/code&gt; to stop the server. Restart the server with your database username and password.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ASTRAUSER=myusername ASTRAPASSWORD=mypassword node bin/www
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Refresh your browser pointing to &lt;a href="http://localhost:3000/"&gt;&lt;/a&gt;&lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your browser displays the changes, which include a new footer with links to the projects we’re using to build our database, server, and HTML for the page. Great job!&lt;/p&gt;

&lt;p&gt;We know that our server is running and that we can actively make changes that are reflected in the browser.&lt;/p&gt;

&lt;p&gt;Let’s revisit your terminal. After updating the footer in the &lt;code&gt;layout.jade&lt;/code&gt; file and refreshing your browser, you should see a few GET calls:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET / 304 254.400 ms - -
GET /stylesheets/style.css 304 1.893 ms - -
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These calls indicate requests from your Express server to the browser endpoints for data. Each time that you refresh your browser, GET calls are sent to the database and updated in your terminal.&lt;/p&gt;

&lt;p&gt;Now, let’s review two different endpoints to view data responses from those GET calls.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In a browser, navigate to &lt;a href="http://localhost:3000/datareport"&gt;&lt;/a&gt;&lt;a href="http://localhost:3000/datareport"&gt;http://localhost:3000/datareport&lt;/a&gt;. You’ll see similar content to the main URL, except that the content displaying is a &lt;em&gt;direct data response&lt;/em&gt; of the JSON response that is using the API GET call. &lt;/li&gt;
&lt;li&gt;Navigate to &lt;a href="http://localhost:3000/data"&gt;&lt;/a&gt;&lt;a href="http://localhost:3000/data"&gt;http://localhost:3000/data&lt;/a&gt; and you’ll see...a set of square brackets? That’s correct! If you inspect the CQL statement that we added to the &lt;code&gt;index.js&lt;/code&gt; file, you’ll see that we’re trying to retrieve data from the &lt;code&gt;orders&lt;/code&gt; table:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT customer_name, address, description, price, prod_id, prod_name, sell_price FROM betterbotz.orders
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Your &lt;code&gt;orders&lt;/code&gt; table is currently &lt;em&gt;empty&lt;/em&gt;, which is why no data returns at the &lt;code&gt;/data&lt;/code&gt; endpoint. In the &lt;a href="https://dev.to/betterbotz/using-glitch-and-the-astra-data-api-4fjk"&gt;next post&lt;/a&gt;, we’ll add data to the &lt;code&gt;orders&lt;/code&gt; table and create a new table to track which orders are shipping and which have already shipped. We can then check the &lt;code&gt;/data&lt;/code&gt; endpoint and see data being returned to the browser.&lt;/p&gt;

&lt;p&gt;Stay tuned!&lt;/p&gt;

</description>
      <category>database</category>
      <category>beginners</category>
      <category>cloud</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building applications with Better Botz</title>
      <dc:creator>BetterBotz</dc:creator>
      <pubDate>Wed, 04 Mar 2020 18:06:32 +0000</pubDate>
      <link>https://dev.to/betterbotz/building-applications-with-better-botz-1he3</link>
      <guid>https://dev.to/betterbotz/building-applications-with-better-botz-1he3</guid>
      <description>&lt;p&gt;&lt;strong&gt;This post is a part of a tutorial series for learning how to build an app with &lt;a href="https://astra.datastax.com/register?utm_medium=referral&amp;amp;utm_source=devto&amp;amp;utm_campaign=building-applications-with-better-botz"&gt;DataStax's Astra&lt;/a&gt; database. See all of the posts in this &lt;a href="https://dev.to/betterbotz"&gt;Better Botz series&lt;/a&gt; to start using Astra now.&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Introducing Better Botz
&lt;/h1&gt;

&lt;p&gt;Better Botz* believes that robots can help improve the health, prosperity, and wellbeing of human beings across the world. The company seeks to build Better Botz for a better future!&lt;/p&gt;

&lt;p&gt;For example, a personal care robot can help disabled or elderly people retrieve objects, carry groceries, navigate their home and community, and complete essential daily tasks. Business-oriented robots can be built for tunneling or mining applications, surveying dangerous areas, completing minor surgery, or traversing great distances without tiring.&lt;/p&gt;

&lt;p&gt;Better Botz supports learning and teaching through hands-on interactions, so they sell kits to build your robot using predefined blueprints. Alternatively, you can purchase individual components to customize your robot for various applications. Pretty cool, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  The Growth Problem
&lt;/h2&gt;

&lt;p&gt;Business is booming, and Better Botz needs a simple application to replace their online ordering platform for accepting orders. Customers can either purchase a robot kit or individual components to build their own robot. The problem is, Better Botz is so focused on designing and building robots that they don’t have time to build the ordering application. Here’s where you come in! &lt;/p&gt;

&lt;p&gt;Better Botz is looking for a savvy software developer (that’s you) to design and build an online ordering application to provide users with a seamless shopping and checkout experience. In this initial post, we’ll review the available data, create a database to store the data, and generate two tables that are crucial to solving this problem.&lt;/p&gt;

&lt;p&gt;With each subsequent post, we’ll dig deeper into different data sets and expand our application, integrating different technologies as we go.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Data
&lt;/h2&gt;

&lt;p&gt;Initially, we’ll be focusing on two tables: Products and Orders. Products can either be individual parts (arms/legs, torso, head, and so on) or complete robot kits. Orders are just a list of Products that customers want to purchase. &lt;/p&gt;

&lt;p&gt;Before creating the tables, we need somewhere to put them. We need a database that is lightweight, performant, and scalable to expand with our application. The &lt;a href="https://astra.datastax.com/register?utm_medium=referral&amp;amp;utm_source=devto&amp;amp;utm_campaign=building-applications-with-better-botz"&gt;DataStax Astra database&lt;/a&gt; checks all of those boxes, and also has a Free tier that you can use for zero dollars while building your application. &lt;/p&gt;

&lt;h3&gt;
  
  
  Goal 1: Create a DataStax Astra database on the Free tier
&lt;/h3&gt;

&lt;p&gt;Use &lt;a href="https://astra.datastax.com/register?utm_medium=referral&amp;amp;utm_source=devto&amp;amp;utm_campaign=building-applications-with-better-botz"&gt;DataStax Astra&lt;/a&gt; to create a database on the Free tier:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On the database login page, select &lt;strong&gt;Register&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;Verify your account using the link from the verification email.&lt;/li&gt;
&lt;li&gt;Follow the prompts to create a database:

&lt;ul&gt;
&lt;li&gt;Choose the &lt;strong&gt;Free Tier&lt;/strong&gt; as the Compute Size.&lt;/li&gt;
&lt;li&gt;Select a region where you want to create the database.&lt;/li&gt;
&lt;li&gt;Enter the database details, using &lt;code&gt;betterbotz&lt;/code&gt; as the keyspace name.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After your database is created, you’re ready to create some tables!&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal 2: Create tables in your database
&lt;/h3&gt;

&lt;p&gt;Because your database runs on Apache Cassandra, we’ll be using the Cassandra Query Language (CQL) to create tables. If you’ve worked with relational databases like MySQL and Postgres, CQL is similar to SQL. The main difference is that Apache Cassandra databases are non-relational, so they use different concepts to store and retrieve data. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In your database, select the &lt;strong&gt;CQL Console&lt;/strong&gt; tab to open the CQL SHell (CQLSH).&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When prompted, enter the database username and password you set when creating the database.&lt;/p&gt;

&lt;p&gt;After entering the user credentials, the CQLSH prompt displays:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Connected to caas-cluster at caas-cluster-caas-dc-service:9042.
[cqlsh 6.8.0 | DSE 6.8.0.77 | CQL spec 3.4.5 | DSE protocol v2]
Use HELP for help.
dbuser@cqlsh&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;At the CQLSH prompt, copy and paste the following &lt;code&gt;CREATE TABLE&lt;/code&gt; statements.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: If you named your keyspace something other than &lt;code&gt;betterbotz&lt;/code&gt; when creating your database, change &lt;code&gt;betterbotz&lt;/code&gt; in the following &lt;code&gt;USE&lt;/code&gt; statement to match your keyspace name, such as &lt;code&gt;USE mykeyspace&lt;/code&gt;. This statement switches to your keyspace before running the &lt;code&gt;CREATE TABLE&lt;/code&gt; statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    USE betterbotz;

    CREATE TABLE IF NOT EXISTS products (
      id uuid,
      name text PRIMARY KEY,
      description text,
      price decimal,
      created timestamp
    );

    CREATE TABLE IF NOT EXISTS orders (
      id uuid,
      address text,
      prod_id uuid,
      prod_name text,
      description text,
      price decimal,
      sell_price decimal,
      customer_name text PRIMARY KEY
    );
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These statements create two tables in your keyspace, which is like a bucket for your tables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The first statement creates a &lt;code&gt;products&lt;/code&gt; table with several fields that define an individual product.&lt;/li&gt;
&lt;li&gt;  The second table creates an &lt;code&gt;orders&lt;/code&gt; table that includes things like product ID, product name, sell price, and other elements of an order.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Goal 3: Insert some data in your tables
&lt;/h3&gt;

&lt;p&gt;With your tables in place, it's time to insert some data.&lt;/p&gt;

&lt;p&gt;In the CQLSH prompt for your database, copy and paste the following &lt;code&gt;INSERT&lt;/code&gt; statements to insert data into the products table while using your &lt;code&gt;betterbotz&lt;/code&gt; keyspace.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO products ( id , name , description, price, created ) VALUES (31047029-2175-43ce-9fdd-b3d568b19bb0,'Heavy Lift Arms', 'Heavy lift arms capable of lifting 1,250 lbs of weight per arm. Sold as a set.',4199.99,'2019-01-10 09:48:31.020+0040')
IF NOT EXISTS;

INSERT INTO products ( id , name , description, price, created ) VALUES (31047029-2175-43ce-9fdd-b3d568b19bb1,'Precision Action Arms','Arms for precision activities in manufacturing or repair. Sold as a set.',12199.99,'2019-01-10 09:28:31.020+0040') IF NOT EXISTS;

INSERT INTO products ( id , name , description, price, created ) VALUES (31047029-2175-43ce-9fdd-b3d568b19bb2,'Medium Lift Arms','Medium lift arms capable of lifting 850 lbs of weight per arm. Sold as a set.',3199.99,'2019-01-10 09:23:31.020+0040') IF NOT EXISTS;

INSERT INTO products ( id , name , description, price, created ) VALUES (31047029-2175-43ce-9fdd-b3d568b19bb3,'Drill Arms','Arms for drilling into surface material. Sold as a set. Does not include drill bits.',2199.99,'2019-01-10 09:12:31.020+0040') IF NOT EXISTS;

INSERT INTO products ( id , name , description, price, created ) VALUES (31047029-2175-43ce-9fdd-b3d568b19bb4,'High Process AI CPU','Head processor unit for robot with heavy AI job process capabilities.',2199.99,'2019-01-10 18:48:31.020+0040') IF NOT EXISTS;

INSERT INTO products ( id , name , description, price, created ) VALUES (31047029-2175-43ce-9fdd-b3d568b19bb5,'Basic Task CPU','Head processor unit for robot with basic process tasks.',899.99,'2019-01-10 18:48:31.020+0040') IF NOT EXISTS;

INSERT INTO products ( id , name , description, price, created ) VALUES (31047029-2175-43ce-9fdd-b3d568b19bb6,'High Strength Torso','Robot body with reinforced plate to handle heavy workload and weight during jobs.',2199.99,'2019-01-10 18:48:31.020+0040') IF NOT EXISTS;

INSERT INTO products ( id , name , description, price, created ) VALUES (31047029-2175-43ce-9fdd-b3d568b19bb7,'Medium Strength Torso','Robot body to handle general jobs.',1999.99,'2019-01-10 18:48:31.020+0040') IF NOT EXISTS;

INSERT INTO products ( id , name , description, price, created ) VALUES (31047029-2175-43ce-9fdd-b3d568b19bb8,'Precision Torso','Robot torso built to handle precision jobs with extra stability and accuracy reinforcement.',8199.99,'2019-01-10 18:48:31.020+0040') IF NOT EXISTS;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For each successful INSERT statement, you’ll see a message that the statement succeeded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; [applied]
-----------
   True
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Your &lt;code&gt;products&lt;/code&gt; table has some data in it that we can work with, so let’s check it out!&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal 4: Retrieve data from your database
&lt;/h3&gt;

&lt;p&gt;Let’s view all of the available products in your &lt;code&gt;products&lt;/code&gt; table so that we know what the data looks like. Run the following &lt;code&gt;SELECT&lt;/code&gt; statement to view the name, description, and price of all products in the products table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, description, price FROM betterbotz.products ;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The results are formatted neatly, and show the name of each product, a description, and the price. This result is a good start, but as our product table grows, we don’t want to return the entire result set every time and have to sift through the results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name                  | description                                                                                 | price
-----------------------+---------------------------------------------------------------------------------------------+----------
            Drill Arms |        Arms for drilling into surface material. Sold as a set. Does not include drill bits. |  2199.99
 Precision Action Arms |                    Arms for precision activities in manufacturing or repair. Sold as a set. | 12199.99
      Medium Lift Arms |               Medium lift arms capable of lifting 850 lbs of weight per arm. Sold as a set. |  3199.99
        Basic Task CPU |                                     Head processor unit for robot with basic process tasks. |   899.99
   High Process AI CPU |                       Head processor unit for robot with heavy AI job process capabilities. |  2199.99
   High Strength Torso |           Robot body with reinforced plate to handle heavy workload and weight during jobs. |  2199.99
 Medium Strength Torso |                                                          Robot body to handle general jobs. |  1999.99
       Heavy Lift Arms |              Heavy lift arms capable of lifting 1,250 lbs of weight per arm. Sold as a set. |  4199.99
       Precision Torso | Robot torso built to handle precision jobs with extra stability and accuracy reinforcement. |  8199.99
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For example, if we wanted to retrieve only the record for the Heavy Lift Arms product, we can take our previous query and add a WHERE clause to specify the criteria we want to match. We expand our query to say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Get the name, description, and price from my products table, WHERE the name matches a specific criteria”:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, description, price FROM betterbotz.products WHERE name = 'Heavy Lift Arms';
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There it is! We returned only the record that we wanted instead of a complete list of every product in the table. Knowing how to ask for the data that you want to retrieve is crucial, because what good is a database if you can’t easily get what you need?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name            | description                                                                    | price
-----------------+--------------------------------------------------------------------------------+---------
 Heavy Lift Arms | Heavy lift arms capable of lifting 1,250 lbs of weight per arm. Sold as a set. | 4199.99
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our orders table is currently empty, but we’re going to fix that in the &lt;a href="https://dev.to/betterbotz/creating-an-express-server-for-better-botz-4b00"&gt;next post&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recap
&lt;/h2&gt;

&lt;p&gt;In this first post, you learned about Better Botz and the problem you can help solve. To lay the foundation for your online ordering application, you created a database in the cloud, created two tables, inserted data into those tables, and learned how to retrieve data that you want to view. That’s a great start!&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/betterbotz/creating-an-express-server-for-better-botz-4b00"&gt;next post&lt;/a&gt;, we’ll create a sample website built with Node.js that also uses Express. We’ll add more data to your existing cloud database and learn about Node.js as we continue to build the Better Botz online ordering application.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;p&gt;If you want to explore on your own, here are some links to learn more about CQL and CQLSH:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://docs.datastax.com/en/dse/6.7/cql/cql/cqlQuickReference.html"&gt;CQL command quick reference&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://docs.datastax.com/en/dse/6.7/cql/cql/cql_reference/cqlsh_commands/cqlshCommandsTOC.html"&gt;CQLSH command reference&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Disclaimer
&lt;/h4&gt;

&lt;p&gt;Better Botz is a fictitious company used for creating tutorials and examples. The authors of the Better Botz blog posts are employed by DataStax, and our goal is to write informative, tutorial-driven posts to help developers learn and develop skills.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>tutorial</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
