-
Notifications
You must be signed in to change notification settings - Fork 1
/
easydb_test.go
85 lines (79 loc) · 2.29 KB
/
easydb_test.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
79
80
81
82
83
84
85
package easydb
import (
"fmt"
"testing"
)
var dbExec *DBExec
var mysqlConf *DBConfig
var mysqlConf2 = NewMysqlConfig(WithPassword("password"), WithSchema("testdb"), WithHost("127.0.0.1"))
var pgsqlConf = NewPgsqlConfig(WithSchema("test_db"))
func Test_mysql_insert(t *testing.T) {
dbExec = GetInst(MYSQL, mysqlConf2)
r, _ := dbExec.Insert(
BuildInsert("testdb").
Table(Table{Name: "test_table"}).
Values(Column{Name: "name", Value: "name"}))
fmt.Println(r)
}
func Test_mysql_delete(t *testing.T) {
mysqlConf = NewMysqlConfig(WithPassword("password"), WithSchema("testdb"))
db := GetExec(MYSQL, mysqlConf2)
r, _ := db.Exec(
BuildDelete("testdb").
Table(Table{Name: "test_table"}).
Where(Where{Key: "id", Opt: EQ, Value: 1}))
fmt.Println(r)
}
func Test_mysql_update(t *testing.T) {
mysqlConf = NewMysqlConfig(WithPassword("password"), WithSchema("testdb"))
db := GetExec(MYSQL, mysqlConf2)
r, _ := db.Exec(
BuildUpdate("testdb").
Table(Table{Name: "test_table"}).
Set(Column{Name: "name", Value: "name1"}).
Where(Where{Key: "email", Opt: EQ, Value: ""}))
fmt.Println(r)
}
func Test_mysql_select(t *testing.T) {
db := GetExec(MYSQL, mysqlConf2)
r, _ := db.Exec(
BuildQuery("testdb").
Columns(Column{Name: "*"}).
Tables(Table{Name: "test_table"}).
Where(Where{Key: "name", Opt: NE, Value: "name"}))
fmt.Println(r)
}
func Test_pgsql_insert(t *testing.T) {
db := GetExec(PGSQL, pgsqlConf)
r, _ := db.Exec(
BuildInsert("public").
Table(Table{Name: "test_table"}).
Values(Column{Name: "name", Value: "name"}))
fmt.Println(r)
}
func Test_pgsql_delete(t *testing.T) {
db := GetExec(PGSQL, pgsqlConf)
r, _ := db.Exec(
BuildDelete("public").
Table(Table{Name: "test_table"}).
Where(Where{Key: "name", Opt: NE, Value: "name"}))
fmt.Println(r)
}
func Test_pgsql_update(t *testing.T) {
db := GetExec(PGSQL, pgsqlConf)
r, _ := db.Exec(
BuildUpdate("public").
Table(Table{Name: "test_table"}).
Set(Column{Name: "email", Value: "email"}).
Where(Where{Key: "name", Opt: EQ, Value: "name"}))
fmt.Println(r)
}
func Test_pgsql_select(t *testing.T) {
db := GetExec(PGSQL, pgsqlConf)
r, _ := db.Exec(
BuildQuery("public").
Columns(Column{Name: "*"}).
Tables(Table{Name: "test_table"}).
Where(Where{Key: "name", Opt: EQ, Value: "name"}))
fmt.Println(r)
}