Code Monkey home page Code Monkey logo

activerecord-intro-exercise's Introduction

Tunr 1.0!

Local Setup

Create your schema.sql:

DROP TABLE IF EXISTS songs;
DROP TABLE IF EXISTS artists;

CREATE TABLE artists(
  id SERIAL PRIMARY KEY,
  name TEXT,
  photo_url TEXT,
  nationality TEXT
);

CREATE TABLE songs(
  id SERIAL PRIMARY KEY,
  title TEXT,
  album TEXT,
  preview_url TEXT,
  artist_id INT
);

create your Gemfile

source "https://rubygems.org"
gem "pg"  # this gem allows ruby to talk to postgres
gem "activerecord"  # this gem provides a connection between your ruby classes to relational database tables
gem "byebug"  # this gem allows access to REPL
bundle install
createdb tunr_db
psql -d tunr_db < schema.sql
psql -d tunr_db < seeds.sql

Create your artist class:

class Artist < ActiveRecord::Base
  # AR classes are singular and capitalized by convention
end

Part 1.1 - Use your Artist Model

In the console:

  1. Find all artists
  2. Find just one artist by id
  3. Find Taylor Swift (or your other fav artist) by name.
  4. Find all artists from the USA
  5. Find all artists NOT from the USA
  6. Create a new artist for your favorite artist
  7. Change at least 2 of their attributes
  8. Destroy the artist you just created
  • (NOTE: If you destroy other artists at this point, you'll need to reseed your data for consistency.)

further

Add another column to your artists table called year with type integer by editing your db/schema.sql file. Then run reset your schema via the command line. Populate each artist with the appropriate year of origin.

further

Use Active Record queries to find all artists:

  • since 2000
  • between 1970 and 1995
  • not in 2004 or 2015

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.