-
Notifications
You must be signed in to change notification settings - Fork 29
/
pstruct.lisp
51 lines (46 loc) · 1.8 KB
/
pstruct.lisp
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
(in-package :graph-db)
(defmacro def-doc (name attribs slots))
(def-doc customer ()
((name :type :string :validator 'valid-name-p :indexed-p t :private-p nil)
(city :type :string :validator 'valid-city-p :indexed-p nil :private-p nil)
(diseases :type :list :indexed-p nil :private-p t)))
(defun create-customer (&key name city diseases id type revision deleted-p addr bytes)
(let ((%%id (or id (gen-id)))
(%%type (or type 1))
(%%revision (or revision 0))
(%%deleted-p deleted-p)
(%%addr addr)
(%%bytes (or bytes :init))
(%name name)
(%city city)
(%diseases diseases))
(lambda (msg &optional arg)
(case msg
(:type %%type) ;;(gethash %%type *doc-type-table*))
(:id %%id)
(:rev %%revision)
(:deleted-p %%deleted-p)
(:addr %%addr)
(:name %name)
(:city %city)
(:diseases %diseases)
(:delete! (setq %%deleted-p t))
(:set-name! (setq %name arg))
(:set-city! (setq %city arg))
(:set-diseases! (setq %diseases arg))
;;(:lookup-by-name (lookup-customer-by-name arg))
(:lastest-rev-p t) ;;(lastest-rev-p %%id))
(:as-json (json:encode-json `((:name . ,%name)
(:city . ,%city)
(:inactive . ,(null %%deleted-p))
(:id . ,%%id)
(:rev . ,%%revision))))
(:save nil) ;; FIXME: serialize
(:bytes %%bytes)
))))
(defun lookup-customer (id)
(let* ((bytes (deserialize-customer (lookup-pointer id)))
(type (deserialize-doc-type bytes)))
(create-customer :id (deserialize-doc-id bytes)
:type (deserialize-doc-type bytes)
: