37 lines
1.2 KiB
Plaintext
37 lines
1.2 KiB
Plaintext
:sig
|
|
StringMap DValue::to_stringmap() const
|
|
|
|
:params
|
|
return value : a flat `StringMap` projection of the node
|
|
|
|
:see
|
|
>types
|
|
0_DValue
|
|
StringMap
|
|
to_string
|
|
dv_keys
|
|
dv_values
|
|
|
|
:content
|
|
Converts a `DValue` 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();
|
|
DValue 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)]))`
|