fetchByUser is added to PostRoutines

This commit is contained in:
programarivm 2019-09-27 18:48:25 +01:00
parent 8876cd5a7c
commit d05f76949a
3 changed files with 40 additions and 17 deletions

View File

@ -16,28 +16,35 @@
s ok=$$set^CommentRoutines(1,1,"This is awesome! Thank you.")
s ok=$$set^CommentRoutines(2,2,"Thank you so much for sharing this.")
; fetch posts
; fetch posts by post
do fetchByPost^PostRoutines(1,.data)
w "Post fetched:",!
w "Post fetched by post:",!
w "slug: ",data("slug"),!
w "title: ",data("title"),!
w "description: ",data("description"),!
do fetchByPost^PostRoutines(2,.data)
w !,"Post fetched:",!
w !,"Post fetched by post:",!
w "slug: ",data("slug"),!
w "title: ",data("title"),!
w "description: ",data("description"),!
; fetch posts by user
do fetchByUser^PostRoutines(1,.data)
w !,"Posts fetched by user:",!
w data(1),!
w data(2),!
; fetch comments
do fetchByComment^CommentRoutines(1,.data)
w !,"Comment fetched:",!
w !,"Comment fetched by comment:",!
w "description: ",data("description"),!
do fetchByComment^CommentRoutines(2,.data)
w !,"Comment fetched:",!
w !,"Comment fetched by comment:",!
w "description: ",data("description"),!
; drop database

View File

@ -15,6 +15,19 @@ fetchByPost(idPost,data)
. . . q
q
fetchByUser(idUser,data)
k data
i idUser="" q 0
s lev1=""
s lev2=""
s count=1
f s lev1=$o(^posts(lev1)) q:lev1="" d
. f s lev2=$o(^posts(lev1,lev2)) q:lev2="" d
. . i lev2=idUser d
. . . s data(count)=$get(^posts(lev1,idUser))
. . . s count=count+1
q
set(idPost,idUser,data)
i idPost=""!idUser="" q 0
s slug=$piece(data,"~",1)

View File

@ -229,22 +229,25 @@ For further details also visit:
### [`basic-blog/Main.m`](https://github.com/programarivm/mumps-examples/blob/master/04-databases/basic-blog/Main.m)
User successfully created!
User successfully created!
Post successfully created!
Post successfully created!
Comment successfully created!
Comment successfully created!
Post successfully fetched!
Post fetched by post:
slug: lorem-ipsum
title: Lorem ipsum
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
id_user: 1
description: Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Comment successfully fetched!
Post fetched by post:
slug: donec-pede-justo
title: Donec pede justo
description: Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.
Posts fetched by user:
lorem-ipsum~Lorem ipsum~Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
donec-pede-justo~Donec pede justo~Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.
Comment fetched by comment:
description: This is awesome! Thank you.
Comment fetched by comment:
description: Thank you so much for sharing this.
id_post: 2
Database successfully dropped!