by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Nick Childers
    @Voltir
    cool project - and nice timing. I have been debating akka-persistence vs slick for a particular feature im working on, and then this project comes along
    Nick Childers
    @Voltir
    Um, where does EventMachine instance come from? Im trying to track that down in the example project and I kind of got lost.
    nm, found it
    Nick Childers
    @Voltir

    Ok, actual question:

    [error]  found   : models.generated.StabPostgresDriver.profile.api.Database
    [error]     (which expands to)  slick.jdbc.JdbcBackend#DatabaseDef
    [error]  required: slick.jdbc.JdbcBackend.Database
    [error]     (which expands to)  slick.jdbc.JdbcBackend.DatabaseDef
    [error]   override lazy val eventsDatabase = new EventsDatabase(db,models.generated.StabPostgresDriver.profile)
    [error]                                                         ^
    [error] one error found
    [error] (server/compile:compile) Compilation failed
    [error] Total time: 1 s, completed Dec 3, 2015 5:50:49 PM

    Trying to create a EventDatabase, in play, using a postgres driver (and interesting to note, I am using macwire in play 2.4)

    Trying to do something that looks kinda like this:
    trait DatabaseModule
      extends SlickComponents
      with EventsModule {
    
      def ec: ExecutionContext
    
      lazy val db: Database = api.dbConfig[StabPostgresDriver](DbName("default")).db
    
      override lazy val eventsDatabase = new EventsDatabase(db,models.generated.StabPostgresDriver.profile)
    
      lazy val idGenerator = new DefaultIdGenerator(datacenterId = 1)
    
      lazy val registry = Registry()
    
      lazy val users = wire[UsersDao]
    
    }
    Nick Childers
    @Voltir

    for the record, a dirty cast appears to work:

      override lazy val eventsDatabase = new EventsDatabase(db.asInstanceOf[slick.jdbc.JdbcBackend.DatabaseDef],models.generated.StabPostgresDriver.profile)

    With that, I do end up getting events stored in the DB

    Im assuming you are all asleep, considering you are in germany, and I am in California
    ill open an issue
    Adam Warski
    @adamw
    well Poland, not Germany, but close :)
    anyway, I replied in the issue (#2)
    Nick Childers
    @Voltir
    #2 works :)
    Nick Childers
    @Voltir
    Hrm, why does CommandResult.newAggregateId(...).map return a DBIOAction and not a CommandResult ?
    nm
    Adam Warski
    @adamw
    well CommandResult is just an alias for DBIOAction, so you probably use the alias when doing map :)
    there's a helper to flat map on success, called unimaginatively .flatMapSuccess :)
    Nick Childers
    @Voltir
    Yep, I get it now :)
    Aleksandrov Vladimir
    @invis87
    Hello guys! Maybe someone here knows how to return eventId in RequestResult )?
    this is how I return results now:
    someDB.operation(....).flatMap {
          case None         => CommandResult.failed(s"Sorry, something goes wrong")
          case Some(client) =>
            val event = Event(MySuperEvent(...)).forNewAggregate
            CommandResult.successful((), event)
        }
    But how to return Event.Id on CommandResult.successful({>>>HERE<<<}, event) ?
    event.aggregateId is Option :(
    Aleksandrov Vladimir
    @invis87
    Looks like I should use IdGenerator :(
    CommandResult.newAggregateId(Event(someData).forNewAggregate, idGenerator)
    Adam Warski
    @adamw
    @invis87 yes, you need to use the newAggregateId method. It needs an IdGenerator as the id needs to be generated somehow :) that's the same instance that you pass to the EventMachine or define as part of EventsModule.
    the id can be either generated at the time of command creation, or later, when the events are handled
    of course, you can create the id in another way as well, the newAggregateId method is quite simple:
    def newAggregateId[U, T, F](event: PartialEvent[U, T], idGenerator: IdGenerator): CommandResult[F, Long @@ U] = {
          val id = idGenerator.nextId().taggedWith[U]
          successful(id, event.copy(aggregateId = Some(id)))
        }
    Aleksandrov Vladimir
    @invis87
    @adamw thanks :)