[Groonga-commit] groonga/grnci at 3c139c1 [master] Simplify DB.LogicalSelect and DB.LogicalSelectRows.

Back to archive index

Susumu Yata null+****@clear*****
Tue Sep 12 16:48:17 JST 2017


Susumu Yata	2017-09-12 16:48:17 +0900 (Tue, 12 Sep 2017)

  New Revision: 3c139c1c4215dd5f376465083b69a84112f7120e
  https://github.com/groonga/grnci/commit/3c139c1c4215dd5f376465083b69a84112f7120e

  Message:
    Simplify DB.LogicalSelect and DB.LogicalSelectRows.
    
    Ref: #42

  Modified files:
    v2/db.go

  Modified: v2/db.go (+14 -13)
===================================================================
--- v2/db.go    2017-09-12 16:46:05 +0900 (32196dd)
+++ v2/db.go    2017-09-12 16:48:17 +0900 (40d3c04)
@@ -773,7 +773,7 @@ func NewDBLogicalSelectOptions() *DBLogicalSelectOptions {
 }
 
 // LogicalSelect executes logical_select.
-func (db *DB) LogicalSelect(logicalTable, shardKey string, options *DBLogicalSelectOptions) (io.ReadCloser, Response, error) {
+func (db *DB) LogicalSelect(logicalTable, shardKey string, options *DBLogicalSelectOptions) (io.ReadCloser, error) {
 	if options == nil {
 		options = NewDBLogicalSelectOptions()
 	}
@@ -838,19 +838,23 @@ func (db *DB) LogicalSelect(logicalTable, shardKey string, options *DBLogicalSel
 	}
 	resp, err := db.Invoke("logical_select", params, nil)
 	if err != nil {
-		return nil, nil, err
+		return nil, err
+	}
+	if resp.Err() != nil {
+		resp.Close()
+		return nil, resp.Err()
 	}
-	return resp, resp, err
+	return resp, nil
 }
 
 // LogicalSelectRows executes logical_select.
-func (db *DB) LogicalSelectRows(logicalTable, shardKey string, rows interface{}, options *DBLogicalSelectOptions) (int, Response, error) {
+func (db *DB) LogicalSelectRows(logicalTable, shardKey string, rows interface{}, options *DBLogicalSelectOptions) (int, error) {
 	if options == nil {
 		options = NewDBLogicalSelectOptions()
 	}
 	rs, err := GetRowStruct(rows)
 	if err != nil {
-		return 0, nil, err
+		return 0, err
 	}
 	var cfs []*ColumnField
 	if options.OutputColumns == nil {
@@ -862,27 +866,24 @@ func (db *DB) LogicalSelectRows(logicalTable, shardKey string, rows interface{},
 		for _, col := range options.OutputColumns {
 			cf, ok := rs.ColumnsByName[col]
 			if !ok {
-				return 0, nil, NewError(CommandError, "The column has no associated field.", map[string]interface{}{
+				return 0, NewError(CommandError, "The column has no associated field.", map[string]interface{}{
 					"column": col,
 				})
 			}
 			cfs = append(cfs, cf)
 		}
 	}
-	result, resp, err := db.LogicalSelect(logicalTable, shardKey, options)
+	result, err := db.LogicalSelect(logicalTable, shardKey, options)
 	if err != nil {
-		return 0, nil, err
+		return 0, err
 	}
 	defer result.Close()
 	data, err := ioutil.ReadAll(result)
 	if err != nil {
-		return 0, resp, err
-	}
-	if resp.Err() != nil {
-		return 0, resp, err
+		return 0, err
 	}
 	n, err := db.parseRows(rows, data, cfs)
-	return n, resp, err
+	return n, err
 }
 
 // DBLogicalShard is a result of logical_shard_list.
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170912/043e4397/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index