You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+95Lines changed: 95 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -233,6 +233,101 @@ They can also be created based on a list of Conditions:
233
233
}).Delete()
234
234
ovs.Transact(ops...)
235
235
236
+
### Querying with Select
237
+
238
+
The `Select` operation is used to build an OVSDB `select` query. Unlike the `List` operation, which returns results directly from the cache, `Select` only generates an `ovsdb.Operation`. You must pass this operation to `Transact` to execute it against the database, and then use a helper function like `GetSelectResults` to parse the reply.
239
+
240
+
The core workflow is: `WhereXxx(...).Select() -> Transact(...) -> GetSelectResults(...)`
241
+
242
+
#### Selecting Rows
243
+
244
+
**Select All Rows from a Table:**
245
+
246
+
To select all rows from a table, you can call `Where()` with a zero-value instance of the model struct (e.g., `&MyLogicalSwitch{}`). This sets the table context for the `Select` operation without adding any conditions.
247
+
248
+
```go
249
+
// var ovs client.Client
250
+
// var ctx context.Context
251
+
// var allSwitches []MyLogicalSwitch
252
+
// 1. Generate Op: Where(&MyLogicalSwitch{}) specifies the table
You can also use `Where()` with a model instance that has indexed fields populated. This will create a condition to find matching rows based on the first available index.
266
+
267
+
```go
268
+
// Assuming "Name" is an indexed field
269
+
ls:= &MyLogicalSwitch{Name: "switch1"}
270
+
varresults []MyLogicalSwitch
271
+
// 1. Generate Op
272
+
selectOp, err:= ovs.Where(ls).Select()
273
+
// ...
274
+
// 2. Transact and parse
275
+
reply, err:= ovs.Transact(ctx, selectOp...)
276
+
err = ovs.GetSelectResults(reply, &results)
277
+
// ...
278
+
```
279
+
280
+
**Select with Conditions (AND):**
281
+
282
+
Use `WhereAll()` to set the table context and one or more filter conditions. All conditions are combined with an `AND` operator.
By default, `Select` queries all columns of a table. You can pass column names to the `Select` method to retrieve only specific columns. The `_uuid` column is always included in the result.
-`WhereCache(...).Select()`: **Not supported**. Cache-based predicate functions cannot be translated into OVSDB query conditions. Calling `Select` after `WhereCache` will return an error.
330
+
236
331
## Monitor for updates
237
332
238
333
You can also register a notification handler to get notified every time an element is added, deleted or updated from the database.
0 commit comments