Skip to content

Instantly share code, notes, and snippets.

@YoEight
Last active September 27, 2019 06:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YoEight/c3d7917bdf6d325bea7b78247284d2b1 to your computer and use it in GitHub Desktop.
Save YoEight/c3d7917bdf6d325bea7b78247284d2b1 to your computer and use it in GitHub Desktop.
eventstore client showdown
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NumericUnderscores #-}
module Main where
import Control.Monad
import Database.EventStore
import qualified Data.Text as Text
import Data.Aeson
import Data.Aeson.TH
data Foo =
Foo
{ firstName :: Text.Text
, lastName :: Text.Text
, age :: Int
, tags :: [Text.Text]
}
$(deriveJSON defaultOptions ''Foo)
userFoo :: Foo
userFoo =
Foo
{ firstName = "Foo"
, lastName = "Bar"
, age = 150
, tags = ["haskell", "rust"]
}
fooEvent :: Event
fooEvent =
createEvent "foo-type" Nothing (withJson userFoo)
main :: IO ()
main = do
conn <- connect defaultSettings (Static "localhost" 1113)
replicateM_ 100_000 $
void $ sendEvent conn (StreamName "foo-stream") anyVersion fooEvent Nothing
shutdown conn
waitTillClosed conn
#[macro_use]
extern crate serde_derive;
#[derive(Serialize, Deserialize, Clone)]
struct Foo {
first_name: String,
last_name: String,
age: usize,
tags: Vec<String>,
}
fn main() {
let connection = eventstore::Connection::builder()
.single_node_connection("127.0.0.1:1113".parse().unwrap());
let foo_user = Foo {
first_name: "Foo".to_owned(),
last_name: "Bar".to_owned(),
age: 150,
tags: vec!("rust".to_owned(), "haskell".to_owned()),
};
let mut i = 1usize;
loop {
i += 1;
let event = eventstore::EventData::json("foo-stream", foo_user.clone()).unwrap();
let _ = connection
.write_events("foo-stream")
.push_event(event)
.execute();
if i > 100_000 {
break;
}
}
connection.shutdown();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment