A simple back-end for the practice-frontend repo showing how to join a one-to-many relationship with Knex query builders.
Note This app is hard-coded to run on localhost:3001
createdb practice_dev
psql practice_dev
knex migrate:latest
knex seed:run
npm install
npm start
This app has two tables: users and shares. Should we put everything in one table?
id | text | |
---|---|---|
1 | first1.last1@gmail.com | hey |
2 | first2.last2@gmail.com | hi |
id | text | |
---|---|---|
1 | first1.last1@gmail.com | hey |
2 | first2.last2@gmail.com | hi |
1 | first1.last1@gmail.com | bye |
After running steps above, go to http://localhost:3001/shares in the browser to see shares from all users. Now go to http://localhost:3001/users/1/shares to see shares from just user 1.
How does this work? Take 10 minutes to explore the database tables created by migrations, look at the routes, and play with the app.
\d
to see tables\d table-name
to see columns in a tableselect * from table-name;
to see data in table
id | |
---|---|
1 | first1.last1@gmail.com |
2 | first2.last2@gmail.com |
id | text | user_id |
---|---|---|
1 | hey | 1 |
2 | hi | 2 |
3 | bye | 1 |