// CreatePrimaryIndex implements datastore.Indexer{} interface. Create or // return a primary index on this keyspace func (gsi *gsiKeyspace) CreatePrimaryIndex( requestId, name string, with value.Value) (datastore.PrimaryIndex, errors.Error) { var withJSON []byte var err error if with != nil { if withJSON, err = with.MarshalJSON(); err != nil { return nil, errors.NewError(err, "GSI error marshalling WITH clause") } } defnID, err := gsi.gsiClient.CreateIndex( name, gsi.keyspace, /*bucket-name*/ string(c.ForestDB), /*using, by default always forestdb*/ "N1QL", /*exprType*/ "", /*partnStr*/ "", /*whereStr*/ nil, /*secStrs*/ true, /*isPrimary*/ withJSON) if err != nil { return nil, errors.NewError(err, "GSI CreatePrimaryIndex()") } // refresh to get back the newly created index. if err := gsi.Refresh(); err != nil { return nil, err } index, errr := gsi.IndexById(defnID2String(defnID)) if errr != nil { return nil, errr } return index.(datastore.PrimaryIndex), nil }
func (this *Base64) Apply(context Context, operand value.Value) (value.Value, error) { if operand.Type() == value.MISSING { return operand, nil } bytes, _ := operand.MarshalJSON() // Ignore errors from BINARY values str := base64.StdEncoding.EncodeToString(bytes) return value.NewValue(str), nil }
// CreateIndex implements datastore.Indexer{} interface. Create a secondary // index on this keyspace func (gsi *gsiKeyspace) CreateIndex( requestId, name string, seekKey, rangeKey expression.Expressions, where expression.Expression, with value.Value) ( datastore.Index, errors.Error) { var partnStr string if seekKey != nil && len(seekKey) > 0 { partnStr = expression.NewStringer().Visit(seekKey[0]) } var whereStr string if where != nil { whereStr = expression.NewStringer().Visit(where) } secStrs := make([]string, len(rangeKey)) for i, key := range rangeKey { s := expression.NewStringer().Visit(key) secStrs[i] = s } var withJSON []byte var err error if with != nil { if withJSON, err = with.MarshalJSON(); err != nil { return nil, errors.NewError(err, "GSI error marshalling WITH clause") } } defnID, err := gsi.gsiClient.CreateIndex( name, gsi.keyspace, /*bucket-name*/ string(c.ForestDB), /*using, by default always forestdb*/ "N1QL", /*exprType*/ partnStr, whereStr, secStrs, false, /*isPrimary*/ withJSON) if err != nil { return nil, errors.NewError(err, "GSI CreateIndex()") } // refresh to get back the newly created index. if err := gsi.Refresh(); err != nil { return nil, err } return gsi.IndexById(defnID2String(defnID)) }
func doGetPrepared(prepared_stmt value.Value, track bool) (*Prepared, errors.Error) { switch prepared_stmt.Type() { case value.STRING: prepared := cache.get(prepared_stmt, track) if prepared == nil { return nil, errors.NewNoSuchPreparedError(prepared_stmt.Actual().(string)) } return prepared, nil case value.OBJECT: name_value, has_name := prepared_stmt.Field("name") if has_name { if prepared := cache.get(name_value, track); prepared != nil { return prepared, nil } } prepared_bytes, err := prepared_stmt.MarshalJSON() if err != nil { return nil, errors.NewUnrecognizedPreparedError(err) } return unmarshalPrepared(prepared_bytes) default: return nil, errors.NewUnrecognizedPreparedError(fmt.Errorf("Invalid prepared stmt %v", prepared_stmt)) } }
/* This method returns a number value that represents the length of the bytes slice returned by the MarshalJSON method cast to a float64 value. */ func (this *EncodedSize) Apply(context Context, arg value.Value) (value.Value, error) { bytes, _ := arg.MarshalJSON() return value.NewValue(float64(len(bytes))), nil }
/* This method returns a Json encoded string by sing the MarshalJSON method. The return bytes value is cast to a string and returned. */ func (this *JSONEncode) Apply(context Context, arg value.Value) (value.Value, error) { bytes, _ := arg.MarshalJSON() return value.NewValue(string(bytes)), nil }