ovn-org / libovsdb

An OVSDB Client Library written in Golang
Apache License 2.0
183 stars 153 forks source link

How to use where if not implemented explicitConditional.Matches? #301

Open ganmao opened 2 years ago

ganmao commented 2 years ago
ovs.Where(ls, client.Condition {
    Field: &ls.UUID,
    Function: ovsdb.ConditionEqual,
    Value: "myUUID"},
    })

github.com/ovn-org/libovsdb@v0.6.0/client/condition.go:80

func (c *explicitConditional) Matches(m model.Model) (bool, error) {
    return false, fmt.Errorf("cannot perform cache comparisons using explicit conditions")
}
ganmao commented 2 years ago

github.com/ovn-org/libovsdb@v0.6.0/client/api.go:185

func (a api) conditionFromModel(any bool, model model.Model, cond ...model.Condition) Conditional {
    var conditional Conditional
    var err error

    tableName, err := a.getTableFromModel(model)
    if tableName == "" {
        return newErrorConditional(err)
    }

    if len(cond) == 0 {
        conditional, err = newEqualityConditional(a.cache.Mapper(), tableName, any, model)
        if err != nil {
            conditional = newErrorConditional(err)
        }

    } else {
        conditional, err = newExplicitConditional(a.cache.Mapper(), tableName, any, model, cond...)
        if err != nil {
            conditional = newErrorConditional(err)
        }
    }
    return conditional
}
amorenoz commented 2 years ago

You can use Where to perform server-side matches, i.e: methods such as Delete, Update, Mutate. If you want to use List or Get that operate on the cache, rather than sending commands to the server, you currently need to use WhereCache. At least until #128 is implemented.