This commit is contained in:
programarivm 2019-09-29 11:25:27 +01:00
parent 7d368b805b
commit ccd26d579e
3 changed files with 99 additions and 70 deletions

View File

@ -35,54 +35,54 @@
s ok=$$set^Comment(1,1,"This is awesome! Thank you.") s ok=$$set^Comment(1,1,"This is awesome! Thank you.")
s ok=$$set^Comment(2,2,"Thank you so much for sharing this.") s ok=$$set^Comment(2,2,"Thank you so much for sharing this.")
; write redords
write "Users: ",!
zwrite ^users
write !,"Categories: ",!
zwrite ^categories
write !,"Posts: ",!
zwrite ^posts
write !,"Comments: ",!
zwrite ^comments
; fetch a category ; fetch a category
s id=3 s id=3
do fetch^Category(id,.data) do fetch^Category(id,.data)
w "Category fetched (",id,"):",! w !,"Category fetched (",id,"):",!
w "description: ",data("description"),! zwrite data
; fetch a post ; fetch a post
s id=1 s id=1
do fetch^Post(id,.data) do fetch^Post(id,.data)
w !,"Post fetched (",id,"):",! w !,"Post fetched (",id,"):",!
w "slug: ",data("slug"),! zwrite data
w "title: ",data("title"),!
w "description: ",data("description"),!
; fetch posts by category ; fetch posts by category
s id=3 s id=3
do fetchByCategory^Post(id,.data) do fetchByCategory^Post(id,.data)
w !,"Posts fetched by category (",id,"):",! w !,"Posts fetched by category (",id,"):",!
s lev1="" zwrite data
s lev2=""
s lev3=""
f s lev1=$o(data(lev1)) q:lev1="" d
. f s lev2=$o(data(lev1,lev2)) q:lev2="" d
. . f s lev3=$o(data(lev1,lev2,lev3)) q:lev3="" d
. . . w "(",lev1,",",lev2,",",lev3,") = ",data(lev1,lev2,lev3),!
; fetch posts by user ; fetch posts by user
s id=1 s id=1
do fetchByUser^Post(id,.data) do fetchByUser^Post(id,.data)
w !,"Posts fetched by user (",id,"):",! w !,"Posts fetched by user (",id,"):",!
s lev1="" zwrite data
s lev2=""
s lev3=""
f s lev1=$o(data(lev1)) q:lev1="" d
. f s lev2=$o(data(lev1,lev2)) q:lev2="" d
. . f s lev3=$o(data(lev1,lev2,lev3)) q:lev3="" d
. . . w "(",lev1,",",lev2,",",lev3,") = ",data(lev1,lev2,lev3),!
; fetch a comment ; fetch a comment
s id=1 s id=1
do fetch^Comment(id,.data) do fetch^Comment(id,.data)
w !,"Comment fetched (",id,"):",! w !,"Comment fetched (",id,"):",!
w "description: ",data("description"),! zwrite data
; drop database ; drop database

View File

@ -6,64 +6,66 @@
s ok=$$set^User(1,"alice~password~alice-jones@no-reply.com~Alice Jones") s ok=$$set^User(1,"alice~password~alice-jones@no-reply.com~Alice Jones")
i ok=1 d i ok=1 d
. w "User successfully created!",! . w "User created:",!
. zwrite ^users(1)
e d e d
. w "Whoops! The user could not be created.",! . w "Whoops! The user could not be created.",!
s ok=$$set^User(2,"bob~password~bob-smith@no-reply.com~Bob Smith") s ok=$$set^User(2,"bob~password~bob-smith@no-reply.com~Bob Smith")
i ok=1 d i ok=1 d
. w "User successfully created!",! . w !,"User created:",!
. zwrite ^users(2)
e d e d
. w "Whoops! The user could not be created.",! . w !,"Whoops! The user could not be created.",!
; fetch a user ; fetch a user
s ok=$$fetch^User(1,.data) s id=1
s ok=$$fetch^User(id,.data)
i ok=1 d i ok=1 d
. w !,"User successfully fetched!",! . w !,"User fetched (",id,"):",!
. w "username: ",data("username"),! . zwrite data
. w "email: ",data("email"),!
. w "fullname: ",data("fullname"),!
e d e d
. w "Whoops! The user could not be fetched.",! . w !,"Whoops! The user could not be fetched.",!
; update a user ; update a user
s ok=$$set^User(1,"amelia~password~amelia-roberts@no-reply.com~Amelia Roberts") s id=1
s ok=$$set^User(id,"amelia~password~amelia-roberts@no-reply.com~Amelia Roberts")
i ok=1 d i ok=1 d
. w !,"User successfully updated!",! . w !,"User updated (",id,"):",!
. zwrite ^users(1)
e d e d
. w !,"Whoops! The user could not be updated.",! . w !,"Whoops! The user could not be updated.",!
; fetch a user ; fetch a user
s ok=$$fetch^User(1,.data) s id=1
s ok=$$fetch^User(id,.data)
i ok=1 d i ok=1 d
. w !,"User successfully fetched!",! . w !,"User fetched (",id,"):",!
. w "username: ",data("username"),! . zwrite data
. w "email: ",data("email"),!
. w "fullname: ",data("fullname"),!
e d e d
. w "Whoops! The user could not be fetched.",! . w !,"Whoops! The user could not be fetched.",!
; delete a user ; delete a user
s ok=$$remove^User(2) s id=2
s ok=$$remove^User(id)
i ok=1 d i ok=1 d
. w !,"User successfully deleted!",! . w !,"User deleted (",id,")",!
e d e d
. w !,"Whoops! The user could not be deleted.",! . w !,"Whoops! The user could not be deleted.",!
; fetch a user ; fetch a user
s ok=$$fetch^User(2,.data) s id=2
s ok=$$fetch^User(id,.data)
i ok=1 d i ok=1 d
. w !,"User successfully fetched!",! . w !,"User fetched (",id,"):",!
. w "username: ",data("username"),! . zwrite data
. w "email: ",data("email"),!
. w "fullname: ",data("fullname"),!
e d e d
. w "Whoops! The user could not be fetched.",! . w !,"Whoops! The user could not be fetched.",!
; drop database ; drop database

View File

@ -228,27 +228,34 @@ Then run the example:
### [`basic-sql-crud/Main.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-crud/Main.m) ### [`basic-sql-crud/Main.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-crud/Main.m)
User successfully created! User created:
User successfully created! ^users(1)="alice~password~alice-jones@no-reply.com~Alice Jones"
User successfully fetched! User created:
username: alice ^users(2)="bob~password~bob-smith@no-reply.com~Bob Smith"
email: alice-jones@no-reply.com
fullname: Alice Jones
User successfully updated! User fetched (1):
data("email")="alice-jones@no-reply.com"
data("fullname")="Alice Jones"
data("password")="password"
data("username")="alice"
User successfully fetched! User updated (1):
username: amelia ^users(1)="amelia~password~amelia-roberts@no-reply.com~Amelia Roberts"
email: amelia-roberts@no-reply.com
fullname: Amelia Roberts
User successfully deleted! User fetched (1):
data("email")="amelia-roberts@no-reply.com"
data("fullname")="Amelia Roberts"
data("password")="password"
data("username")="amelia"
User successfully fetched! User deleted (2)
username:
email: User fetched (2):
fullname: data("email")=""
data("fullname")=""
data("password")=""
data("username")=""
Database successfully dropped! Database successfully dropped!
@ -259,24 +266,44 @@ For further details also visit:
### [`basic-sql-blog/Main.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-blog/Main.m) ### [`basic-sql-blog/Main.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-blog/Main.m)
Users:
^users(1)="alice~password~alice-jones@no-reply.com~Alice Jones"
^users(2)="bob~password~bob-smith@no-reply.com~Bob Smith"
Categories:
^categories(1)="foo~Foo"
^categories(2)="bar~Bar"
^categories(3)="foobar~Foobar"
Posts:
^posts(1,1,1)="lorem-ipsum~Lorem ipsum~Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
^posts(2,1,1)="donec-pede-justo~Donec pede justo~Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu."
^posts(3,3,2)="curabitur-ullamcorper-ultricies~Curabitur ullamcorper ultricies~Curabitur ullamcorper ultricies nisi."
^posts(4,3,2)="donec-vitae-sapien~Donec vitae sapien~Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante."
Comments:
^comments(1,1)="This is awesome! Thank you."
^comments(2,2)="Thank you so much for sharing this."
Category fetched (3): Category fetched (3):
description: Foobar data("description")="Foobar"
data("slug")="foobar"
Post fetched (1): Post fetched (1):
slug: lorem-ipsum data("description")="Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
title: Lorem ipsum data("slug")="lorem-ipsum"
description: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. data("title")="Lorem ipsum"
Posts fetched by category (3): Posts fetched by category (3):
(3,3,2) = curabitur-ullamcorper-ultricies~Curabitur ullamcorper ultricies~Curabitur ullamcorper ultricies nisi. data(3,3,2)="curabitur-ullamcorper-ultricies~Curabitur ullamcorper ultricies~Curabitur ullamcorper ultricies nisi."
(4,3,2) = donec-vitae-sapien~Donec vitae sapien~Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. data(4,3,2)="donec-vitae-sapien~Donec vitae sapien~Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante."
Posts fetched by user (1): Posts fetched by user (1):
(1,1,1) = lorem-ipsum~Lorem ipsum~Lorem ipsum dolor sit amet, consectetuer adipiscing elit. data(1,1,1)="lorem-ipsum~Lorem ipsum~Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
(2,1,1) = donec-pede-justo~Donec pede justo~Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. data(2,1,1)="donec-pede-justo~Donec pede justo~Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu."
Comment fetched (1): Comment fetched (1):
description: This is awesome! Thank you. data("description")="This is awesome! Thank you."
Database successfully dropped! Database successfully dropped!