Example #1
0
func (vind *LookupHashUnique) Map(vcursor planbuilder.VCursor, ids []interface{}) ([]key.KeyspaceId, error) {
	out := make([]key.KeyspaceId, 0, len(ids))
	bq := &tproto.BoundQuery{
		Sql: vind.sel,
	}
	for _, id := range ids {
		bq.BindVariables = map[string]interface{}{
			vind.From: id,
		}
		result, err := vcursor.Execute(bq)
		if err != nil {
			return nil, err
		}
		if len(result.Rows) == 0 {
			out = append(out, "")
			continue
		}
		if len(result.Rows) != 1 {
			return nil, fmt.Errorf("unexpected multiple results from vindex %s: %v", vind.Table, id)
		}
		inum, err := mproto.Convert(result.Fields[0].Type, result.Rows[0][0])
		if err != nil {
			return nil, err
		}
		num, err := getNumber(inum)
		if err != nil {
			return nil, err
		}
		out = append(out, vhash(num))
	}
	return out, nil
}
Example #2
0
func (vind *HashVindex) Delete(vcursor planbuilder.VCursor, id interface{}, _ key.KeyspaceId) error {
	bq := &tproto.BoundQuery{
		Sql: vind.del,
		BindVariables: map[string]interface{}{
			vind.Column: id,
		},
	}
	if _, err := vcursor.Execute(bq); err != nil {
		return err
	}
	return nil
}
Example #3
0
func (vind *HashVindex) Generate(vcursor planbuilder.VCursor) (id interface{}, err error) {
	bq := &tproto.BoundQuery{
		Sql: vind.ins,
		BindVariables: map[string]interface{}{
			vind.Column: nil,
		},
	}
	result, err := vcursor.Execute(bq)
	if err != nil {
		return nil, err
	}
	return result.InsertId, err
}
Example #4
0
func (vind *LookupHashUnique) Create(vcursor planbuilder.VCursor, id interface{}, ksid key.KeyspaceId) error {
	bq := &tproto.BoundQuery{
		Sql: vind.ins,
		BindVariables: map[string]interface{}{
			vind.From: id,
			vind.To:   vunhash(ksid),
		},
	}
	if _, err := vcursor.Execute(bq); err != nil {
		return err
	}
	return nil
}
Example #5
0
func (vind *LookupHashUnique) Generate(vcursor planbuilder.VCursor, ksid key.KeyspaceId) (id interface{}, err error) {
	bq := &tproto.BoundQuery{
		Sql: vind.ins,
		BindVariables: map[string]interface{}{
			vind.From: nil,
			vind.To:   vunhash(ksid),
		},
	}
	result, err := vcursor.Execute(bq)
	if err != nil {
		return nil, err
	}
	return result.InsertId, err
}
Example #6
0
func (vind *LookupHashUnique) Verify(vcursor planbuilder.VCursor, id interface{}, ksid key.KeyspaceId) (bool, error) {
	bq := &tproto.BoundQuery{
		Sql: vind.verify,
		BindVariables: map[string]interface{}{
			vind.From: id,
			vind.To:   vunhash(ksid),
		},
	}
	result, err := vcursor.Execute(bq)
	if err != nil {
		return false, err
	}
	if len(result.Rows) == 0 {
		return false, nil
	}
	return true, nil
}