DEV Community

Osazuwa J. Agbonze
Osazuwa J. Agbonze

Posted on

Journey to SQLAlchemy for Beginners - The Genesis

Lady on a narrow path discovering things around

Image credit to Michelle Spencer

Hi, there're lots of data to be managed and interacted with concurrently. Have you given thoughts about how the data you see on the web are managed from an application stand point ? SQL comes to mind for sure, even more, a specialist skill level would be needed for this kind. To buttress a little, think about how when you log in to Linkedin, twitter or Meta, you immediately not only see recent posts, your notification chimes, profile image displays, ads & all those extra spices just keeps popping out, Ohh !!! the recommendation system, friends, pages you name it. I can't imagine someone compiling all those data writing pure SQL (data could also be from different data sources) in an application.

Well, to be honest, we can't hide data too far from SQL. Luckily, we do have a much more approachable way to manage all these data and getting started is even easier.

SQLAlchemy is an object relational mapper that simplifies and allows us a robust access to interacting with databases without having to know about SQL core. By no way the best definition, but just follow on.

Either or not you know how to program, the statement object relational mapper would definitely be a familiar grammar. If not, well, that's why this is The Genesis. Lets take the Three words, Object, Relational, Mapper and see how it all fits together.

Object is anything (digital / physical or ...) that can be interacted with e.g Student, BlogPost, Product, Meal e.t.c. My ideology is, If you can model it, it's an object ( wrong ? plz, freely correct me ).

Relational are ways one or more objects/models are connected.

Having known what Object and Relational is, to explain Mapper, unfortunately, it wouldn't hold much context in itself, therefore, we'll need the previous two to explain Mapper.

Object Relational Mapper is a map between connected Objects. Simple right ? Cool - but how's this related with SQL, you would ask ?

It's going to be a ride explaining this as simple as I can, but hold my beer and pass it on afterwards.

SQL (Structured Query Language) is to Database what English (or French/Spanish e.t.c) is to Humans. Outside the context of Databases, SQL doesn't exist. Database simply keep records of an object in a Table ( think of excel - rows and columns of similar records ). The function of SQL is to interact with Database to retrieve, modify, delete and add some/all record.

The only citizen of SQL is Database and here comes the controversy, how do we make Object from outside the context of a Database (e.g our application) understood by SQL ? You guessed right, we Map them. Mapper does what a translator do to two foreigners.

So earlier when I said, Object Relational Mapper is a map between connected Objects, the objects referred are :

1) Application Object
2) Database Table holding similar object

The beautiful thing is that, either object doesn't know they're connected. What they do know is how to convey their messages and understand the sent message with the help of the middle man SQLAlchemy Object Relational Mapper.

Even when your experience with SQL is top notch, wouldn't you still go with a process that makes life easier ? Yes, I bet you would.

I'm driven by curiosity to go on a Journey to SQLAlchemy, I heard it's a mine full of discoveries, FOLLOW ME NOW ( like right NOW !!! ), cause I'll be sharing my finding with you (share with me too, if you find some discoveries yourself in this journey).

Some Articles I Found Useful

Just as mentioned, I'm on a journey, I found so many discoveries super interesting. Amongst the many @billtrn 's post is an interesting read and also gave a good introduction to SQLAlchemy ( NOTE: much more technical than this post )

Do you have links to basic introduction to SQLAlchemy for beginners ? drop in the comment section, I promise to read your discoveries too.

Please, My Beer

You can pass me my beer now, Please. Sighhh !!! Did you finish it ? but I said, hold. Well, I don't mind a cup coffee for a replacement -> https://www.buymeacoffee.com/spaceofmiah

Top comments (0)