-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelations.lua
More file actions
38 lines (33 loc) · 1.34 KB
/
relations.lua
File metadata and controls
38 lines (33 loc) · 1.34 KB
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
37
38
-- yours package
---@class YoursPackage: Atomic.Package
local package = current()
local MeadowsORM = package:getDependency("team.meadows.orm")
---@cast MeadowsORM MeadowsORM
--- importing basic constraints
local NOT_NULL = MeadowsORM.NOT_NULL
local UNIQUE = MeadowsORM.UNIQUE
local DEFAULT_JSON_ARRAY = MeadowsORM.DEFAULT_JSON_ARRAY
local SET_NULL = MeadowsORM.SET_NULL
local SET_DEFAULT = MeadowsORM.SET_DEFAULT
local RawSQL = MeadowsORM.RawSQL
local groups = MeadowsORM:create("groups")
:id()
:column("name", "varchar(32)", NOT_NULL + UNIQUE)
:column("permissions", "json", NOT_NULL, DEFAULT_JSON_ARRAY)
:column("inherits", "int", NOT_NULL)
-- column `inherits` is related to this table's column `id`
-- relation groups.id <-> groups.inherits
:relation("inherits", "id", SET_NULL)
-- and if you'll remove an group (row) from groups
-- the relation will set to null (ON DELETE = SET NULL)
:build()
local users = MeadowsORM:create("users")
:id()
:column("steam_id", "varchar(32)", NOT_NULL + UNIQUE)
:column("group", "int", NOT_NULL, RawSQL("1")) -- default group = 1
-- column `group` is related to groups's table column `id`
-- relation users.group <-> groups.id
:relation(groups, "group", "id", SET_DEFAULT)
-- if you'll remove an group (row) from groups
-- group of an user will set to default (ON DELETE = SET DEFAULT)
:build()