Skip to content

Commit

Permalink
Fixed #29: Added import / export commands with batching
Browse files Browse the repository at this point in the history
  • Loading branch information
cpliakas committed Feb 5, 2021
1 parent 79fead5 commit b37a880
Show file tree
Hide file tree
Showing 11 changed files with 419 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cmd/records_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var recordsInsertCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
ctx, logger, qb := qbcli.NewClient(cmd, globalCfg)

err := qbcli.SetFieldTypeMap(qb, recordsInsertCfg.GetString("to"))
err := qbcli.CacheTableSchema(qb, recordsInsertCfg.GetString("to"))
qbcli.HandleError(ctx, logger, "error setting field type map", err)

input := &qbclient.InsertRecordsInput{}
Expand Down
40 changes: 40 additions & 0 deletions cmd/table_export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"github.com/QuickBase/quickbase-cli/qbcli"
"github.com/QuickBase/quickbase-cli/qbclient"
"github.com/cpliakas/cliutil"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var tableExportCfg *viper.Viper

var tableExportCmd = &cobra.Command{
Use: "export",
Short: "Export data in a table",

Args: func(cmd *cobra.Command, args []string) (err error) {
if err = globalCfg.Validate(); err == nil {
globalCfg.SetDefaultTableID(tableExportCfg)
qbcli.SetOptionFromArg(tableExportCfg, args, 0, qbclient.OptionTableID)
}
return
},

Run: func(cmd *cobra.Command, args []string) {
ctx, logger, qb := qbcli.NewClient(cmd, globalCfg)

opts := &qbcli.ExportOptions{}
qbcli.GetOptions(ctx, logger, opts, tableExportCfg)

err := qbcli.Export(qb, opts)
qbcli.HandleError(ctx, logger, "error exporting records", err)
},
}

func init() {
var flags *cliutil.Flagger
tableExportCfg, flags = cliutil.AddCommand(tableCmd, tableExportCmd, qbclient.EnvPrefix)
flags.SetOptions(&qbcli.ExportOptions{})
}
40 changes: 40 additions & 0 deletions cmd/table_import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"github.com/QuickBase/quickbase-cli/qbcli"
"github.com/QuickBase/quickbase-cli/qbclient"
"github.com/cpliakas/cliutil"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var tableImportCfg *viper.Viper

var tableImportCmd = &cobra.Command{
Use: "import",
Short: "Import data into a table",

Args: func(cmd *cobra.Command, args []string) (err error) {
if err = globalCfg.Validate(); err == nil {
globalCfg.SetDefaultTableID(tableImportCfg)
qbcli.SetOptionFromArg(tableImportCfg, args, 0, qbclient.OptionTableID)
}
return
},

Run: func(cmd *cobra.Command, args []string) {
ctx, logger, qb := qbcli.NewClient(cmd, globalCfg)

opts := &qbcli.ImportOptions{}
qbcli.GetOptions(ctx, logger, opts, tableImportCfg)

output, err := qbcli.Import(qb, opts)
qbcli.Render(ctx, logger, cmd, globalCfg, output, err)
},
}

func init() {
var flags *cliutil.Flagger
tableImportCfg, flags = cliutil.AddCommand(tableCmd, tableImportCmd, qbclient.EnvPrefix)
flags.SetOptions(&qbcli.ImportOptions{})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.15

require (
github.com/araddon/dateparse v0.0.0-20201001162425-8aadafed4dc4
github.com/cpliakas/cliutil v0.2.3
github.com/cpliakas/cliutil v0.2.4
github.com/go-playground/locales v0.13.0
github.com/go-playground/universal-translator v0.17.0
github.com/go-playground/validator/v10 v10.4.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpliakas/cliutil v0.2.3 h1:mb91difRwnG9A9p8+pNMXCvTuzku/d3cNl2rCClaLBc=
github.com/cpliakas/cliutil v0.2.3/go.mod h1:rHiqeBXCXOikDmm+tpmBGY/afxRNWGfTr9D7dx217e4=
github.com/cpliakas/cliutil v0.2.4 h1:gyMtCwHA6ImmNflbjTHW4WhMGsrGoGGLodZFD9+0JKo=
github.com/cpliakas/cliutil v0.2.4/go.mod h1:rHiqeBXCXOikDmm+tpmBGY/afxRNWGfTr9D7dx217e4=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
Loading

0 comments on commit b37a880

Please sign in to comment.