/
main.go
97 lines (69 loc) · 1.71 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"strconv"
"time"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"github.com/satori/go.uuid"
)
func main() {
db := sqlx.MustConnect(
"mysql",
"root:dev@tcp(172.19.8.101:3306)/test?parseTime=true",
)
// testuuid := Insert(db)
// Select(db, testuuid.String())
tetuint := uint64(9223372036854775826)
SelectuInt(db, tetuint)
}
type UserTest struct {
ID uuid.UUID
}
func InsertBin(dbx *sqlx.DB) uuid.UUID {
// Creating UUID Version 4
u1 := uuid.NewV4()
_, err := dbx.Exec("INSERT INTO test_table_bin (id) VALUES (?)", u1.Bytes())
if err != nil {
fmt.Printf("%v", err)
}
return u1
}
func InsertIntAuto(dbx *sqlx.DB) uint64 {
_, _ = dbx.Exec("INSERT INTO test_table_int() values()")
row := dbx.QueryRow("SELECT MAX(id) FROM test_table_int")
var testuint uint64
// var testuintX int64
_ = row.Scan(&testuint)
// testuintX, _ = res.LastInsertId()
return testuint
}
func Select(dbx *sqlx.DB, testuuid string) {
uuid, _ := uuid.FromString(testuuid)
var user UserTest
row := dbx.QueryRow("SELECT id from test_table WHERE ID = ?", uuid.Bytes())
err := row.Scan(&user.ID)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%#v", user.ID.String())
}
func SelectuInt(dbx *sqlx.DB, testuint uint64) {
type userS struct {
ID uint64
TimeCreated time.Time `db:"time_created"`
}
rows, err := dbx.Queryx("SELECT id, time_created from test_table_int WHERE ID=" + strconv.FormatUint(testuint, 10))
for rows.Next() {
var user userS
err = rows.StructScan(&user)
idstr := strconv.FormatUint(user.ID, 10)
fmt.Printf("%#v", user.TimeCreated.Location())
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%#v", idstr)
}
}