04-databases/blog is been added

This commit is contained in:
programarivm 2019-09-27 10:54:25 +01:00
parent aa1f02ff3f
commit e22ca8d22e
8 changed files with 125 additions and 2 deletions

View File

@ -0,0 +1,21 @@
fetch(n,data)
n record
k data
i n="" q 0
s record=$get(^comments(n))
s data("description")=$piece(record,"~",1)
s data("id_post")=$piece(record,"~",2)
q 1
set(n,data)
i n="" q 0
s description=$piece(data,"~",1)
s idPost=$piece(data,"~",2)
s ^comments(n)=description_"~"_idPost
q 1
remove(n)
i n="" q 0
k ^comments(n)
q 1

View File

@ -0,0 +1,6 @@
drop()
k ^comments;
k ^posts;
k ^users;
q

46
04-databases/blog/Main.m Normal file
View File

@ -0,0 +1,46 @@
; create users
s ok=$$set^UserRoutines(1,"alice~password~alice-jones@no-reply.com~Alice Jones")
i ok=1 d
. w "User successfully created!",!,!
e d
. w "Whoops! The user could not be created.",!,!
s ok=$$set^UserRoutines(2,"bob~password~bob-smith@no-reply.com~Bob Smith")
i ok=1 d
. w "User successfully created!",!,!
e d
. w "Whoops! The user could not be created.",!,!
; create posts
s ok=$$set^PostRoutines(1,"lorem-ipsum~Lorem ipsum~Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.~1")
i ok=1 d
. w "Post successfully created!",!,!
e d
. w "Whoops! The post could not be created.",!,!
s ok=$$set^PostRoutines(2,"excepteur-sint-occaecat~Excepteur sint occaecat~Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.~2")
i ok=1 d
. w "Post successfully created!",!,!
e d
. w "Whoops! The post could not be created.",!,!
; create comments
s ok=$$set^CommentRoutines(1,"This is awesome. Thank you.~1")
i ok=1 d
. w "Comment successfully created!",!,!
e d
. w "Whoops! The comment could not be created.",!,!
s ok=$$set^CommentRoutines(2,".Thank you so much for sharing this.~2")
i ok=1 d
. w "Comment successfully created!",!,!
e d
. w "Whoops! The comment could not be created.",!,!
; drop database
d drop^DatabaseRoutines

View File

@ -0,0 +1,25 @@
fetch(n,data)
n record
k data
i n="" q 0
s record=$get(^posts(n))
s data("slug")=$piece(record,"~",1)
s data("title")=$piece(record,"~",2)
s data("description")=$piece(record,"~",3)
s data("id_user")=$piece(record,"~",4)
q 1
set(n,data)
i n="" q 0
s slug=$piece(data,"~",1)
s title=$piece(data,"~",2)
s description=$piece(data,"~",3)
s idUser=$piece(data,"~",4)
s ^posts(n)=slug_"~"_title_"~"_description_"~"_idUser
q 1
remove(n)
i n="" q 0
k ^posts(n)
q 1

View File

@ -0,0 +1,25 @@
fetch(n,data)
n record
k data
i n="" q 0
s record=$get(^users(n))
s data("username")=$piece(record,"~",1)
s data("password")=$piece(record,"~",2)
s data("email")=$piece(record,"~",3)
s data("fullname")=$piece(record,"~",4)
q 1
set(n,data)
i n="" q 0
s username=$piece(data,"~",1)
s password=$piece(data,"~",2)
s email=$piece(data,"~",3)
s fullname=$piece(data,"~",4)
s ^users(n)=username_"~"_password_"~"_email_"~"_fullname
q 1
remove(n)
i n="" q 0
k ^users(n)
q 1

View File

@ -196,7 +196,7 @@ Copy the examples into your `~/.fis-gtm/V6.3-003A_x86_64/r` folder and run:
$data(^gtree(0,0,0,0,0)) is 0
$data(^gtree(0)) is 0
### [`Crud.m`](https://github.com/programarivm/mumps-examples/blob/master/04-databases/Crud.m)
### [`simple-crud/Main.m`](https://github.com/programarivm/mumps-examples/blob/master/04-databases/simple-crud/Main.m)
User successfully created!
@ -221,7 +221,7 @@ Copy the examples into your `~/.fis-gtm/V6.3-003A_x86_64/r` folder and run:
Email:
Full name:
> For further details also visit [UserRoutines.m](https://github.com/programarivm/mumps-examples/blob/master/04-databases/UserRoutines.m)
> For further details also visit [UserRoutines.m](https://github.com/programarivm/mumps-examples/blob/master/04-databases/simple-crud/UserRoutines.m)
---