mercredi 23 janvier 2019

What pattern or architecture can be applied to Repositories and several data clients (Mysql, Postgress, Elasticsearch, etc)?

my question is because I currently have several repositories working with a data system, specifically a DbalClient, which works with Postgress and Mysql, the question is that I want to implement something else like MongoDB or Elasticsearch and I would have to adapt my repositories, How can I abstract this?

Some example code

UserRepository {

   protected $client;

   public function __construct(DbalClient $client)
   {
      $this->client = $client;
   }        

   public function find($id)
   {
      $query = $this->client->createQueryBuilder();
      $result = $query->select('*')->where('user.id = :id')
         ->setParameter('id', $id);
         ->getResult($query);
      return $result;
   }

}

This is only serving me for DbalClient, What pattern could I use apart from interfaces?

Aucun commentaire:

Enregistrer un commentaire