public void Handle(CreateCustomerEvent e)
 {
     using (var conn = _configuration.CreateConnection())
     {
         conn.Open();
         var cmd = conn.CreateCommand();
         cmd.CommandText = "insert into Customer (id, username) values (@username, @username)";
         cmd.AddWithValue("@username", e.Username);
         cmd.ExecuteNonQuery();
     }
 }
Exemple #2
0
 public static void CreateEventTable(DatabaseConfiguration configuration)
 {
     using (var conn = configuration.CreateConnection())
     {
         conn.Open();
         var createTable      = conn.CreateCommand();
         var tableCommandText = $@"create table {configuration.TableName} (
                                     id TEXT,
                                     aggregateId TEXT,
                                     eventType TEXT,
                                     eventDateTime TEXT,
                                     savedTimestamp TEXT,
                                     data BLOB)";
         createTable.CommandText = tableCommandText;
         createTable.ExecuteNonQuery();
     }
 }
        private void Replay()
        {
            var events = new EventList();

            using (var conn = _configuration.CreateConnection())
            {
                conn.Open();
                var cmd = conn.CreateCommand();
                cmd.CommandText = "delete from Customer";
                cmd.ExecuteNonQuery();

                cmd             = conn.CreateCommand();
                cmd.CommandText = "select * from CustomerEvent order by eventDateTime asc";

                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    events.Add(_eventSerializer.Deserialize((string)reader["eventType"], (byte[])reader["Data"]));
                }
            }
            events.ForEach(x => _bus.Post(x));
        }