mardi 11 février 2020

Database client abstractions

I have read many times that it is a good idea to write a layer of abstraction over any database clients, so that you can change the DB layer without affecting any other parts of the code.

In my project I use both BigQuery and Firebase quite heavily - but the client libs are so simple to use, I am not sure what I can add as a layer of abstraction, for example:

  await bigquery
    .dataset(datasetId)
    .table(tableId)
    .insert(rows);

I could wrap this in a function, which would include a little error handling.

The other option is that I make this new client more coupled to my domain, and expose methods which would save specific datasets rather than just take a rows object - this seems like it would be detrimental.

How does one abstract database in nodejs applications?

Aucun commentaire:

Enregistrer un commentaire