Robase - A Firebase Real-time Database Wrapper
Github Release | API Docs | Github Repo | Roblox Model |
---|
Robase is a RESTful API wrapper for Firebase Realtime Database - written in untyped Luau - for Roblox Developers seeking an external database service with a simple to use wrapper.
As mentioned, Robase seeks to be simple to use, but this is one of two core aims of this project. The second aim is to be an easy replacement to DataStoreService. You can find useful code to help with replacing old DataStore code and transferring data here.
RobaseService aims to provide a reliable and safe method of saving and loading data, no matter how big or small. But what does it offer that DataStoreService doesnāt?
-
You are no longer limited to 4MB of data per key, your database can hold 1GB of storage and you have complete control over how everything is stored.
-
You can access any key within the real-time database, simply use ā/ā to separate the keys. With DataStores you only have access to one point, making querying difficult and ensuring all data exists a slog with sanity checks.
-
Robase is open-sourced, this means that its source code is available to everyone and can be looked at and researched easily especially with the source documentation! This will make extending and wrapping RobaseService simpler and creating an extension similar to DataStore2 by @Kampfkarren or a manager like ProfileService by @loleris.
-
The methods are guaranteed to be race condition free, Robase uses Promises by @evaera to ensure race safety. Every async function will yield until a value is retrieved. There are also two methods which return promises, these are
Robase:Set()
andRobase:Get()
and are documented here -
You can update keys externally, there is no need to go into game to update a DataStore. Simply go to the Firebase Console and access your database and modify away! Entering a live game isnāt practical most of the time, this makes the process easier and more accessible - you can even do it on your phone!
For more in-depth explanation of the above points you can go to the limitations section of the API Docs.
note: In order to keep this article concise, this section will be hidden by default. Click the link above to navigate to the docs page covering this section.
Getting Started
Before you can use RobaseService you will first need to create a new Firebase project, this can be done from the Firebase Console. Once you have followed the instructions and started a new project, you will need to open the side-bar menu and go to your āRealtime Databaseā and then āCreate Databaseā, you will then have a pop-up appear configuring your database and the security rules for it.
Finding your Database Url
You can find your Database URL by going to the Firebase Console and opening up your Real-time Database. You should be met with a page that looks like this:
In the green box is your URL, it should be formatted like so:
{database-name}-default-rtdb-{server-location}.firebasedatabase.app/
NOTE: This is the baseUrl
parameter of RobaseService.new().
Finding your Database Secret
Your database secret will be serving as your authentication token for your requests, this can be created or found by following the image and step-by-step instructions below.
When you create your database a database secret should be generated automatically, but you can create more.
WARNING: You must have created your database first, if you have just created your project you will not be able to create a database secret. Read the opening paragraph of this page for help with creating your database.
- Begin by navigating to your Firebase Console
- Click on the gear icon next to āProject Overviewā
- Click āService Accountsā in the tabs that appear
- Click āDatabase Secretsā
4.a) If a secret does not this exist then āaddā (create) a new one - Hover over the secret and reveal it, then copy it and save it somewhere safe.
NOTE: The value of your database secret is the token
parameter of RobaseService.new().
RobaseService
is made to be a replication of DataStoreService
so that setup and transferring data are simple to do.
Example
Code that once looked like this:
local DataStoreService = game:GetService("DataStoreService")
local ExampleDataStore = DataStoreService:GetDataStore("Example")
local ExampleData = ExampleDataStore:GetAsync("123456789")
Will now look like this:
local RobaseServiceModule = require(path.to.robase)
local RobaseService = RobaseServiceModule.new("URL", "AUTH")
local ExampleRobase = RobaseService:GetRobase("Example")
local Success, Result = ExampleRobase:GetAsync("123456789")
Every Async
method call to a Robase
will return a Success
and a Result
, check the API Reference for more detailed information.
An in-depth usage guide can be found at the link above, it will not be covered in this post as it falls out of scope of this category.
As the API Reference page is extensive, it will be omitted in favour of the docs page that covers it. If you wish to find out more about the methods and internals of RobaseService, use the link above.
Closing
For issue reporting see here for information on the different methods.
Thank you for reading through this article. Any and all feedback is appreciated, if you like this opensource software donāt forget to like the post and if it is something you may consider using star the GitHub!