-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-fetch.golo
69 lines (57 loc) · 1.26 KB
/
02-fetch.golo
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
module fetchall
import artemia.redis
----
id is mandatory for "artemia model"
----
struct human = {
id
, firstName
, lastName
}
augment human {
function display = |this| ->
println(
"Human: id="+ this: id() +
" firstName=" + this: firstName() +
" lastName=" + this: lastName()
)
}
struct animal = {
id, name, species
}
----
redis helper
----
struct redisHelper = {
db, models, model
}
augment redisHelper with jedisCollection
----
fetch all humans
run it:
golo golo --classpath jars/*.jar --files imports/artemia.jedis.collection.golo 02-fetch.golo
----
function main = |args| {
let redis = jedis("localhost", 6379)
let humansCollection =
redisHelper()
: model(human())
: db(redis)
let animalsCollection =
redisHelper()
: model(animal())
: db(redis)
# give me Bob
println("=== Who is this Bob ===")
let bob = humansCollection: fetch("bob_morane")
bob: display()
# fetch all human
println("=== All humans ===")
humansCollection: fetchAll("*"): each(|human| -> human: display())
# fetch Doe Family
println("=== Doe Family ===")
humansCollection: fetchAll("*_doe"): each(|human| -> human: display())
# fetch all animals
println("=== All animals ===")
animalsCollection: fetchAll("*"): each(|animal| -> println(animal))
}