Giter VIP home page Giter VIP logo

04_intro_to_databases_and_activerecord's Introduction

Intro to Databases & ActiveRecord

Learning Goals:

  • [] Explain persistence, the need for using SQL, and difference between SQLite3 and SQL
  • [] Perform CRUD actions on a single table
  • [] Explore how to interact with a sqlite3 database with a ruby file
  • [] Perform CRUD actions using ActiveRecord

Important Resources for Today

Topics

What are the benefits of having a database for our application?

...

What is SQL and what do we use it for?

...

Why have a separate language for interacting with the database? Why not use Ruby or JavaScript?

...

What's the difference between SQLite and SQL?

...

What is an RDBMS?

...

Demonstration

  • Create Dogs model and table
  • open up ./bin/console and do create a couple of dogs.

Task 1

  1. Create a computers table with the following columns:
  • brand (string)
  • model (string)
  • screen_size (float)
  • model_year (integer)
  • asleep (boolean)
  • last_backed_up_at (datetime)
  1. In lib/computer.rb, create a Computer class that inherits from ActiveRecord::Base

  2. In lib/exercises.rb fill in the first_computer and second_computer methods so that they both return computers with brand, model, screen_size and model_year properties assigned.

How did you create the computers table?

...

Why do we write database changes to a file instead of using SQL to update the structure of the database?

...

How is the Computer class connected to the computers table?

...

Why do migration file names start with a number?

...

What else is important about migration file names?

...

What is an ORM and why do we need/want one?

...

What is rake and what is it used for?

Demonstration - Updating and Deleting Dogs

For this, let's open up ./bin/console and attempt the following:

Find an existing dog

Update the dog's age

Delete the dog

Try to find the dog again to demonstrate it has been deleted

Task 2

  1. Define a back_up method within the computer class that updates the last_backed_up_at attribute of the computer to the current date and time.

  2. Define a sleep method within the computer class that updates the asleep attribute of the computer to true.

  3. Define a wake_up method within the computer class that updates the asleep attribute of the computer to false.

  4. Define a backed_up method within the computer class that returns all of the computers that have been backed_up.

What is the main purpose of ActiveRecord in our application?

...

What would we have to do in our application if we didn't have something like ActiveRecord?

...

What are some potential downsides of using ActiveRecord?

...

04_intro_to_databases_and_activerecord's People

Contributors

dakotalmartinez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.