Skip to main content

PersistentDatabase

Stores JSON data into database.

🗿Static Class
This is a Static Class. Access it's methods directly with .. It's not possible to spawn new instances.
💂Authority
This static class can be accessed only on 🟦 Server side.

Usage Limits

  • 65536 keys limit.
  • 10 input / output operations per minute.
  • Each key can be a maximum of 4 Kb.

Examples

local json = JSON.stringify({ scriptingKey1 = "My data", scriptingKey2 = false, scriptingKey3 = 123, scriptingKey4 = { objKey1 = "My object data",  objKey2 = true}})
local key = "UniqueKey"

function InsertIntoDatabase(key, json)
PersistentDatabase.Insert(key, json, function(success)
if success then
print("Key " .. key .. " inserted.") -- Key UniqueKey inserted.
end
end)
end

function GetMyKey(key)
PersistentDatabase.GetByKey(key, function(success, data)
if success then
print(data) -- [{"id":"f49cee2a-900f-4e1f-91e7-44e4a02b024a","key":"UniqueKey","user_id":"eeed3229-47e6-4130-9904-e5bab2deaa32","value":{"scriptingKey1":"My data","scriptingKey2":false,"scriptingKey3":123,"scriptingKey4":{"objKey1":"My object data","objKey2":true}}}]
local json_ret = JSON.parse(data) -- Parse JSON data
print(json_ret[1]["value"]["scriptingKey1"]) -- My data
end
end)
end

PersistentDatabase.Create(function(success)
if success then
print("New space created.")
InsertIntoDatabase(key, json)
GetMyKey(key)
end
end)

Static Functions

ReturnsNameDescription
CreateCreate new space into database.
InsertInsert new JSON data into database.
UpdateUpdate JSON data for a specific key.
DeleteDelete a key from database.
GetByKeyQuery a specific key from database.
GetAllQuery all data from database.
GetSummaryReturns a brief summary of database usage

Create

Create new space into database.

PersistentDatabase.Create(callback?)
TypeParameterDefaultDescription
functioncallback?nilThe result will be called in the format `function(success)`

Insert

Insert new JSON data into database.

PersistentDatabase.Insert(key, data, callback?)
TypeParameterDefaultDescription
stringkeyThe data key to query.
stringdataData to be inserted in JSON format.
functioncallback?nilThe result will be called in the format `function(success)`

Update

Update JSON data for a specific key.

PersistentDatabase.Update(key, data, callback?)
TypeParameterDefaultDescription
stringkeyThe data key to query.
stringdataData to be updated in JSON format.
functioncallback?nilThe result will be called in the format `function(success)`

Delete

Delete a key from database.

PersistentDatabase.Delete(key, callback?)
TypeParameterDefaultDescription
stringkeyThe data key to query.
functioncallback?nilThe result will be called in the format `function(success)`

GetByKey

Query a specific key from database.

PersistentDatabase.GetByKey(key, callback?)
TypeParameterDefaultDescription
stringkeyThe data key to query.
functioncallback?nilThe result will be called in the format `function(success, data)`, `data` can be parsed with JSON.parse() function.

GetAll

Query all data from database.

PersistentDatabase.GetAll(callback?)
TypeParameterDefaultDescription
functioncallback?nilThe result will be called in the format `function(success, data)`, `data` can be parsed with JSON.parse() function.

GetSummary

Returns a brief summary of database usage

PersistentDatabase.GetSummary(callback?)
TypeParameterDefaultDescription
functioncallback?nilThe result will be called in the format `function(success, data)`, `data` can be parsed with JSON.parse() function.

Events

This entity doesn't have own events.