⚠️ This lesson is retired and might contain outdated information.

Create Tables on Hasura

Ali Spittel
InstructorAli Spittel
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 2 years ago

Over the course of the next few videos, we will be creating a simplified Twitter clone with users and statuses on Hasura. We will create two tables, users and statuses and add a foreign key between them. We'll also populate the databases using Hasura's interface.

Ali Spittel: [0:00] We go into the Data tab in order to create some tables. The first table that we're going to create is the users' table. Click Add Table, and then add in a table name. I'm going to call it users.

[0:19] Then we're going to add some columns. First, I'm going to create ID, which will be an auto-incrementing integer, which needs to be unique. It's going to be our Primary Key field, so I'll go ahead and select that. We're also going to have a username which is going to be a Text field. Once I've done that, I'm going to scroll down and click the Add Table button.

[0:48] Now, I'm going to click that Add Table button again and create a statuses table. This one's going to have the column ID, which again is going to be that auto-incrementing Primary Key. I'm going to also have created_at field which is going to be a Timestamp. I'm going to put now() there. I'm also going to add in text. This will be a Text field.

[1:31] Then my final one is going to be user_id which will be an integer. That one's going to be a Foreign Key. This one is going to connect my statuses to my users, so users can have statuses. My user_id column in my status table is going to reference my ID column in my users table.

[1:59] I'm going to click Save and Add Table. Hasura's also going to create us some forms so we can add data. If you click on Insert Row, you can add some users. Now, I have two users, which I can see in my Browse Rows tab.

[2:28] Then I'm going to add some statuses. You can go back to the Browse Rows and see my IDs and created_at were done for me. They both also have text and the user that they reference.

[2:56] In summary, we created some tables. We added some columns, including a relationship between two tables, and then we added data to our database.

egghead
egghead
~ 20 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today