From a2946ede0a024c4483262fab16a0aa50e086185f Mon Sep 17 00:00:00 2001 From: programarivm Date: Sat, 28 Sep 2019 23:20:15 +0100 Subject: [PATCH] cleanup --- 04-databases/basic-sql-blog/Main.m | 50 +++++++++------------ 04-databases/basic-sql-blog/routines/Post.m | 14 +++--- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/04-databases/basic-sql-blog/Main.m b/04-databases/basic-sql-blog/Main.m index dc981c7..d1738d5 100644 --- a/04-databases/basic-sql-blog/Main.m +++ b/04-databases/basic-sql-blog/Main.m @@ -27,7 +27,7 @@ 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.") - s ok=$$set^Post(3,3,2,"curabitur-ullamcorper-ultricies~Curabitur ullamcorper ultricies~ Curabitur ullamcorper ultricies nisi.") + s ok=$$set^Post(3,3,2,"curabitur-ullamcorper-ultricies~Curabitur ullamcorper ultricies~Curabitur ullamcorper ultricies nisi.") s ok=$$set^Post(4,3,2,"donec-vitae-sapien~Donec vitae sapien~Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante.") ; create comments @@ -35,21 +35,13 @@ s ok=$$set^Comment(1,1,"This is awesome! Thank you.") s ok=$$set^Comment(2,2,"Thank you so much for sharing this.") -; fetch categories +; fetch a category do fetch^Category(1,.data) w "Category fetched:",! w "description: ",data("description"),! - do fetch^Category(2,.data) - w !,"Category fetched:",! - w "description: ",data("description"),! - - do fetch^Category(3,.data) - w !,"Category fetched:",! - w "description: ",data("description"),! - -; fetch posts by post +; fetch a post do fetch^Post(1,.data) w !,"Post fetched:",! @@ -57,36 +49,36 @@ w "title: ",data("title"),! w "description: ",data("description"),! - do fetch^Post(2,.data) - w !,"Post fetched:",! - w "slug: ",data("slug"),! - w "title: ",data("title"),! - w "description: ",data("description"),! +; fetch posts by category + + do fetchByCategory^Post(3,.data) + w !,"Posts fetched by category:",! + s lev1="" + 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 data(lev1,lev2,lev3),! ; fetch posts by user do fetchByUser^Post(1,.data) w !,"Posts fetched by user:",! s lev1="" - f s lev1=$o(data(lev1)) q:lev1="" d w data(lev1),! + 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 data(lev1,lev2,lev3),! -; fetch posts by category - - do fetchByCategory^Post(3,.data) - w !,"Posts fetched by category:",! - s lev1="" - f s lev1=$o(data(lev1)) q:lev1="" d w data(lev1),! - -; fetch comments +; fetch a comment do fetch^Comment(1,.data) w !,"Comment fetched:",! w "description: ",data("description"),! - do fetch^Comment(2,.data) - w !,"Comment fetched:",! - w "description: ",data("description"),! - ; drop database s ok=$$drop^Database() diff --git a/04-databases/basic-sql-blog/routines/Post.m b/04-databases/basic-sql-blog/routines/Post.m index 0482e0e..b8ad0f9 100644 --- a/04-databases/basic-sql-blog/routines/Post.m +++ b/04-databases/basic-sql-blog/routines/Post.m @@ -23,28 +23,24 @@ fetchByCategory(id,data) s lev1="" s lev2="" s lev3="" - s count=1 f s lev1=$o(^posts(lev1)) q:lev1="" d . f s lev2=$o(^posts(lev1,lev2)) q:lev2="" d . . f s lev3=$o(^posts(lev1,lev2,lev3)) q:lev3="" d . . . i lev2=id d - . . . . s data(count)=$get(^posts(lev1,lev2,lev3)) - . . . . s count=count+1 + . . . . s data(lev1,lev2,lev3)=$get(^posts(lev1,lev2,lev3)) q -fetchByUser(idUser,data) +fetchByUser(id,data) k data - i idUser="" q 0 + i id="" q 0 s lev1="" s lev2="" s lev3="" - s count=1 f s lev1=$o(^posts(lev1)) q:lev1="" d . f s lev2=$o(^posts(lev1,lev2)) q:lev2="" d . . f s lev3=$o(^posts(lev1,lev2,lev3)) q:lev3="" d - . . . i lev3=idUser d - . . . . s data(count)=$get(^posts(lev1,lev2,lev3)) - . . . . s count=count+1 + . . . i lev3=id d + . . . . s data(lev1,lev2,lev3)=$get(^posts(lev1,lev2,lev3)) q set(id,idCategory,idUser,data)