mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-21 11:29:51 -05:00
moving option inside of datamover
This commit is contained in:
@@ -190,6 +190,10 @@ type tableOptions struct {
|
||||
batched bool
|
||||
}
|
||||
|
||||
func (m tableOptions) IsBatched() bool {
|
||||
return m.batched
|
||||
}
|
||||
|
||||
func (m tableOptions) WritesToTable() bool {
|
||||
return false
|
||||
}
|
||||
@@ -252,7 +256,7 @@ func getTableWriter(ctx context.Context, dEnv *env.DoltEnv, tblOpts *tableOption
|
||||
return nil, errhand.BuildDError("Could not create table writer for %s", tblOpts.tableName).AddCause(err).Build()
|
||||
}
|
||||
|
||||
wr, err := tblOpts.dest.NewCreatingWriter(ctx, tblOpts, tblOpts.batched, root, outSch, opts, writer)
|
||||
wr, err := tblOpts.dest.NewCreatingWriter(ctx, tblOpts, root, outSch, opts, writer)
|
||||
if err != nil {
|
||||
return nil, errhand.BuildDError("Could not create table writer for %s", tblOpts.tableName).AddCause(err).Build()
|
||||
}
|
||||
|
||||
@@ -65,6 +65,10 @@ func (m exportOptions) checkOverwrite(ctx context.Context, root *doltdb.RootValu
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (m exportOptions) IsBatched() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (m exportOptions) WritesToTable() bool {
|
||||
return false
|
||||
}
|
||||
@@ -238,7 +242,7 @@ func getTableWriter(ctx context.Context, root *doltdb.RootValue, dEnv *env.DoltE
|
||||
return nil, errhand.BuildDError("Error opening writer for %s.", exOpts.DestName()).AddCause(err).Build()
|
||||
}
|
||||
|
||||
wr, err := exOpts.dest.NewCreatingWriter(ctx, exOpts, false, root, rdSchema, editor.Options{Deaf: dEnv.DbEaFactory()}, writer)
|
||||
wr, err := exOpts.dest.NewCreatingWriter(ctx, exOpts, root, rdSchema, editor.Options{Deaf: dEnv.DbEaFactory()}, writer)
|
||||
if err != nil {
|
||||
return nil, errhand.BuildDError("Error opening writer for %s.", exOpts.DestName()).AddCause(err).Build()
|
||||
}
|
||||
|
||||
@@ -103,6 +103,10 @@ type importOptions struct {
|
||||
ignoreSkippedRows bool
|
||||
}
|
||||
|
||||
func (m importOptions) IsBatched() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (m importOptions) WritesToTable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ type DataLocation interface {
|
||||
|
||||
// NewCreatingWriter will create a TableWriteCloser for a DataLocation that will create a new table, or overwrite
|
||||
// an existing table.
|
||||
NewCreatingWriter(ctx context.Context, mvOpts DataMoverOptions, batched bool, root *doltdb.RootValue, outSch schema.Schema, opts editor.Options, wr io.WriteCloser) (table.SqlTableWriter, error)
|
||||
NewCreatingWriter(ctx context.Context, mvOpts DataMoverOptions, root *doltdb.RootValue, outSch schema.Schema, opts editor.Options, wr io.WriteCloser) (table.SqlTableWriter, error)
|
||||
}
|
||||
|
||||
// NewDataLocation creates a DataLocation object from a path and a format string. If the path is the name of a table
|
||||
|
||||
@@ -160,6 +160,10 @@ func TestExists(t *testing.T) {
|
||||
|
||||
type testDataMoverOptions struct{}
|
||||
|
||||
func (t testDataMoverOptions) IsBatched() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (t testDataMoverOptions) WritesToTable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ type MoverOptions struct {
|
||||
}
|
||||
|
||||
type DataMoverOptions interface {
|
||||
IsBatched() bool
|
||||
WritesToTable() bool
|
||||
SrcName() string
|
||||
DestName() string
|
||||
|
||||
@@ -178,7 +178,7 @@ func (dl FileDataLocation) NewReader(ctx context.Context, root *doltdb.RootValue
|
||||
|
||||
// NewCreatingWriter will create a TableWriteCloser for a DataLocation that will create a new table, or overwrite
|
||||
// an existing table.
|
||||
func (dl FileDataLocation) NewCreatingWriter(ctx context.Context, mvOpts DataMoverOptions, batched bool, root *doltdb.RootValue, outSch schema.Schema, opts editor.Options, wr io.WriteCloser) (table.SqlTableWriter, error) {
|
||||
func (dl FileDataLocation) NewCreatingWriter(ctx context.Context, mvOpts DataMoverOptions, root *doltdb.RootValue, outSch schema.Schema, opts editor.Options, wr io.WriteCloser) (table.SqlTableWriter, error) {
|
||||
switch dl.Format {
|
||||
case CsvFile:
|
||||
return csv.NewCSVWriter(wr, outSch, csv.NewCSVInfo())
|
||||
@@ -189,7 +189,7 @@ func (dl FileDataLocation) NewCreatingWriter(ctx context.Context, mvOpts DataMov
|
||||
case JsonFile:
|
||||
return json.NewJSONWriter(wr, outSch)
|
||||
case SqlFile:
|
||||
if batched {
|
||||
if mvOpts.IsBatched() {
|
||||
return sqlexport.OpenBatchedSQLExportWriter(ctx, wr, root, mvOpts.SrcName(), outSch, opts)
|
||||
} else {
|
||||
return sqlexport.OpenSQLExportWriter(ctx, wr, root, mvOpts.SrcName(), outSch, opts)
|
||||
|
||||
@@ -73,7 +73,7 @@ func (dl StreamDataLocation) NewReader(ctx context.Context, root *doltdb.RootVal
|
||||
|
||||
// NewCreatingWriter will create a TableWriteCloser for a DataLocation that will create a new table, or overwrite
|
||||
// an existing table.
|
||||
func (dl StreamDataLocation) NewCreatingWriter(ctx context.Context, mvOpts DataMoverOptions, batched bool, root *doltdb.RootValue, outSch schema.Schema, opts editor.Options, wr io.WriteCloser) (table.SqlTableWriter, error) {
|
||||
func (dl StreamDataLocation) NewCreatingWriter(ctx context.Context, mvOpts DataMoverOptions, root *doltdb.RootValue, outSch schema.Schema, opts editor.Options, wr io.WriteCloser) (table.SqlTableWriter, error) {
|
||||
switch dl.Format {
|
||||
case CsvFile:
|
||||
return csv.NewCSVWriter(iohelp.NopWrCloser(dl.Writer), outSch, csv.NewCSVInfo())
|
||||
|
||||
@@ -91,7 +91,7 @@ func RowAsInsertStmt(r row.Row, tableName string, tableSch schema.Schema) (strin
|
||||
return b.String(), nil
|
||||
}
|
||||
|
||||
func InsertStatementPrefix(ctx context.Context, tableName string, tableSch schema.Schema) (string, error) {
|
||||
func InsertStatementPrefix(tableName string, tableSch schema.Schema) (string, error) {
|
||||
var b strings.Builder
|
||||
|
||||
b.WriteString("INSERT INTO ")
|
||||
|
||||
@@ -118,7 +118,7 @@ func (w *BatchSqlExportWriter) WriteSqlRow(ctx context.Context, r sql.Row) error
|
||||
// Append insert values as tuples
|
||||
if w.numInserts == 0 {
|
||||
// Get insert prefix string
|
||||
prefix, err := sqlfmt.InsertStatementPrefix(ctx, w.tableName, w.sch)
|
||||
prefix, err := sqlfmt.InsertStatementPrefix(w.tableName, w.sch)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user