You can jump right in and follow this basic phone book tutorial where you'll learn how to perform the fundamental "CRUD" (Create, Read, Update, Delete) operations with Repl.it Database.
Database is a simple and easy-to-use key-value store inside of every repl. There is no configuration—just start using it! Here's how:
When viewing your repl, you'll see the Database icon toward the bottom of the sidebar. That’s Repl.it’s new key-value database, built right into your repl!
To access Database, you can use a library or simple curl commands.
Replit provides official clients:
We recommend using the above clients if your repl is in one of those languages.
When you click on the Database icon in the sidebar, you'll see some instructions. If your repl is in a language that has an official Database client, you can quickly import it and start using Database by clicking on the "Insert" buttons.
If your language does not have a client, we provide some curl examples. They are also found below. These are a useful reference if you wish to write your own Database client.
curl $REPLIT_DB_URL -d '<key>=<value>'
If your key and value don't use any unsafe characters, you can use an alternative version:
curl -XPOST $REPLIT_DB_URL/<key>=<value>
curl -XDELETE $REPLIT_DB_URL/<key>
Delete returns status code 204 if the key was deleted or 404 if the key did not exist.
curl $REPLIT_DB_URL --get -d 'prefix=<key>'
The returned keys will be separated by newlines.
Listing also takes a query parameter:
encode=true. If set, the returned keys
will be URL encoded. This lets you safely handle keys that contain newlines.
This is the environment variable we have created with your repl. It is the key that will allow you to access your database.
The clients listed above take care of using
REPLIT_DB_URL for you. But if you want to write your own client or use Database from a language that doesn't yet have a client, here are two examples:
import os print(os.getenv("REPLIT_DB_URL"))
REPLIT_DB_URL provides full access to your database. Therefore, you should take care not to expose it to the world or share it with people you don't trust.
The value of
REPLIT_DB_URL changes from time to time, so we recommend that you not copy it elsewhere. Subsequent reads by the same process will see the same value. We will restart your repl if we need to change it after it has been read.
The limits are currently:
There are rate limits that apply to all operations. You will receive an HTTP 429 if you exceed them. We recommend implementing an exponential backoff and retry to handle this case.
The Database sidebar shows you the number of keys in your database along with the total storage occupied by your keys and values.
Yes, each Database is private and isolated. Every repl has its own database, and they are not shared among repls.
The easiest way to do this is to use one repl as the primary database and have other repls connect to it via web hosting. Here’s an example repl in Python: https://repl.it/@util/Replit-Database-proxy
Any requests sent to the above repl will operate on its database, so sending requests to it from other repls means that they all share the same information.