[MUSIC] Hi and welcome to lecture two. In the previous lecture, we started generating our application, the fancy cars application, and we're using the scaffolding command to put stuff into the database. But which database is Rails using? And how do you view the contents of that database. So Rails, by default, uses SQLite as its database engine and SQLite is self contained, server less which basically means it has no server. Whereas, for example, MySQL oppose grass oracle. Pretty much any relational database engine out there is gonna have a server. SQLite doesn't have a server. It's just a file that sits on your file system. And SQLite lets you interact with that file as if it were a real database engine. And SQLite actually is. Claimed to be the most widely deployed SQL database engine in the world. All these devices, Android phones, Apple phones, different browsers use SQLite to store information. The way the database interactions setup in Rails is that you have a config directory, which is gonna be on the same level as your app directory in your Rails application, and that config directory has database dot y m l file in it, and automatically when you generate an application Rails says go ahead and specify that the development dot sqlite three file, which actually is located right here, is gonna be used for developing your Rails application. Again, the file that says where the database is is database dot yaml which is located in your config directory. But where the database is actually stored if you're using SQLite three. Your SQLite is going to be underneath the d b directory. Now we probably have to install some kind of a fancy tool that lets you visualize the database. But actually, no. We don't need to because you could just do a rails d b if you are inside the fancy cars application, which is the rails application we created in lecture one. And the rails d b pops you straight into SQLite console, which tells you all the different commands available if you do dot help, what it tells you all the different commands available to execute in the console to view a contents of your database. So for example. If we want to see the tables that currently exist in the database you can do dot tables. And that tells you that there's a car stable which we know was created. There's also this schema migrations table which we'll talk about in a few minutes. Now the good thing to do, at least what I find helpful, is to turn the headers on. So you do dot headers on, and what this lets you do is it enables the column headers. All these column headers, make, color, year, and so on, they get enabled by doing that headers on, without that you actually see the content but you don't see the column headers. Another option that I find useful to turn on is mode, so by basic default mode, whatever that is, but the mode I find useful is dot mode columns, which actually displays the columns in your database table as columns. Now at this point if you do a dot headers on and dot mode columns, you're able to do select, star from cars and that lets you see the structure of a table that we created back in lecture one. Two things to note here is this created at an updated at column. Which we didn't really create, so where did that come from? And we'll talk about that a little later, and basically the idea is created at is a column that gets created and populated when the record is created, and updated at Is a column that gets modified, so when you update a row in the database, the updated at column gets modified with timestamp on when that column was modified. And there's also this ID column which we didn't create. We only created make, color and year. Columns, but as we're gonna see, rails, or specifically the active record, which is used to interact to the database, assumes that we obviously wanna have a primary key to our table because that is a good practice to always have a primary key. Pretty much all the time, the primary key on your database tables, so it creates a primary key called ID and it auto increments it one, two, three and so on. To exit the SQLite console you would dot exit, and that takes you out of the console. Now of course you don't have to use the rails space d b command to view your SQLite console or your SQLite database there are other tools out there. For example, this tool right here called SQLite browser, which you could use to view your database. But the point is you don't really need to install any other tools. Once you have your Rails application, you automatically have access to your SQLite schema and data in the SQLite database. By doing Rails space d b. So in summary, Rails uses SQLite by default. And there's a built in command line d b viewer to view the contents and schema of your database. What's next? Next we'll talk about Migrations, what those are and we're gonna start getting closer and closer to the actual database. But as we're gonna see, we don't have to get too close hopefully. It's gonna be mostly abstract concepts. But it's gonna give you a good understanding of how the interaction of the database happens in Rails.