-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert_withdbq.go
35 lines (26 loc) · 1022 Bytes
/
insert_withdbq.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
package main
import (
"context"
"database/sql"
"time"
_ "github.com/go-sql-driver/mysql"
"github.com/rocketlaunchr/dbq"
)
func singleRowInsertWithDbq(ctx context.Context, db *sql.DB) {
// Single Row Insert Data with dbq.E
newStore := []interface{}{
[]interface{}{"404", "motor Cycle", 36, 4464646.46, 1, time.Now()},
}
stmt := dbq.INSERT("store", []string{"Id", "product", "quantity", "price", "available", "timing"}, len(newStore), dbq.MySQL)
dbq.MustE(ctx, db, stmt, nil, newStore)
}
func multipleRowsInsertWithDbq(ctx context.Context, db *sql.DB) {
// Multiple Row Insert with dbq.E and dbq.INSERT
newStores := []interface{}{
[]interface{}{"405", "Comic Book", 25, 456.34, 1, time.Now()},
[]interface{}{"406", "Movie Ticket", 17, 1250.5, 1, time.Now()},
[]interface{}{"407", "Teddy Bear", 30, 99.99, 0, time.Now()},
}
stmt := dbq.INSERT("store", []string{"Id", "product", "quantity", "price", "available", "timing"}, len(newStores), dbq.MySQL)
dbq.MustE(ctx, db, stmt, nil, newStores)
}