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
feat: Bind segment values as query parameters (#20)
* feat: Bind segment values as query parameters
Add an optional Binder on TranslateContext that promotes value-bearing
literals to bound query parameters instead of inlining them, so no user
value (notably a regex `%`) reaches a driver that substitutes parameters
by %-formatting the query text. With no Binder the output is unchanged.
beep boop
* test: Add missing When marker to regex binder test
beep boop
Copy file name to clipboardExpand all lines: README.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,36 @@ translator can't handle — typically a REGEX pattern the active dialect's
50
50
regex flavour can't compile. Callers should fall back to
51
51
`flag_engine.is_context_in_segment` for those segments.
52
52
53
+
## Bound parameters
54
+
55
+
By default the translator inlines each segment value as an escaped SQL string literal. Pass a `Binder` on the `TranslateContext` to bind value-bearing literals as query parameters instead.
56
+
57
+
```python
58
+
from flagsmith_sql_flag_engine import (
59
+
Binder,
60
+
PyformatParamStyle,
61
+
TranslateContext,
62
+
translate_segment,
63
+
)
64
+
from flagsmith_sql_flag_engine.dialects import ClickHouseDialect
65
+
66
+
binder = Binder(PyformatParamStyle())
67
+
ctx = TranslateContext(
68
+
evaluation_context=eval_context,
69
+
dialect=ClickHouseDialect(),
70
+
binder=binder,
71
+
)
72
+
where_expr = translate_segment(segment, ctx)
73
+
```
74
+
75
+
Hand both to the driver:
76
+
77
+
```python
78
+
cursor.execute(f"... WHERE ({where_expr})", binder.params)
79
+
```
80
+
81
+
Currently, `%`-prefixed style `PyformatParamStyle` and ClickHouse-specific `ClickHouseServerParamStyle` are supported.
82
+
53
83
## Schema
54
84
55
85
Each dialect publishes the table layout it expects via a `schema_ddl`
0 commit comments