Here you will find an API that allows you to easily play around with restdb.io as a database: https://www.roblox.com/library/4747902960/RestDB-io-API.
Notice: This API uses a Heroku Proxy Service. I currently use a free one created by Sentanos; you can find it here: https://elements.heroku.com/buttons/sentanos/proxyservice. I won’t go too much into detail about this but all you need from this is the url and the access key (which you can find in the config vars).
Anyways, here’s some documentation on this API.
local rest_db = require(game:GetService("ServerScriptService").RestDB)
rest_db:SetDBUrl(string DatabaseName) -- for example, "roblox"; you do not need to put the full url, just the name of your database
rest_db:SetDBKey(string DatabaseAPIKey) -- for example "123456789", you can find this key in Developer Mode on restdb.io
rest_db:SetProxyUrl(string ProxyUrl) -- for example, "https://something.herokuapp.com/"
rest_db:SetProxyKey(string ProxyKey) -- for example, "123456789"; found in config vars on Heroku
rest_db:InitProxy() -- you must run this after setting your url and key
Now that we’ve set it up, we can do something like getting a collection:
rest_db:GetCollection(string CollectionName) -- for example, "users"
This will return all of the documents inside the collection, if you do not have any documents inside, or the collection does not exist, you will receive an error.
You can add documents to a collection:
rest_db:AddDocument(string CollectionName, table DocumentFields)
-- for example:
rest_db:AddDocument("users", {["name"] = "xJDiviisionZ"})
-- will create a document with the body: {"name": "xJDiviisionZ"}
-- note: this function WILL return the document too, so
-- you can use variables to define this document so you can
-- retrieve it later
-- for example:
local new_doc = rest_db:AddDocument("users", {["name"] = "xJDiviisionZ"})
-- say you wanted to delete this document:
rest_db:DeleteDocument(string CollectionName, string id)
-- therefore
rest_db:DeleteDocument("users", new_doc._id)
-- note: it MUST be _id not id - simply the way restdb.io is setup
You can also update a document:
local new_doc = rest_db:AddDocument("users", {["name"] = "xJDiviisionZ"})
local updated_doc = rest_db:UpdateDocument("users", new_doc._id, {["name"] = "xjdiviisionz"})
-- again, :UpdateDocument() ALSO returns the document
-- allowing you to use variables to store the document for later use
I know I already showcased this but just to be clear on everything covered, you can also delete documents:
local new_doc = rest_db:AddDocument("users", {["name"] = "xJDiviisionZ"})
local updated_doc = rest_db:UpdateDocument("users", new_doc._id, {["name"] = "xjdiviisionz"})
rest_db:DeleteDocument("users", updated_doc._id)
Finally, you can verify a collection (whether it is empty or exists) by doing:
local collection = "users"
local ver = rest_db:Verify(string CollectionName)
if ver then
print(collection.." exists.")
else
print(collection.." is either empty or does not exist.")
end