RubyMine has more tools that let us manage all aspects of our programming projects. This recipe will concentrate on configuring and using the built-in database tools in RubyMine.
Open your Progeny
Rails project that we created earlier in RubyMine.
When the project opens, there will likely be a window that comes open like the following:
Click on the link and RubyMine will download and install some Java database drivers so that it can access your Sqlite database (or whichever you are using) from your existing Rails project.
Directly accessing your database fields and structure is much more efficient when we have a nice tool to list and modify our records. RubyMine has the ability to show the tables from your environment directly in the interface, so there is no need to open another tool. Perform the following steps for monitoring your extremities:
Click on the Database button on the left side of the RubyMine main frame. This will open a panel that looks like the following:
Click on the panel and then use the command code as described in the window. (This will be different for each operating system).
Select the menu item Import from sources … and then hit OK from the next window.
Click on the table that shows and open up each level.
Double-click on the
id
element of theSpecies
table and we will see a window like the following:This allows us to view, add, modify, and delete records from our tables easily.
Click on the + icon, we will then be able to manually add another record to our database.
If we double-click on one of the cells, we can modify the values that are stored in the database. This is a quick way to edit some mistakes that we made when entering data or to test out a part of our interface. Let's add another record via the table editor.
Click on the + icon and enter the following information into the cells of the new blank row that is created:
Now we have two species in our database. We can edit these items as we please, but please note that updates do not automatically change the
updated_at
field. This is done through the Rails system as it saves a record and we are bypassing that framework completely using this system. We are talking directly to the database.RubyMine also gives us a nice interface to perform direct database queries on our data tables directly.
Open the database console by hitting the icon Database Console at the top of the Database panel. This opens a window in the main editor panel that lets us type SQL queries directly and execute them to get a dataset back, as you can see in the following screenshot:
Type the following in the console window:
select * from species where assimilated = 'f'
Select the green arrow button right above the text in the editor panel. Don't select the green arrow which runs a specific configuration.
The results of this direct query will now show at the bottom in a new panel with a database table editor like we had before. It will look something like the following screenshot:
We selected all of the species in our table that have not yet been assimilated. We can now remedy that easily.
Double click on the f letter in the assimilated column.
Change that to
t
.
See how easy it is to assimilate other species?
Notice that when you changed the field, it disappeared. This is because our query was executed again and found no more species left to assimilate in our database table. Our job is done. We can return to the collective.