-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
54 lines (50 loc) · 1019 Bytes
/
create.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
package x
import (
"context"
"fmt"
"github.com/bwmarrin/snowflake"
"github.com/michaelzx/pgx-z/examples/internal/col"
"github.com/michaelzx/pgx-z/examples/internal/model"
"github.com/michaelzx/pgx-z/pgxz"
"github.com/rs/xid"
"time"
)
var snowNode *snowflake.Node
func init() {
var err error
snowNode, err = snowflake.NewNode(1)
if err != nil {
panic(err)
}
}
func CreateByPgx() {
no := xid.New().String()
_, err := db.Exec(context.TODO(), `insert into team ("no", title)
values ($1,$2);`, no, "CreateByPgx"+time.Now().String())
if err != nil {
fmt.Println(no)
panic(err)
}
}
func CreateByPgxZ() {
no := xid.New().String()
err := pgxz.Create(db, col.Team(&model.Team{
No: no,
Title: "CreateByPgxZ" + time.Now().String(),
}))
if err != nil {
fmt.Println(no)
panic(err)
}
}
func CreateByGorm() {
no := xid.New().String()
err := gormdb.Create(&model.Team{
No: no,
Title: "CreateByGorm" + time.Now().String(),
}).Error
if err != nil {
fmt.Println(no)
panic(err)
}
}