[erlang-questions] How to code against an interface rather than an implementation?

Harsh J qwertymaniac@REDACTED
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:

> Hello,
> 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,
> Hans
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130809/e358532d/attachment.htm>

More information about the erlang-questions mailing list