Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Create a No-Code REST API Using Xano!
You have completed Create a No-Code REST API Using Xano!
Preview
In this video, you'll learn how to create database tables with relationships, validation rules, and proper data structures for users, products, reviews, and orders in Xano's visual interface.
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Let's start building our marketplace
by clicking on Database
0:00
in the nav bar on the left.
0:03
You'll notice
0:07
that we already have a users
table set up for us.
0:08
This is because we checked
the authentication option
0:12
during our workspace setup.
0:15
The users table comes
with all the essential fields we need.
0:18
An ID for unique identification,
timestamps to track
0:22
when the user was created,
plus name, email, and a securely hashed
0:26
password field.
0:32
Now let's create
our first table for the products.
0:34
Click the Add Table
button in the top right corner.
0:38
While Xano offers the ability to import
0:43
existing data from CSV files or Airtable,
0:45
we'll build our table structure manually.
0:50
We'll name this table Product
0:54
and leave the AutoCreate CRUD
0:56
API Endpoints option checked.
0:58
This will automatically generate
the routes we need to create,
1:02
read, update, and delete records.
1:06
After clicking Add Table,
1:11
we're presented with a new window
1:13
where we can define our table structure.
1:15
Notice
that Xano automatically includes an ID
1:19
and created at field for us.
1:22
Let add some additional fields by clicking
1:27
the plus icon at the end of the table
1:29
First we have to choose a field type
1:34
to use for this field
We start with the product name
1:36
which will be the text field
and we give it a name of name
1:40
Every field in Xano
can have a description,
1:45
making it easier for team members
to understand the purpose of each column.
1:48
We'll mark this field as required
1:54
since every product
needs a name, and confirm
1:56
by clicking the Add Column button.
2:00
Next, we'll add a description
2:04
field, also as text, but this time
we'll allow it to be nullable
2:06
since not every product
might need a detailed description.
2:12
For the price
2:19
field, we'll use an integer type
2:20
and add price in cents as the description.
2:23
Storing prices as cents is a common
2:28
practice to avoid precision issues
with decimals.
2:31
This field will be required as well.
2:35
Finally,
2:44
we'll create a relationship
between products and users
2:45
by adding a table reference field.
2:50
This powerful feature in Xano handles
2:53
all of the database
relationship complexity for us.
2:56
We'll reference the users table
3:00
and name this field seller ID.
3:04
the description owner of the product
3:09
By making this field required
3:16
we ensure that
every product in our marketplace
3:18
has an owner
3:22
That sets up the basic structure
for our products.
3:25
Let's create our orders table next.
3:29
Click Add a Table again and name it Order.
3:32
This table will track the purchases
made in our marketplace.
3:38
We'll keep it simple with just two table
3:43
reference fields, user ID,
3:45
linking to the buyer,
3:48
and product ID,
connecting to the purchased product.
3:51
Both fields are
3:55
required to ensure data integrity.
3:57
We always want to know who bought what.
4:00
In a production environment,
4:04
you might want to expand this table
with fields Status
4:06
to track order statuses, Transaction
ID for payment processing,
4:09
or Download Count to limit access.
4:14
But for this workshop,
we'll stick to the Essential
4:18
Relationships.
4:20
For our final table,
4:24
let's add a Review functionality.
4:25
Create a new table called Review.
4:28
First add an integer field called Rating
4:36
This will be required
4:47
Xano lets us add
4:50
validation rules at the database level
4:51
So scroll down to custom rules
and set a minimum
4:55
value of one
4:59
and maximum of five
5:05
This enforces a five rating system
5:08
right in the database.
5:11
Next, add a comment text field.
5:16
But we'll make this nullable
5:24
since some users might just want to leave
a star rating without writing a review.
5:25
We'll
5:34
need two relationship fields for reviews.
5:34
User ID, referencing the user's table
to track who wrote the review,
5:37
and Product ID,
linking to the product being reviewed.
5:43
Both these fields should be required.
5:48
Every review needs an author
and a product.
5:50
These relationships will make it easy
to show all reviews for a product
5:54
or all reviews written by a specific user.
5:59
That completes our database structure
for the digital marketplace.
6:04
We have users who can sell products, users
who can buy products
6:08
through orders,
and users can leave reviews.
6:13
In the next video,
we'll start working with the API
6:17
endpoints that Xano has generated for us
6:20
and create some custom endpoints
to handle specific business logic.
6:24
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up