Crud.m and UserRoutines.m have been added

This commit is contained in:
programarivm 2019-09-26 21:48:50 +01:00
parent 180cf8c580
commit 4b2e8f35fc
3 changed files with 117 additions and 0 deletions

63
04-databases/Crud.m Normal file
View File

@ -0,0 +1,63 @@
; 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.",!,!
; fetch a user
s ok=$$fetch^UserRoutines(1,.data)
i ok=1 d
. w "User successfully fetched!",!
. w "Username: ",data("username"),!
. w "Email: ",data("email"),!
. w "Full name: ",data("fullname"),!,!
e d
. w "Whoops! The user could not be fetched.",!,!
; update a user
s ok=$$set^UserRoutines(1,"amelia~password~amelia-roberts@no-reply.com~Amelia Roberts")
i ok=1 d
. w !,"User successfully updated!",!,!
e d
. w !,"Whoops! The user could not be updated.",!,!
; fetch a user
s ok=$$fetch^UserRoutines(1,.data)
i ok=1 d
. w "User successfully fetched!",!
. w "Username: ",data("username"),!
. w "Email: ",data("email"),!
. w "Full name: ",data("fullname"),!,!
e d
. w "Whoops! The user could not be fetched.",!,!
; delete a user
s ok=$$remove^UserRoutines(2)
i ok=1 d
. w "User successfully deleted!",!,!
e d
. w "Whoops! The user could not be deleted.",!,!
; fetch a user
s ok=$$fetch^UserRoutines(2,.data)
i ok=1 d
. w "User successfully fetched!",!
. w "Username: ",data("username"),!
. w "Email: ",data("email"),!
. w "Full name: ",data("fullname"),!
e d
. w "Whoops! The user could not be fetched.",!

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

@ -195,6 +195,35 @@ Copy the examples into your `~/.fis-gtm/V6.3-003A_x86_64/r` folder and run:
$data(^gtree(0,1,1,1)) is 0
$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)
User successfully created!
User successfully created!
User successfully fetched!
Username: alice
Email: alice-jones@no-reply.com
Full name: Alice Jones
User successfully updated!
User successfully fetched!
Username: amelia
Email: amelia-roberts@no-reply.com
Full name: Amelia Roberts
User successfully deleted!
User successfully fetched!
Username:
Email:
Full name:
> For further details also visit [UserRoutines.m](https://github.com/programarivm/mumps-examples/blob/master/04-databases/UserRoutines.m)
---
### Contributions