Learn the basics of RethinkDB and ReQL(RethinkDB query language) through building a simple chat app.
This repo teaches you the basics of ReQL by having the user write ReQL queries to get this chat app to work.
Setup: Install RethinkDB and Node.js
If using Mac:
brew install rethinkdb brew install node
After installing RethinkDB and Node.js, go the root directory of the repo and install all dependencies.
You can now run the node server using the following command:
# Mac and Linux npm run dev # Windows node server
After starting your server, go to http://localhost:8000 on your browser.
To get started, take a look at the instructions in the server/index.js file
After starting node and creating the necessary tables, you can now start writing ReQL queries to complete the excercise.
Complete all 3 steps to get the chat app working. Each step will involve writing a ReQL query to get a part of the app working.
- Inserting messages: /server/index.js:122
- Getting messages: /server/index.js:L74
- Listening for messages: /server/index.js:L101
After completing these 3 steps, your chat app will run correctly.
If you get stuck:
Don't spend more than 10 minutes on any single step. If you get stuck, there are branches with the solutions for each step. Consult these branches and move on to the next one.
If you finish with all steps, consider implementing some of the following features:
- Adding rooms to chat app
- Displaying users in room/chat
- Add multiple nodes to the RethinkDB cluter
- Add message search
- Add message liking
- Add the ability to delete messages
Step 1 : Inserting messages
Insert a document into the
messages table with the following attributes:
`text`: A string with the message text from the user `email`: An email address that exists in the `users` table `created`: A Unix Timestamp `(new Date()).getTime()`
There is no need for a callback.
Once you write this query, you'll be able to insert new messages in the front-end and see them in the database
Step 2: Getting messages
Write a query that gets all messages, ordered by
created (a secondary index)
Return the messages array as a JSON document through
Once you have written this query, you'll be able to see all previously inserted messages when loading the page
Step 3 : listening for messages
Write a query that listens to changes in the
HINT: the query will return a cursor, not an array
HINT: the objects return by the cursor have a
new_val and an
Every time a change is pushed by the database, push that change to the client by emitting a socket event:
Once you write this query, you'll be able to see new messages be displayed as they are being added