-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.lua
More file actions
36 lines (29 loc) · 933 Bytes
/
json.lua
File metadata and controls
36 lines (29 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- yours package
---@class YoursPackage: Atomic.Package
local package = current()
local MeadowsORM = package:getDependency("team.meadows.orm")
---@cast MeadowsORM MeadowsORM
local NOT_NULL = MeadowsORM.NOT_NULL
local UNIQUE = MeadowsORM.UNIQUE
local DEFAULT_JSON_ARRAY = MeadowsORM.DEFAULT_JSON_ARRAY
-- creating (defining) an database table
local database = MeadowsORM:create("groups")
:id() -- add `id` column
:column("name", "varchar(16)", NOT_NULL + UNIQUE)
:column("permissions", "json", NOT_NULL, DEFAULT_JSON_ARRAY) -- default = [] (empty array)
:build() -- required! do not forget to call this method
---@param name string
local function loadGroup(name)
async(function()
local group = database:findUnique({
where = {
name = name
}
})
if (not group) then
return
end
print(#group.permissions) -- length of `permissions` column's array
end)
end
loadGroup("admin")