fix: stabilize runtime follow-up regressions
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
:sig
|
||||
StringMap DTree::to_stringmap() const
|
||||
|
||||
:params
|
||||
return value : a flat `StringMap` projection of the node
|
||||
|
||||
:see
|
||||
>types
|
||||
0_DTree
|
||||
StringMap
|
||||
to_string
|
||||
dtree_keys
|
||||
dtree_values
|
||||
|
||||
:content
|
||||
Converts a `DTree` into a flat `StringMap`. This is a read accessor: it is `const`, never creates or modifies nodes, and dereferences internal references automatically.
|
||||
|
||||
- Map-shaped nodes produce one entry per child, with each child read via `to_string()`. Nested maps flatten to empty strings — this is a one-level projection, not a serializer.
|
||||
- A non-empty scalar produces a single `"value"` entry holding the scalar.
|
||||
- Empty values and unresolvable references produce an empty map.
|
||||
|
||||
Use this when handing request- or config-shaped data to APIs that take `StringMap`, such as `sqlite_query()` / `mysql_query()` parameter maps or `encode_query()`.
|
||||
|
||||
## Example
|
||||
|
||||
```cpp
|
||||
StringMap params = context.props["filters"].to_stringmap();
|
||||
DTree rows = sqlite_query(db, "select * from notes where author = :author", params);
|
||||
```
|
||||
|
||||
For a faithful representation of nested data, use `json_encode()` instead.
|
||||
|
||||
## Related Concepts
|
||||
|
||||
- PHP: casting a one-level array with `array_map('strval', $a)`
|
||||
- JavaScript: `Object.fromEntries(Object.entries(o).map(([k, v]) => [k, String(v)]))`
|
||||
Reference in New Issue
Block a user