diff --git a/README.md b/README.md index bcc6acd..450c379 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ cli-kintone is a command line utility for kintone. ## Version -0.3 +0.4 ## How to Build diff --git a/export.go b/export.go index fe283bf..ce00e63 100644 --- a/export.go +++ b/export.go @@ -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 @@ -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 @@ -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 } } @@ -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 @@ -216,7 +216,7 @@ func writeCsv(app *kintone.App) error { } i++ } - if len(records) < ROW_LIMIT { + if len(records) < EXPORT_ROW_LIMIT { break } } diff --git a/import.go b/import.go index 33067f8..df575ae 100644 --- a/import.go +++ b/import.go @@ -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 @@ -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) } } } @@ -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 @@ -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] { diff --git a/main.go b/main.go index 6de81c6..01fc890 100644 --- a/main.go +++ b/main.go @@ -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