go,dolt/go: Context propagation in some doltdb methods, pick up ValueReaderWriter context so far.

This commit is contained in:
Aaron Son
2019-04-24 20:43:31 -07:00
parent a8b4290588
commit 946282ab0b
33 changed files with 157 additions and 125 deletions

View File

@@ -1,6 +1,7 @@
package sql
import (
"context"
"errors"
"fmt"
"github.com/attic-labs/noms/go/types"
@@ -21,7 +22,7 @@ var ErrMissingPrimaryKeys = errors.New("one or more primary key columns missing
var ErrConstraintFailure = errors.New("row constraint failed")
// ExecuteSelect executes the given select query and returns the resultant rows accompanied by their output schema.
func ExecuteInsert(db *doltdb.DoltDB, root *doltdb.RootValue, s *sqlparser.Insert, query string) (*InsertResult, error) {
func ExecuteInsert(db *doltdb.DoltDB, root *doltdb.RootValue, s *sqlparser.Insert, query string) (*InsertResult, error) {
tableName := s.Table.Name.String()
if !root.HasTable(tableName) {
return errInsert("Unknown table %v", tableName)
@@ -107,9 +108,9 @@ func ExecuteInsert(db *doltdb.DoltDB, root *doltdb.RootValue, s *sqlparser.Inser
me.Set(key, r.NomsMapValue(tableSch))
}
table = table.UpdateRows(me.Map())
table = table.UpdateRows(context.TODO(), me.Map())
result.Root = root.PutTable(db, tableName, table)
result.Root = root.PutTable(context.TODO(), db, tableName, table)
return &result, nil
}
@@ -149,7 +150,7 @@ func prepareInsertVals(cols []schema.Column, values *sqlparser.Values, tableSch
func makeRow(columns []schema.Column, tableSch schema.Schema, tuple sqlparser.ValTuple) (row.Row, error) {
if len(columns) != len(tuple) {
return errInsertRow("Wrong number of values for tuple %v", nodeToString(tuple))
return errInsertRow("Wrong number of values for tuple %v", nodeToString(tuple))
}
taggedVals := make(row.TaggedValues)
@@ -231,11 +232,11 @@ func makeRow(columns []schema.Column, tableSch schema.Schema, tuple sqlparser.Va
}
// Returns an error result with return type to match ExecuteInsert
func errInsert(errorFmt string, args... interface{}) (*InsertResult, error) {
func errInsert(errorFmt string, args ...interface{}) (*InsertResult, error) {
return nil, errors.New(fmt.Sprintf(errorFmt, args...))
}
// Returns an error result with return type to match ExecuteInsert
func errInsertRow(errorFmt string, args... interface{}) (row.Row, error) {
func errInsertRow(errorFmt string, args ...interface{}) (row.Row, error) {
return nil, errors.New(fmt.Sprintf(errorFmt, args...))
}
}