Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from ryokdy/v0.4
Browse files Browse the repository at this point in the history
extend ROW_LIMIT for import and fix a bug
  • Loading branch information
ymmt2005 committed Oct 27, 2015
2 parents d3ebccf + da19c23 commit 3b6c918
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cli-kintone is a command line utility for kintone.

## Version

0.3
0.4

## How to Build

Expand Down
12 changes: 6 additions & 6 deletions export.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func getRecords(app *kintone.App, fields []string, offset int64) ([]*kintone.Record, error) {

newQuery := config.query + fmt.Sprintf(" limit %v offset %v", ROW_LIMIT, offset)
newQuery := config.query + fmt.Sprintf(" limit %v offset %v", EXPORT_ROW_LIMIT, offset)
records, err := app.GetRecords(fields, newQuery)
if err != nil {
return nil, err
Expand All @@ -36,7 +36,7 @@ func writeJson(app *kintone.App) error {
writer := getWriter()

fmt.Fprint(writer, "{\"records\": [\n")
for ;;offset += ROW_LIMIT {
for ;;offset += EXPORT_ROW_LIMIT {
records, err := getRecords(app, config.fields, offset)
if err != nil {
return err
Expand All @@ -50,7 +50,7 @@ func writeJson(app *kintone.App) error {
fmt.Fprint(writer, json)
i += 1
}
if len(records) < ROW_LIMIT {
if len(records) < EXPORT_ROW_LIMIT {
break
}
}
Expand Down Expand Up @@ -145,13 +145,13 @@ func writeCsv(app *kintone.App) error {
return err
}

for ;;offset += ROW_LIMIT {
hasTable := false
for ;;offset += EXPORT_ROW_LIMIT {
records, err := getRecords(app, config.fields, offset)
if err != nil {
return err
}

hasTable := false
for _, record := range records {
if i == 0 {
// write csv header
Expand Down Expand Up @@ -216,7 +216,7 @@ func writeCsv(app *kintone.App) error {
}
i++
}
if len(records) < ROW_LIMIT {
if len(records) < EXPORT_ROW_LIMIT {
break
}
}
Expand Down
10 changes: 5 additions & 5 deletions import.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func readCsv(app *kintone.App, filePath string) error {

head := true
updating := false
records := make([]*kintone.Record, 0, ROW_LIMIT)
records := make([]*kintone.Record, 0, IMPORT_ROW_LIMIT)
var columns Columns

// retrieve field list
Expand Down Expand Up @@ -157,9 +157,9 @@ func readCsv(app *kintone.App, filePath string) error {
} else {
records = append(records, kintone.NewRecord(record))
}
if len(records) >= ROW_LIMIT {
if len(records) >= IMPORT_ROW_LIMIT {
upsert(app, records[:], updating)
records = make([]*kintone.Record, 0, ROW_LIMIT)
records = make([]*kintone.Record, 0, IMPORT_ROW_LIMIT)
}
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func upsert(app *kintone.App, recs []*kintone.Record, updating bool) error {
func deleteRecords(app *kintone.App) error {
var lastId uint64 = 0
for {
ids := make([]uint64, 0, ROW_LIMIT)
ids := make([]uint64, 0, IMPORT_ROW_LIMIT)
records, err := getRecords(app, []string{"$id"}, 0)
if err != nil {
return err
Expand All @@ -204,7 +204,7 @@ func deleteRecords(app *kintone.App) error {
return err
}

if len(records) < ROW_LIMIT {
if len(records) < IMPORT_ROW_LIMIT {
break
}
if lastId == ids[0] {
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type Configure struct {

var config Configure

const ROW_LIMIT = 100
const IMPORT_ROW_LIMIT = 100
const EXPORT_ROW_LIMIT = 500

type Column struct {
Code string
Expand Down

0 comments on commit 3b6c918

Please sign in to comment.