Skip to content

Data Gateway Pattern

bignomanatee edited this page Dec 29, 2010 · 2 revisions

I think it is quite possible to write an effective data adaption mechanism that doesn't tie you to a specific Database, or for that matter, bind you to SQL or NoSQL.

No matter what code language you are using, they all eventually require data that is a heirarchical organization of information. JSON / Javascript Objects is the classic model, as is to some extent XML.

So if you have a simple CRUD contract, i.e.,

  • get(type, id): hash
  • put (type, id, data): boolean
  • find (type, query): hash[]
  • delete(type, id | query): int

You should be able to create an adaptive layer between any repository type that you can think of, sql or noSql, and if you want to optimize for a specific query and a specific database type, write an event system that intercepts and overrides the general case call to the repository and returns you data faster.

For instance, why should I be forced to use a single repository and repository type for all my data I/O? Why can't I use mongoDB for comments, REST for articles, and PostGres for users?

Clone this wiki locally