# tkvstore

Source: https://zotonic.com/docs/2014/tkvstore

URI: https://zotonic.com/id/2014

Language: en



Simple read-only interface to the typed key-value store of <a href="/id/doc_module_mod_tkvstore" class="doc-reference doc-reference-module"><code>module#mod_tkvstore</code></a>. To get a value from the store: use m.tkvstore.type.key, like this:

```erlang
{% print m.tkvstore.keytype.examplekey %}
```

When the key is not a literal value but a variable or a number, use the following notation:

```erlang
{% print m.tkvstore.keytype[keyvar] %}
```

To store data in a key, use `m_tkvstore:put/4`, as follows:

```erlang
m_tkvstore:put(KeyType, KeyVar, Value, Context).
```

For instance, from within Erlang, let's store edge data for a given edge id, 3434:

```erlang
Edgeid = 3434,
Value = <<"Hello">>,
m_tkvstore:put(edge_data, EdgeId, Value, Context).
```

Now, to retrieve it in the template, do the following:

```erlang
{{ m.tkvstore.edge_data[3434] }}
```

This will output the string `Hello`.

Note that the value can be any type: not only a simple string but also a list, tuple, or any other Erlang composite type.

Available Model API Paths
-------------------------

| Method | Path pattern      | Description                                                                      |
| ------ | ----------------- | -------------------------------------------------------------------------------- |
| `get`  | `/+type/+key/...` | Return admin-only typed-key value from `tkvstore` row (`type = +type`, `key = +key`), yielding stored `props` term or `undefined` when missing. |

`/+name` marks a variable path segment. A trailing `/...` means extra path segments are accepted for further lookups.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2014?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2014?language=en>)
