Skip to content

Instantly share code, notes, and snippets.

@amogh-plivo
amogh-plivo / insertsLoopedGorm.go
Last active May 30, 2017 20:41
How to insert multiple records in postgres using Gorm
import "github.com/jinzhu/gorm"
databaseURL:= "user=abc password=abc dbname=db host=localhost port=5432"
db, err := gorm.Open("postgres", databaseURL)
if err != nil {
fmt.Printf("DBERR %s", err.Error())
}
db.DB().SetMaxIdleConns(10)
db.DB().SetMaxOpenConns(10)
db.LogMode(true)
m := &MessageDetailRecord{
import (
"database/sql"
"github.com/lib/pq"
)
dbb, _ := sql.Open("postgres", "postgres://Amogh:amogh@localhost:6431/dblog?sslmode=disable")
dbb.SetMaxIdleConns(10)
dbb.SetMaxOpenConns(10)
dbb.SetConnMaxLifetime(0)
a := time.Now()
txn, err := dbb.Begin()