Skip to content

Commit 4f54cce

Browse files
committed
Fixed #31: Added LineErrors to qbclient.InsertRecordsOutputMetadata
1 parent 2370e10 commit 4f54cce

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

qbcli/batch.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"os"
99
"sort"
10+
"strconv"
1011
"time"
1112

1213
"github.com/QuickBase/quickbase-cli/qbclient"
@@ -128,6 +129,7 @@ type ImportOptions struct {
128129
func Import(qb *qbclient.Client, opts *ImportOptions) (*qbclient.InsertRecordsOutputMetadata, error) {
129130
metadata := &qbclient.InsertRecordsOutputMetadata{
130131
CreatedRecordIDs: []int{},
132+
LineErrors: map[string][]string{},
131133
TotalNumberOfRecordsProcessed: 0,
132134
UnchangedRecordIDs: []int{},
133135
UpdatedRecordIDs: []int{},
@@ -247,13 +249,32 @@ func Import(qb *qbclient.Client, opts *ImportOptions) (*qbclient.InsertRecordsOu
247249
}
248250

249251
// Empty the records for the next batch.
252+
rlen := len(records)
250253
records = []map[int]*qbclient.InsertRecordsInputData{}
251254

252255
metadata.CreatedRecordIDs = append(metadata.CreatedRecordIDs, iro.Metadata.CreatedRecordIDs...)
253256
metadata.TotalNumberOfRecordsProcessed += iro.Metadata.TotalNumberOfRecordsProcessed
254257
metadata.UnchangedRecordIDs = append(metadata.UnchangedRecordIDs, iro.Metadata.UnchangedRecordIDs...)
255258
metadata.UpdatedRecordIDs = append(metadata.UpdatedRecordIDs, iro.Metadata.UpdatedRecordIDs...)
256259

260+
// Merging the line errors isn't so simple.
261+
for k, v := range iro.Metadata.LineErrors {
262+
n, err := strconv.Atoi(k)
263+
if err != nil {
264+
return metadata, fmt.Errorf("%s: expecting lineErrors key to be an integer", k)
265+
}
266+
267+
// This works no matter the batch size, but I have no idea why
268+
// we have to subtract 1 from n when eof is true. If this is
269+
// buggy, blame [email protected].
270+
n = line - rlen + n
271+
if eof {
272+
n--
273+
}
274+
275+
metadata.LineErrors[strconv.Itoa(n)] = v
276+
}
277+
257278
// Delay before the next API call.
258279
if opts.Delay > 0 && !eof {
259280
time.Sleep(time.Duration(opts.Delay) * time.Millisecond)

qbclient/resource_records.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ func (o *InsertRecordsOutput) decode(body io.ReadCloser) error { return unmarsha
3939

4040
// InsertRecordsOutputMetadata models the metadata property.
4141
type InsertRecordsOutputMetadata struct {
42-
CreatedRecordIDs []int `json:"createdRecordIds"`
43-
TotalNumberOfRecordsProcessed int `json:"totalNumberOfRecordsProcessed"`
44-
UnchangedRecordIDs []int `json:"unchangedRecordIds"`
45-
UpdatedRecordIDs []int `json:"updatedRecordIds"`
42+
CreatedRecordIDs []int `json:"createdRecordIds"`
43+
LineErrors map[string][]string `json:"lineErrors,omptempty"`
44+
TotalNumberOfRecordsProcessed int `json:"totalNumberOfRecordsProcessed"`
45+
UnchangedRecordIDs []int `json:"unchangedRecordIds"`
46+
UpdatedRecordIDs []int `json:"updatedRecordIds"`
4647
}
4748

4849
// InsertRecords sends a request to POST /v1/records.

0 commit comments

Comments
 (0)