forked from bpradipt/sampleflaskapp
-
Notifications
You must be signed in to change notification settings - Fork 20
/
db_setup
97 lines (83 loc) · 1.97 KB
/
db_setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
CREATE DATABASE IF NOT EXISTS BucketList;
CREATE TABLE IF NOT EXISTS `BucketList`.`tbl_user` (
`user_id` BIGINT NULL AUTO_INCREMENT,
`user_name` VARCHAR(45) NULL,
`user_username` VARCHAR(45) NULL,
`user_password` VARCHAR(255) NULL,
PRIMARY KEY (`user_id`));
DELIMITER $$
USE `BucketList`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_createUser`(
IN p_name VARCHAR(45),
IN p_username VARCHAR(45),
IN p_password VARCHAR(255)
)
BEGIN
if ( select exists (select 1 from tbl_user where user_username = p_username) ) THEN
select 'Username Exists !!';
ELSE
insert into tbl_user
(
user_name,
user_username,
user_password
)
values
(
p_name,
p_username,
p_password
);
END IF;
END$$
DELIMITER ;
DELIMITER $$
USE `BucketList`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_validateLogin`(
IN p_username VARCHAR(20)
)
BEGIN
select * from tbl_user where user_username = p_username;
END$$
DELIMITER ;
CREATE TABLE IF NOT EXISTS `BucketList`.`tbl_wish` (
`wish_id` int(11) NOT NULL AUTO_INCREMENT,
`wish_title` varchar(45) DEFAULT NULL,
`wish_description` varchar(5000) DEFAULT NULL,
`wish_user_id` int(11) DEFAULT NULL,
`wish_date` datetime DEFAULT NULL,
PRIMARY KEY (`wish_id`)
)ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
DELIMITER $$
USE `BucketList`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_addWish`(
IN p_title varchar(45),
IN p_description varchar(1000),
IN p_user_id bigint
)
BEGIN
insert into tbl_wish(
wish_title,
wish_description,
wish_user_id,
wish_date
)
values
(
p_title,
p_description,
p_user_id,
NOW()
);
END$$
DELIMITER ;
;
DELIMITER $$
USE `BucketList`$$
CREATE PROCEDURE `sp_GetWishByUser` (
IN p_user_id bigint
)
BEGIN
select * from tbl_wish where wish_user_id = p_user_id;
END$$
DELIMITER ;