mrproliu opened a new pull request, #1213:
URL: https://github.com/apache/skywalking-banyandb/pull/1213

   ## Background
   
   This is the follow-up requested in review on the parameter-binding PR: 
https://github.com/apache/skywalking-banyandb/pull/1209#discussion_r3541263665
   
   The existing `BindParams` binds parameters by **mutating the parsed grammar 
in place**, so a parsed query can be bound exactly once — it cannot deliver the 
prepared-statement "parse once, bind many" payoff. This PR adds a 
prepared-query API built on that preferred **positional value overlay**: 
`Prepare` numbers the `?` placeholders on an immutable template, `Bind` 
resolves parameters into a per-request overlay, and `TransformBound` reads 
values from that overlay. The template is never written after `Prepare`, so one 
`*PreparedStatement` can be cached and bound concurrently.
   
   ## Usage
   
   ### Prepare once, bind many
   
   ```go
   // Parse and number placeholders once — cache this and reuse it.
   ps, err := bydbql.Prepare(
       "SELECT * FROM STREAM sw IN default WHERE service_id = ? AND duration > 
? LIMIT ?")
   if err != nil {
       return err
   }
   
   // Bind fresh parameters per request; the template is left untouched.
   bq, err := ps.Bind([]*modelv1.TagValue{
       strValue("web"),  // service_id = ?
       intValue(100),    // duration  > ?
       intValue(20),     // LIMIT ?
   })
   if err != nil {
       return err
   }
   
   // Transform reads the values from the per-request overlay.
   result, err := transformer.TransformBound(ctx, bq)
   ```
   
   The same `ps` can be `Bind`-ed again with different parameters, including 
concurrently from multiple goroutines — no re-parsing, no locking.
   
   ### One-shot path is unchanged
   
   Callers that do not reuse a query keep the existing in-place path:
   
   ```go
   g, err := bydbql.ParseQuery(query)
   // ...
   err = bydbql.BindParams(g, params) // mutates g in place; binds exactly once
   result, err := transformer.Transform(ctx, g)
   ```
   
   - [ ] If this pull request closes/resolves/fixes an existing issue, replace 
the issue number. Fixes apache/skywalking#<issue number>.
   - [x] Update the [`CHANGES` 
log](https://github.com/apache/skywalking-banyandb/blob/main/CHANGES.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to