# `ApifyClient.KeyValueStores`
[🔗](https://github.com/social-growth-studio/apify-client-ex/blob/v1.0.0/lib/apify_client/key_value_stores.ex#L1)

Key-value store records: get, set and delete them.

    :ok = ApifyClient.KeyValueStores.put_record(store_id, "state", %{"page" => 2})
    {:ok, %{"page" => 2}} = ApifyClient.KeyValueStores.get_record(store_id, "state")

    :ok = ApifyClient.KeyValueStores.put_record(store_id, "shot", png, content_type: "image/png")
    {:ok, ^png} = ApifyClient.KeyValueStores.get_record(store_id, "shot")

Functions take the connection options described in `ApifyClient.Client`
(`:token`, `:config`, ...) next to their own. For everything else about
key-value stores, see `ApifyClient.API.KeyValueStores` and the modules below it.

# `delete_record`

```elixir
@spec delete_record(String.t(), String.t(), keyword()) ::
  :ok | {:error, ApifyClient.Error.t()}
```

Deletes a record.

# `get_record`

```elixir
@spec get_record(String.t(), String.t(), keyword()) ::
  {:ok, term()} | {:error, ApifyClient.Error.t()}
```

Gets a record's value.

JSON records are decoded (maps with string keys); other records come back as
the raw binary. A missing record is `{:error, %ApifyClient.Error{type:
:not_found_error}}`.

# `list_keys`

```elixir
@spec list_keys(String.t(), keyword()) ::
  {:ok, ApifyClient.Schemas.ListOfKeys.t()} | {:error, ApifyClient.Error.t()}
```

Lists record keys, one page at a time.

## Options

  * `:limit` - keys per page (at most 1000)
  * `:exclusive_start_key` - list keys after this one; pass the previous page's
    `next_exclusive_start_key` to get the next page
  * `:prefix` - only keys starting with this
  * `:collection` - only keys in this collection

# `put_record`

```elixir
@spec put_record(String.t(), String.t(), term(), keyword()) ::
  :ok | {:error, ApifyClient.Error.t()}
```

Sets a record.

Maps and lists are stored as JSON. Binaries are stored as they are, as
`text/plain; charset=utf-8` when valid UTF-8 and `application/octet-stream`
otherwise, unless `:content_type` says otherwise.

## Options

  * `:content_type` - content type of the record

# `record_exists?`

```elixir
@spec record_exists?(String.t(), String.t(), keyword()) ::
  {:ok, boolean()} | {:error, ApifyClient.Error.t()}
```

Whether a record exists.

# `stream_keys`

```elixir
@spec stream_keys(String.t(), keyword()) :: Enumerable.t()
```

Streams all keys of a store (`ApifyClient.Schemas.KeyValueStoreKey` structs,
with `key` and `size`), fetching them page by page as the stream is consumed.

Raises `ApifyClient.Error` if a page can't be fetched.

## Options

  * `:prefix` - only keys starting with this
  * `:collection` - only keys in this collection
  * `:exclusive_start_key` - start after this key
  * `:limit` - maximum number of keys in the whole stream (default: all)
  * `:page_size` - keys per request (default and maximum: 1000)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
