Susumu Yata
null+****@clear*****
Fri Jun 16 15:37:24 JST 2017
Susumu Yata 2017-06-16 15:37:24 +0900 (Fri, 16 Jun 2017) New Revision: 8c2940046c9d01781e198c2f998575dea1f32cd1 https://github.com/groonga/grnci/commit/8c2940046c9d01781e198c2f998575dea1f32cd1 Message: Update v2. Modified files: v2/command.go v2/db.go Modified: v2/command.go (+1 -1) =================================================================== --- v2/command.go 2017-06-16 10:52:57 +0900 (3b97da3) +++ v2/command.go 2017-06-16 15:37:24 +0900 (b5bfac0) @@ -334,7 +334,7 @@ var commandFormats = map[string]*commandFormat{ newParamFormat("output_columns", formatParamValueCSV, false), newParamFormat("offset", nil, false), newParamFormat("limit", nil, false), - newParamFormat("drilldown", nil, false), + newParamFormat("drilldown", formatParamValueCSV, false), newParamFormat("drilldown_sortby", formatParamValueCSV, false), newParamFormat("drilldown_output_columns", formatParamValueCSV, false), newParamFormat("drilldown_offset", nil, false), Modified: v2/db.go (+91 -11) =================================================================== --- v2/db.go 2017-06-16 10:52:57 +0900 (418f6c2) +++ v2/db.go 2017-06-16 15:37:24 +0900 (442a49f) @@ -22,7 +22,7 @@ func NewDB(h Handler) *DB { } // ColumnCreate executes column_create. -func (db *DB) ColumnCreate(tbl, name, typ, flags string) (bool, Response, error) { +func (db *DB) ColumnCreate(tbl, name, typ string, flags []string) (bool, Response, error) { cmd, err := NewCommand("column_create", map[string]interface{}{ "table": tbl, "name": name, @@ -44,13 +44,9 @@ func (db *DB) ColumnCreate(tbl, name, typ, flags string) (bool, Response, error) withSection = true } } - if flags == "" { - flags = typFlag - } else { - flags += "|" + typFlag - } + flags = append(flags, typFlag) if withSection { - flags += "|WITH_SECTION" + flags = append(flags, "WITH_SECTION") } if err := cmd.SetParam("flags", flags); err != nil { return false, nil, err @@ -110,6 +106,90 @@ func (db *DB) ColumnRemove(tbl, name string) (bool, Response, error) { return result, resp, nil } +// DeleteByID executes delete. +func (db *DB) DeleteByID(tbl string, id int) (bool, Response, error) { + cmd, err := NewCommand("delete", map[string]interface{}{ + "table": tbl, + "id": id, + }) + if err != nil { + return false, nil, err + } + resp, err := db.Query(cmd) + if err != nil { + return false, nil, err + } + defer resp.Close() + jsonData, err := ioutil.ReadAll(resp) + if err != nil { + return false, resp, err + } + var result bool + if err := json.Unmarshal(jsonData, &result); err != nil { + return false, resp, NewError(InvalidResponse, map[string]interface{}{ + "method": "json.Unmarshal", + "error": err.Error(), + }) + } + return result, resp, nil +} + +// DeleteByKey executes delete. +func (db *DB) DeleteByKey(tbl string, key interface{}) (bool, Response, error) { + cmd, err := NewCommand("delete", map[string]interface{}{ + "table": tbl, + "key": key, + }) + if err != nil { + return false, nil, err + } + resp, err := db.Query(cmd) + if err != nil { + return false, nil, err + } + defer resp.Close() + jsonData, err := ioutil.ReadAll(resp) + if err != nil { + return false, resp, err + } + var result bool + if err := json.Unmarshal(jsonData, &result); err != nil { + return false, resp, NewError(InvalidResponse, map[string]interface{}{ + "method": "json.Unmarshal", + "error": err.Error(), + }) + } + return result, resp, nil +} + +// DeleteByFilter executes delete. +func (db *DB) DeleteByFilter(tbl, filter string) (bool, Response, error) { + cmd, err := NewCommand("delete", map[string]interface{}{ + "table": tbl, + "filter": filter, + }) + if err != nil { + return false, nil, err + } + resp, err := db.Query(cmd) + if err != nil { + return false, nil, err + } + defer resp.Close() + jsonData, err := ioutil.ReadAll(resp) + if err != nil { + return false, resp, err + } + var result bool + if err := json.Unmarshal(jsonData, &result); err != nil { + return false, resp, NewError(InvalidResponse, map[string]interface{}{ + "method": "json.Unmarshal", + "error": err.Error(), + }) + } + return result, resp, nil +} + // DBDumpOptions stores options for DB.Dump. type DBDumpOptions struct { Tables string // --table @@ -315,7 +395,7 @@ type DBSelectOptions struct { OutputColumns []string // --output_columns Offset int // --offset Limit int // --limit - Drilldown string // --drilldown + Drilldown []string // --drilldown DrilldownSortKeys []string // --drilldown_sort_keys DrilldownOutputColumns []string // --drilldown_output_columns DrilldownOffset int // --drilldown_offset @@ -374,7 +454,7 @@ func (db *DB) Select(tbl string, options *DBSelectOptions) (Response, error) { if options.Limit != 10 { params["limit"] = options.Limit } - if options.Drilldown != "" { + if options.Drilldown != nil { params["drilldown"] = options.Drilldown } if options.DrilldownSortKeys != nil { @@ -420,9 +500,9 @@ func (db *DB) Select(tbl string, options *DBSelectOptions) (Response, error) { } // SelectRows executes select. -func (db *DB) SelectRows(tbl string, rows interface{}, options *DBSelectOptions) (Response, error) { +func (db *DB) SelectRows(tbl string, rows interface{}, options *DBSelectOptions) (int, Response, error) { // TODO - return nil, nil + return 0, nil, nil } // DBStatusResult is a response of status. -------------- next part -------------- HTML����������������������������...ダウンロード