« first day (4264 days earlier)      last day (698 days later) » 

5:19 AM
@Wes I'm not sure that's a useful abstraction. If you have something like a ProductRepo, making two versions of MysqlProductRepo and SQLiteProductRepo will take less time than trying to extract bits of it to a common class as either:
i) you can copy and paste code between the two implementations, just changing the mysql/sqlite appropriate method names.
ii) the implementations need to be quite different, and so each of them need quite different code.
For neither of those cases, would abstracting stuff save that much time.
 
Wes
my mappers are not 1:1 to transactions, they contain functions that can be used in transactions for example find product by id is used by 20 different transactions, but i only have 1 method for it, roughly like $mapper->getProductByIDForUpdate(32)
 
"they contain functions" - can those functions be removed from the classes to be just functions?
actually, even if they can't.....individual implementations ftw.
mostly.
 
Wes
so i do transactions on a higher layer than that, something like
public function addProductToCart($productID){
    $this->mapper->dbal->transaction(function(){
        $this->mapper->findByID(...)
    });
}
i think i should have
    $this->mapper->addProductToCart()
and have it include the transaction as well
but based on my experience if i do it that way the mapper will contain a lot of model logic that should not be there
i am probably not being clear. what'd you do tho?
i recall liking this design also for another reason. i can include other stuff in the transaction logic, not just db related operations. for example if renaming a file fails, i can make the transaction fail. if that makes sense
 
 
3 hours later…
8:26 AM
morns
 
Wes
8:51 AM
\o
 
 
9 hours later…
5:26 PM
I think I prefer using RAII rather than callbacks for things like transactions: $transaction = $dbal->startTransaction(); then automatically roll back the transaction if it is destructed without a $transaction->commit();
then the code inside the transaction can be broken down arbitrarily - you can have functions that expect to be passed an open transaction, for instance
and for the simple case, you don't need the extra level of nesting and variable scope like a callback, just two extra lines of inline code
 

« first day (4264 days earlier)      last day (698 days later) »