Advertisement
Guest User

Untitled

a guest
Nov 12th, 2021
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.92 KB | None | 0 0
  1. # ../pil21/pil plisp.l -rule~main -go +
  2. # http://localhost:8080/?-A67
  3.  
  4. (allowed NIL
  5.    "@lib.css" "!rule.json" "!test.json")
  6.  
  7. (load "@lib/http.l" "@lib/xhtml.l" "@lib/json.l")
  8.  
  9. (symbols 'rule 'pico)
  10.  
  11. ### DB ###
  12. (class +Rule +Entity)
  13. (dm T @ (put> This 'id (genKey 'id '+Rule)) (pass super))
  14. (rel id (+Need +Key +Number)) #Id
  15. (rel name (+String))      # Name
  16. (rel version (+Number))
  17. (rel updatedAt (+Number))
  18. (rel createdAt (+Number))
  19. (rel result (+Ref +String))
  20. (rel content (+Ref +String))
  21. (rel ruleType (+Joint) ruleTypes (+RuleType))
  22.  
  23. (class +RuleType +Entity)
  24. (dm T @ (put> This 'id (genKey 'id '+RuleType)) (pass super))
  25. (rel id (+Need +Key +Number)) #RuleType
  26. (rel name (+Idx +String))
  27.  
  28. (dbs
  29.  (0)
  30.  (1 +RuleType)
  31.  (2 +Rule)
  32.  (2 (+RuleType id name))
  33.  (3 (+Rule name))
  34.  (2 (+Rule id))
  35. )
  36.  
  37.                                         #
  38. (de test ()
  39.     (request! '(+RuleType) 'name "Test")
  40.     )
  41.  
  42. (de test.json (This)
  43.     (msg This)
  44.     (test)
  45.     (httpHead "application/json" 0)
  46.     (ht:Out *Chunked
  47.             (printJson "I have added something into database")))
  48.  
  49. (de rule.json (This)
  50.    (httpHead "application/json" 0)
  51.    (msg This)
  52.    (ht:Out *Chunked
  53.            (printJson
  54.             (mapcar
  55.              '((X)
  56.                (cons
  57.                 (cdr X)
  58.                 (cond
  59.                  ((num? V) (datStr V)) # Can only be date
  60.                  ((isa '+RuleType V) (do
  61.                                          (msg "df")
  62.                                          ( ; V nm
  63.                                           )))
  64.                  ((isa '+Rule V) (; V nm
  65.                                   ))
  66.                  ((pair V) (mapcar '((This) (: nm)) V) )
  67.                  (T V))))
  68.              (db 'name '+RuleType This)))))
  69.  
  70. ### RUN ###
  71. (de main ()
  72.    (symbols '(rule pico))
  73.    (pool "rule/" *Dbs) )
  74.  
  75. (de go ()
  76.     (rollback)
  77.     (server 8080 '("!test.json" "!rule.json")) )
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement