|
2 | 2 |
|
3 | 3 | (require "main.rkt") |
4 | 4 |
|
5 | | -; create datastore |
6 | | -; delete datastore |
7 | | -; create relation name (fields) |
8 | | -; delete relation |
9 | | -; create tuple (x y z) |
10 | | -; read (x y) from relation where (u v) |
11 | | -; update (x y) in relation where (u v) |
12 | | -; delete from relation where (u v) |
13 | 5 |
|
14 | 6 | (define world (create-datastore)) |
15 | 7 |
|
16 | | -(world 'display) |
| 8 | +(world) |
| 9 | + |
| 10 | +(define bfields '(id name brawn brains moves cool karma)) |
17 | 11 |
|
18 | 12 | (define world2 |
19 | 13 | (world 'add_relation |
20 | 14 | 'brawlers |
21 | | - '(id name brawn brains moves cool karma))) |
| 15 | + bfields)) |
22 | 16 |
|
23 | | -(world2 'display) |
| 17 | +(world2) |
24 | 18 |
|
25 | 19 | (define world3 |
26 | | - (world 'add_tuples |
27 | | - 'brawlers |
28 | | - '(1 "Jack Damage" 20 0 2 10 100) |
29 | | - '(2 "Dark Okie" 18 3 14 7 100) |
30 | | - '(3 "Grey Hound" 10 0 17 0 100) |
31 | | - '(4 "Billy Gunn" 0 3 4 0 100) |
32 | | - '(5 "Doctor Braino" 0 10 0 10 100))) |
| 20 | + (world2 'create 'brawlers |
| 21 | + '((1 "Jack Damage" 20 0 2 10 100) |
| 22 | + (2 "Dark Okie" 18 3 14 7 100) |
| 23 | + (3 "Grey Hound" 10 0 17 0 100) |
| 24 | + (4 "Billy Gunn" 0 3 4 0 100) |
| 25 | + (5 "Doctor Braino" 0 10 0 10 100)))) |
33 | 26 |
|
34 | | -(world3 'display) |
| 27 | +(world3) |
35 | 28 |
|
36 | 29 | (define world4 |
37 | | - (world 'update |
38 | | - 'brawlers |
39 | | - '((brawn 21) (brains 1)) |
40 | | - '((id 1)))) |
| 30 | + (world3 'update 'brawlers |
| 31 | + '((id 1)) |
| 32 | + '((brawn 21) (brains 1)))) |
41 | 33 |
|
42 | | -(world4 'display) |
| 34 | +(world4) |
43 | 35 |
|
44 | 36 | (define brawlers |
45 | | - (world 'get_relation 'brawlers)) |
46 | | - |
47 | | -(brawlers 'display) |
48 | | - |
49 | | -(define jack |
50 | | - (brawlers 'get_tuple '(('id 1))) |
51 | | - |
52 | | -(jack 'display) |
| 37 | + (world4 'get_relation 'brawlers)) |
53 | 38 |
|
54 | | -(define new-world (create-datastore (ds init))) |
| 39 | +(brawlers) |
55 | 40 |
|
| 41 | +(define jack (car (brawlers 'read '((id 1)) '(name brawn brains moves cool karma)))) |
56 | 42 |
|
57 | | -(define fields '(x y z p q)) |
58 | | -(define tf (tuple-factory fields)) |
59 | | -(define xyzpq (tf '(1 1 2 3 5))) |
60 | | - |
61 | | -(newline) |
62 | | - |
63 | | -(xyzpq) |
64 | | -(xyzpq 'z) |
65 | | -((xyzpq 'q 8)) |
66 | | - |
67 | | -(newline) |
68 | | - |
69 | | -(define ts |
70 | | - '((1 1 2 3 5) |
71 | | - (8 13 21 34 55) |
72 | | - (0 0 2 1 0) |
73 | | - (1 1 1 1 1) |
74 | | - (0 0 0 0 0))) |
75 | | - |
76 | | -(define table (relation 'numbers fields ts)) |
| 43 | +(displayln (jack 'cool)) |
77 | 44 |
|
78 | 45 | (define (unroll xs) |
79 | 46 | (map (λ (tup) (tup)) xs)) |
80 | 47 |
|
81 | | -(table 'name) |
82 | | -(table 'fields) |
83 | | - |
84 | | -(unroll (table 'read '((x 0) (q 0)) '(y z p))) |
85 | | -((table 'read-row '((p 3)) '(x y z))) |
86 | | -(table 'read-val '((z 21)) '(q)) |
87 | | - |
88 | 48 | (unroll |
89 | | - (table 'read |
90 | | - (λ (tup) |
91 | | - (let ((total (apply + (map tup (table 'fields))))) |
92 | | - (or (= (tup 'z) 21) (and (> total 4) (< total 16))))) |
93 | | - '(x y z p q))) |
94 | | - |
95 | | -(newline) |
96 | | - |
97 | | -(table) |
98 | | - |
99 | | -(define table2 (table 'create '((8 6 7 5 3) (0 9 8 6 7) (5 3 0 9 9)))) |
100 | | - |
101 | | -(table2) |
102 | | - |
103 | | -(define table3 (table2 'update '((x 0)) '((y 3)))) |
104 | | - |
105 | | -(table3) |
106 | | - |
107 | | -(define table4 (table3 'update |
108 | | - (λ (t) (> (apply + (map t (table3 'fields))) 10)) |
109 | | - (λ (t) (let ((xyz (map t '(x y z)))) |
110 | | - (append xyz (list (apply + xyz) (apply * xyz))))))) |
111 | | - |
112 | | -(table4) |
113 | | - |
114 | | -(define table5 (table4 'delete (λ (t) (> (apply + (map t (table4 'fields))) 100)))) |
115 | | - |
116 | | -(table5) |
117 | | - |
118 | | -(define table6 (table5 'delete '((x 1)))) |
| 49 | + (world4 'read 'brawlers |
| 50 | + (λ (tup) (> (tup 'brawn) 10)) |
| 51 | + '(id name))) |
119 | 52 |
|
120 | | -(table6) |
| 53 | +(define world5 |
| 54 | + (world4 'update 'brawlers |
| 55 | + (λ (t) (> (apply + (map t '(brawn brains moves cool))) 12)) |
| 56 | + (λ (t) (map (t 'cool 37) bfields)))) |
121 | 57 |
|
| 58 | +(world5) |
122 | 59 |
|
| 60 | +(define world6 |
| 61 | + (world5 'delete 'brawlers |
| 62 | + (λ (t) (< (apply + (map t '(brawn moves))) 8)))) |
123 | 63 |
|
| 64 | +(world6) |
124 | 65 |
|
| 66 | +(world6 'relations) |
125 | 67 |
|
| 68 | +(world6 'indexes) |
126 | 69 |
|
0 commit comments