FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
orm/examples/cache.lua at develop · TeamMeadows/orm · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
TeamMeadows
/
orm
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
orm
/
examples
/
cache.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (58 loc) · 1.93 KB
Breadcrumbs
orm
/
examples
/
cache.lua
Copy path
File metadata and controls
72 lines (58 loc) · 1.93 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--
Entity is a basic class, that implements logic to automatically update
---
@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
RawSQL
=
MeadowsORM
.
RawSQL
local
database
=
MeadowsORM
:
create
(
"
users
"
)
:
id
()
:
column
(
"
steam_id
"
,
"
varchar(32)
"
,
NOT_NULL
+
UNIQUE
)
:
column
(
"
money
"
,
"
int
"
,
NOT_NULL
,
RawSQL
(
"
0
"
))
:
index
(
"
steam_id
"
,
false
,
true
)
--
index also being used for fast search in cache (O(1))
:
cache
()
--
applying cache (TableCache class)
:
build
()
---
Example №1 - find query
local
function
loadUser
(
player
)
local
user
=
database
:
findUnique
({
where
=
{
steam_id
=
player
:
SteamID
()
},
cache
=
true
--
inserting found row in cache = true
})
if
(
not
user
)
then
user
=
database
:
create
({
data
=
{
steam_id
=
player
:
SteamID
()
},
cache
=
true
--
insering new created row in cache = true
})
end
end
---
@param
player
Player
---
@return
YoursPackage.User
?
local
function
getUser
(
player
)
local
cache
=
database
:
getCache
()
--
O(1) user get
return
cache
:
findIndexed
(
"
steam_id
"
,
player
:
SteamID
())
end
---
@param
money
integer
---
@param
operation
?
MeadowsORM.WhereBuilder.WhereCompareIndexes
local
function
getUsersWithMoney
(
money
,
operation
)
local
cache
=
database
:
getCache
()
--
O(n) users get
return
cache
:
find
(
"
money
"
,
money
,
operation
or
"
eq
"
)
end
local
user
=
getUser
(
Player
(
1
))
print
(
user
and
user
:
getMoney
())
--
find users with money=1000
getUsersWithMoney
(
1000
)
--
find users with money>1000
getUsersWithMoney
(
1000
,
"
gt
"
)
--
gt = greater than
--
find users with money>=1000
getUsersWithMoney
(
1000
,
"
gte
"
)
--
gte = greater than and equals
--
find users with money<1000
getUsersWithMoney
(
1000
,
"
lt
"
)
--
lt = less than
--
find users with money<=1000
getUsersWithMoney
(
1000
,
"
lte
"
)
--
lte = less than and equals
Back
|
FazBrowse Home
|
New Git URL