GithubHelp home page GithubHelp logo

active-record-vali-488's Introduction

ActiveRecord Boilerplate

This is a starting point for the Activerecord Basics lecture using sqlite. During the lecture, you need to:

  • Clone The project
  • Run bundle install
  • Explain rake -T
  • Explain config/database.yml
  • Run rake db:create / rake db:drop
  • Create and run 2 migrations

REVIEW

  • Relational Database: tables representing data and tables can be related to one another through foreign keys (ids)

  • Relationships: 1:N, N:N, 1:1

  • SQL CRUD (characters as our table)

  • SQL is the language for relational databases

READ ALL for SQL

  • SELECT * FROM characters;

READ ONE for SQL

  • SELECT * FROM characters WHERE id = 1;

CREATE

  • INSERT INTO

UPDATE

  • UPDATE SET

DELETE

  • DELETE FROM

FILTERS

  • ORDER BY << sorts results in order (ASC / DESC)
  • COUNT << returns # of items that meet the criteria
  • GROUP BY << groups results by specified column / criteria

JOIN

JOIN table_name ON column_one.id = column_two.column_one_id

ACTIVE RECORD

  • Active Record: design pattern, allows you to interact with DB through Ruby methods which are inherited, ActiveRecord is a gem. Links one record in our database to one instance of our Class.

RAKE TASKS

  • CREATE: rake db:create

  • DROP: rake db:drop

  • MIGRATE: rake db:migrate

  • Migrations: change the structure of the database / schema (add a table, new column, drop a table)

ACTIVE RECORD CRUD (characters)

READ ALL

  • Character.all

READ ONE

  • Character.find(1)
  • Character.find_by(name: 'Harry Potter') # returns first one

FILTERED MANY

  • Character.where(address: 'Hogwarts') # returns all as an ARRAY

CREATE

  • Character.create(name: 'Harry Potter')
  • character = Character.new(name: 'Harry Potter')
  • character.save

UPDATE

  • character = Character.find(1)
  • character.name = 'Voldemort'
  • character.save

DELETE

  • character = Character.find(1)
  • character.destroy

ADVANCED

  • Character.last
  • Character.first
  • Character.first(5)
  • Character.count

active-record-vali-488's People

Contributors

barangerbenjamin avatar caioertai avatar cveneziani avatar db0sch avatar kevcha avatar krokrob avatar nfilzi avatar papillard avatar sheesh19 avatar ssaunier avatar

Watchers

 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.