[erlang-questions] How to code against an interface rather than an implementation?
Fri Aug 9 10:28:08 CEST 2013
Perhaps you are looking for an ORM. Something like
https://github.com/evanmiller/boss_db could probably some your need?
On Aug 9, 2013 1:51 PM, "H.C. v. Stockhausen" <hc@REDACTED> wrote:
> I need a DB backend for my application but I'd like to be able to swap
> it out for different DBs if I choose so later on.
> I would like to code against an interface and tell the application
> what specific backend to use through config rather than code changes.
> Is there a pattern for doing that? Hot code upgrades and multi-node
> are not a real concern at this time - mostly, since I have no
> experience yet with either - however if doing it right means taking
> that into account too I'd also like to learn more about that.
> I am thinking of defining a custom behaviour ("my_crud" perhaps), then
> to implement it for various DBs and to also let a config driven
> adapter implement it that I then use to throughout the code to talk to
> the DB layer.
> For example, using Mnesia and AWS DynamoDB:
> - my_crud.erl (behaviour)
> - my_db_mnesia.erl (implements behaviour)
> - my_db_dynamo.erl (implements behaviour)
> - my_db.erl (configurable adapter that also implements behaviour)
> - my.config
> my_db:insert(Key, Value).
> Is that a reasonable approach that makes proper use of Erlang and
> behaviours or is this just not how one should do it?
> Thank you for any help & best regards,
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions