DEV Community

Cover image for First time with a Data Base
acm-sp85
acm-sp85

Posted on

First time with a Data Base

After building a couple of front end projects emulating a database via db-json the time had come to go a step further and jump into the real world of databases. Let me tell you all abut it in this short and screenshot intense blogpost.

How was it like to be working with a db-json

Alt Text

During the previous project at Flatiron School - Phase 2, I built a web app that was able to keep a log of my photographic equipment. I needed to store that information somewhere, but I had no idea about data bases, Ruby, ActiveRecord or any of that fun stuff. So what we were encouraged to do was to build a db-json with all our information and fake a DB that way.

At its core, a db-json is an object with data in it, and the greatest perk of this is that you can get to see what is going on in your code editor.

Alt Text

Adding items to your DB, deleting or updating them is as easy as opening the file on your editor and type it yourself. That is a very big perk!

Adding a layer of complexity with relational databases

During Phase3 of our course we started learning the powerful but old-timey language of Ruby with the intention of creating a strong foundation of the technology before getting into the most popular Ruby on Rails.

With Ruby we learnt about Object Oriented Programming and got introduced to Active Record and RACK, two powerful tools that allow you to program your server and communicate that way with the database.

At this point, the databases we were building looked nothing like the db-json ones, and special software was needed to visualize the data.

Alt Text

Instead you have to use software like DB Browser for SQLite

Alt Text

This made adding/modifying/deleting data a rather cumbersome process, but came with added powers that working with a non-relational DB didn't: the ability to have a DB formed with many different tables that talk to each other via foreign keys and that facilitate data retrieval via Querying.

As an example, here you can see the schema of my database, formed by 3 tables: Brands, Formats and Rolls.

Alt Text

And here you can see the relations in between tables, in which you can notice that every Roll belongs_to a Brand and a Format, every Brand has many Rolls and Formats, and every Format has many Rolls and Brands.

Alt Text

With a structure like this, every time you create a new Roll object you are creating an association in between the three tables and unlocking the true potential of relational databases.

Top comments (0)