From d05f76949afb66de0caaa52e0cd8b3ac03827b27 Mon Sep 17 00:00:00 2001 From: programarivm Date: Fri, 27 Sep 2019 18:48:25 +0100 Subject: [PATCH] fetchByUser is added to PostRoutines --- 04-databases/basic-blog/Main.m | 17 +++++++++++----- 04-databases/basic-blog/PostRoutines.m | 13 +++++++++++++ README.md | 27 ++++++++++++++------------ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/04-databases/basic-blog/Main.m b/04-databases/basic-blog/Main.m index bd9f145..9c7de43 100644 --- a/04-databases/basic-blog/Main.m +++ b/04-databases/basic-blog/Main.m @@ -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 diff --git a/04-databases/basic-blog/PostRoutines.m b/04-databases/basic-blog/PostRoutines.m index 57cfddb..5467770 100644 --- a/04-databases/basic-blog/PostRoutines.m +++ b/04-databases/basic-blog/PostRoutines.m @@ -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) diff --git a/README.md b/README.md index e797bfe..43a1063 100644 --- a/README.md +++ b/README.md @@ -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!