Skip to content

Instantly share code, notes, and snippets.

@LennyPenny
Created May 21, 2014 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LennyPenny/a7bcb8577e26268dfffc to your computer and use it in GitHub Desktop.
Save LennyPenny/a7bcb8577e26268dfffc to your computer and use it in GitHub Desktop.
class "database" {
public {
___onLoaded = function(self)
self:load()
end;
addTable = function(self, name)
self.tables[name] = self.tables[name] or {}
self:save()
end;
updateTable = function(self, tbl, data)
if not self.tables[tbl] or not data then return end
self.tables[tbl] = data
self:save()
end;
getTable = function(self, name)
return self.tables[name]
end;
};
private {
tables = {};
lastSaved = 0;
save = function(self)
cookie.Set("secreet", util.TableToJSON(self.tables))
self.lastSaved = CurTime()
end;
load = function(self)
local tmpData = cookie.GetString("secreet", "nope")
if tmpData == "nope" then return end
self.tables = util.JSONToTable(tmpData)
end;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment