From a5c83524915de8f06b88f9aa03041308f49d5cd9 Mon Sep 17 00:00:00 2001 From: steffkes Date: Fri, 13 Apr 2018 15:55:51 +0200 Subject: [PATCH] provide sample implementation for store --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2fa5164..f7dda28 100644 --- a/README.md +++ b/README.md @@ -95,11 +95,25 @@ behaviour. defmodule MyApp.ElasticsearchStore do @behaviour Elasticsearch.Store - @impl Elasticsearch.Store - def load(MyApp.Post, offset, limit) do + def load(MyApp.Post, offset, limit) when offset <= 1_000 do # Return MyApp.Posts, restricted by offset and limit + # a sample implementation to get you started: + + [%MyApp.Post{title: "Name", author: "Author"}] + |> Stream.cycle() + |> Stream.map(&Map.put(&1, :id, random_str())) + |> Enum.take(5_000) + end + + def load(_module, _offset, _limit) do + [] + end + + defp random_str do + :crypto.strong_rand_bytes(32) |> Base.encode64() end end + ``` #### Elasticsearch.Document