forked from 0c34/govwa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunction.go
78 lines (64 loc) · 1.61 KB
/
function.go
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
package setup
import (
"database/sql"
"github.com/govwa/util/database"
)
const (
DropUsersTable = `DROP TABLE IF EXISTS Users`
CreateUsersTable = `CREATE TABLE Users (
id int(10) NOT NULL AUTO_INCREMENT,
uname varchar(100) NOT NULL,
pass varchar(100) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1`
InsertUsers = `INSERT INTO Users VALUES (1,'admin','9f3b6fa4703a5ba96fda0dee48ec76fc'),(2,'user1','ff1d5c0015a535b01a5d03a373bf06f6')`
DropProfilesTable = `DROP TABLE IF EXISTS Profile`
CreateProfilesTable = `CREATE TABLE Profile (
profile_id int(10) NOT NULL AUTO_INCREMENT,
user_id int(10) NOT NULL,
full_name varchar(100) NOT NULL,
city varchar(100) NOT NULL,
phone_number varchar(15) NOT NULL,
PRIMARY KEY (profile_id)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1`
InsertProfile = `INSERT INTO Profile VALUES (1,1,'Andro','Jakarta','08882112345'),(2,2,'Rocky','Bandung','08882112345')`
)
var DB *sql.DB
var err error
/*func init() {
DB, err = database.Connect()
if err != nil {
log.Println(err.Error())
}
}*/
func createUsersTable() error {
DB, err = database.Connect()
_, err = DB.Exec(DropUsersTable)
if err != nil {
return err
}
_, err = DB.Exec(CreateUsersTable)
if err != nil {
return err
}
_, err = DB.Exec(InsertUsers)
if err != nil {
return err
}
return nil
}
func createProfileTable() error {
_, err = DB.Exec(DropProfilesTable)
if err != nil {
return err
}
_, err = DB.Exec(CreateProfilesTable)
if err != nil {
return err
}
_, err = DB.Exec(InsertProfile)
if err != nil {
return err
}
return nil
}