Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"math/big"
"net"
"strings"

_ "github.com/lib/pq"
)
Expand Down Expand Up @@ -189,6 +190,35 @@ func (c *Client) Write(a interface{}, options ...option) error {
return nil
}

func (c *Client) WriteBatch(rows []interface{}, options ...option) error {
var models []*Model
for _, row := range rows {
m, err := NewModel(row)
if err != nil {
return err
}
if len(options) > 0 {
for _, opt := range options {
// check and set all options here
if opt.tableName != "" {
m.tableName = opt.tableName
}
}
}
models = append(models, m)
}

var sb strings.Builder
for _, m := range models {
sb.Write(m.MarshalLine())
}
_, err := c.ilpConn.Write([]byte(sb.String()))
if err != nil {
return err
}
return nil
}

// DB func returns the underlying *sql.DB struct for DB operations over the Postgres wire protocol
func (c *Client) DB() *sql.DB {
return c.pgSqlDB
Expand Down