mumps-demo/06-databases/basic-sql-blog/Main.m

94 lines
2.1 KiB
Mathematica
Raw Normal View History

2019-09-27 16:06:39 -04:00
2019-09-28 17:46:15 -04:00
zlink "routines/Category"
zlink "routines/Comment"
zlink "routines/Database"
zlink "routines/Post"
zlink "routines/User"
2019-09-27 16:06:39 -04:00
; create users
s ok=$$set^User(1,"alice~password~alice-jones@no-reply.com~Alice Jones")
s ok=$$set^User(2,"bob~password~bob-smith@no-reply.com~Bob Smith")
2019-09-28 17:46:15 -04:00
; create categories
s ok=$$set^Category(1,"foo~Foo")
s ok=$$set^Category(2,"bar~Bar")
s ok=$$set^Category(3,"foobar~Foobar")
2019-09-27 16:06:39 -04:00
2019-09-28 17:46:15 -04:00
; create posts
;
; s ok=$$set^Post(1, ...
; post id
; s ok=$$set^Post(1,1, ...
; category id
; s ok=$$set^Post(1,1,1 ...
; user id
s ok=$$set^Post(1,1,1,"lorem-ipsum~Lorem ipsum~Lorem ipsum dolor sit amet, consectetuer adipiscing elit.")
s ok=$$set^Post(2,1,1,"donec-pede-justo~Donec pede justo~Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.")
2019-09-28 18:20:15 -04:00
s ok=$$set^Post(3,3,2,"curabitur-ullamcorper-ultricies~Curabitur ullamcorper ultricies~Curabitur ullamcorper ultricies nisi.")
2019-09-28 17:46:15 -04:00
s ok=$$set^Post(4,3,2,"donec-vitae-sapien~Donec vitae sapien~Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante.")
2019-09-27 16:06:39 -04:00
; create comments
s ok=$$set^Comment(1,1,"This is awesome! Thank you.")
s ok=$$set^Comment(2,2,"Thank you so much for sharing this.")
2019-09-29 06:25:27 -04:00
; write redords
write "Users: ",!
zwrite ^users
write !,"Categories: ",!
zwrite ^categories
write !,"Posts: ",!
zwrite ^posts
write !,"Comments: ",!
zwrite ^comments
2019-09-28 18:20:15 -04:00
; fetch a category
2019-09-28 17:46:15 -04:00
2019-09-28 18:35:31 -04:00
s id=3
do fetch^Category(id,.data)
2019-09-29 06:25:27 -04:00
w !,"Category fetched (",id,"):",!
zwrite data
2019-09-28 17:46:15 -04:00
2019-09-28 18:20:15 -04:00
; fetch a post
2019-09-27 16:06:39 -04:00
2019-09-28 18:35:31 -04:00
s id=1
do fetch^Post(id,.data)
w !,"Post fetched (",id,"):",!
2019-09-29 06:25:27 -04:00
zwrite data
2019-09-27 16:06:39 -04:00
2019-09-28 18:20:15 -04:00
; fetch posts by category
2019-09-28 18:35:31 -04:00
s id=3
do fetchByCategory^Post(id,.data)
2019-09-28 18:36:55 -04:00
w !,"Posts fetched by category (",id,"):",!
2019-09-29 06:25:27 -04:00
zwrite data
2019-09-27 16:06:39 -04:00
; fetch posts by user
2019-09-28 18:35:31 -04:00
s id=1
do fetchByUser^Post(id,.data)
2019-09-28 18:36:55 -04:00
w !,"Posts fetched by user (",id,"):",!
2019-09-29 06:25:27 -04:00
zwrite data
2019-09-28 17:46:15 -04:00
2019-09-28 18:20:15 -04:00
; fetch a comment
2019-09-27 16:06:39 -04:00
2019-09-28 18:35:31 -04:00
s id=1
do fetch^Comment(id,.data)
w !,"Comment fetched (",id,"):",!
2019-09-29 06:25:27 -04:00
zwrite data
2019-09-27 16:06:39 -04:00
; drop database
s ok=$$drop^Database()
i ok=1 d
. w !,"Database successfully dropped!",!
e d
. w "Whoops! The database could not be dropped.",!