From e22ca8d22e29a6cf6c19357485e804a72f5b2682 Mon Sep 17 00:00:00 2001 From: programarivm Date: Fri, 27 Sep 2019 10:54:25 +0100 Subject: [PATCH] 04-databases/blog is been added --- 04-databases/blog/CommentRoutines.m | 21 ++++++++++ 04-databases/blog/DatabaseRoutines.m | 6 +++ 04-databases/blog/Main.m | 46 +++++++++++++++++++++ 04-databases/blog/PostRoutines.m | 25 +++++++++++ 04-databases/{ => blog}/UserRoutines.m | 0 04-databases/{Crud.m => simple-crud/Main.m} | 0 04-databases/simple-crud/UserRoutines.m | 25 +++++++++++ README.md | 4 +- 8 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 04-databases/blog/CommentRoutines.m create mode 100644 04-databases/blog/DatabaseRoutines.m create mode 100644 04-databases/blog/Main.m create mode 100644 04-databases/blog/PostRoutines.m rename 04-databases/{ => blog}/UserRoutines.m (100%) rename 04-databases/{Crud.m => simple-crud/Main.m} (100%) create mode 100644 04-databases/simple-crud/UserRoutines.m diff --git a/04-databases/blog/CommentRoutines.m b/04-databases/blog/CommentRoutines.m new file mode 100644 index 0000000..7bf02c2 --- /dev/null +++ b/04-databases/blog/CommentRoutines.m @@ -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 diff --git a/04-databases/blog/DatabaseRoutines.m b/04-databases/blog/DatabaseRoutines.m new file mode 100644 index 0000000..81749ee --- /dev/null +++ b/04-databases/blog/DatabaseRoutines.m @@ -0,0 +1,6 @@ + +drop() + k ^comments; + k ^posts; + k ^users; + q diff --git a/04-databases/blog/Main.m b/04-databases/blog/Main.m new file mode 100644 index 0000000..dbd280f --- /dev/null +++ b/04-databases/blog/Main.m @@ -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 diff --git a/04-databases/blog/PostRoutines.m b/04-databases/blog/PostRoutines.m new file mode 100644 index 0000000..9c14e3c --- /dev/null +++ b/04-databases/blog/PostRoutines.m @@ -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 diff --git a/04-databases/UserRoutines.m b/04-databases/blog/UserRoutines.m similarity index 100% rename from 04-databases/UserRoutines.m rename to 04-databases/blog/UserRoutines.m diff --git a/04-databases/Crud.m b/04-databases/simple-crud/Main.m similarity index 100% rename from 04-databases/Crud.m rename to 04-databases/simple-crud/Main.m diff --git a/04-databases/simple-crud/UserRoutines.m b/04-databases/simple-crud/UserRoutines.m new file mode 100644 index 0000000..82e71ef --- /dev/null +++ b/04-databases/simple-crud/UserRoutines.m @@ -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 diff --git a/README.md b/README.md index 1bda301..ed49d06 100644 --- a/README.md +++ b/README.md @@ -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) ---