# db

### Utilizing database

`db.key_name:` <mark style="color:purple;">`any`</mark>

`db.key_name = value`

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="410.3276962436035">Description</th></tr></thead><tbody><tr><td><strong>key_name</strong></td><td><strong><code>any</code></strong></td><td>Name of the key</td></tr><tr><td><strong>value</strong></td><td><strong><code>any</code></strong></td><td>Value the key should be set to. This can be anything that can be sanitized (no functions, userdata)</td></tr></tbody></table>

{% hint style="warning" %}
Indexing database keys is a heavy process. Do not do it inside callbacks that are called a lot of times per second.
{% endhint %}

```lua
-- look up for database key named "test"
-- returns the new table if database returned nil
local data = db.test or { }

data.name = 'Salvatore'
data.project = 'Spirthack Innovations LLC'

events.shutdown:set(function()
    -- replace "test" key with the new value
    db.test = data
end)
```
