stackoverflowuser95
stackoverflowuser95

Reputation: 2070

Bad practice to have ORMs with NoSQL stores?

I use Redis (redis-py) inside my Python platform. Recently it was suggested that I switch to an ORM.

E.g.: python-stdnet, rom or redisco

Is use of ORMs considered bad practice in the NoSQL world?

Upvotes: 5

Views: 1757

Answers (2)

Josiah
Josiah

Reputation: 727

Ultimately the question boils down to at what layer do you want to write code.

Do you want to write code that manipulates data structures in a remote database, or do you want to write higher-level code that uses the abstractions built on top of those data structures? You can think of it as a similar question about relational databases as do you want to write SQL, or do you want to write higher-level code?

Personally, despite using rom myself for a variety of tasks (I am the author), I also directly manipulate Redis in the same projects where it makes sense.

Upvotes: 4

Carl Zulauf
Carl Zulauf

Reputation: 39568

Comments pointing out that the R in ORM is for relational are technically correct. That doesn't mean there aren't valid uses and reasons for libraries that abstract redis away.

There are some great libraries that make interfacing with a redis feel much nicer and more idiomatic to the language you are using. For ruby libraries like ohm or redis-native_hash (disclosure: I wrote that one) do just that. For python there are tools like redisco and surely others. These make persisting objects to redis very simple and make working with redis feel much more ruby-ish or python-ish.

Here are a few more benefits from using even the most basic abstraction, like a very thin wrapper you might write and keep in your application:

  • Switching redis clients will be easier. Maybe you'll never do this, but if you did, changing your calls to redis in one place (your wrapper) is much simpler than changing them everywhere you use redis.

  • Implementing things you might need for scaling, like sharding or connection pooling, is likely going to be easier if your calls are made through some abstraction.

  • Replacing redis with some other key/value store or data structure server would be simpler if an abstraction is in place.

I'm not advocating using an object mapping library or building your own abstraction, just pointing out there are valid reasons why you would. Its up to you to evaluate your needs and pick what works best for you. There is nothing wrong with calling redis directly either.

Upvotes: 2

Related Questions