Giter Club home page Giter Club logo

100-days-of-code's Introduction

100 Days of Code Log

Day 1: May 1st, 2019

Today's Progress

Finished the Pokemon Scraper Lab Bonus tests

  • Named and optional arguments and metaprogramming facilitate saving objects to a persistent data store
  • SQLite gem DB queries return an array of rows, of which the rows are arrays of columns

Completed the 2 ORM mapping labs.

  • We setup DB[:conn] constant hash in environment.rb and use it to talk to the database.
  • The example ORM initializes the object's id to nil so we can write it after the db has generated it with its autoincrement feature. We set the instance varible directly inside a save method, since it's an attr_reader.
  • Tables represent Classes and rows instance objects

ORM mapping to table lab
ORM mapping db to Ruby object lab

Day 2: May 2nd, 2019

Completed the Updating Records in an ORM lab.

  • Implemented the find or create pattern with the db
  • instantiate object, save to db, set db-generated key field in object
  • save all attributes to db when updating

Completed Bringing it all Together lab.

  • prevent duplication via find or create methods
  • reinforced the pattern of mapping an object to a db row, then writing the unique identifier generated by the db
  • that unique identifier should be an attr_reader vs accessor, because we don't want it changed once the db writes it
  • we set it using instance variable in a .save method

Day 3: May 3rd, 2019

Completed Dynamic ORMs lab

  • The pattern of first creating the database table and having your program do all the work of writing your ORM methods based on that table is exactly how we'll develop web apps in Sinatra and Rails
  • It seems like a best practices to put the IF (NOT) EXISTS constraints on creating and dropping db tables.
  • introduces the #results_as_hash method of the SQLite3 gem that returns database rows as a hash using the column names as keys, instead of an array of array rows
  • PRAGMA table_info("#{table_name}") sql keyword to get the column names of a table.
  • the table_name class method doesn't require self when in the Class context(ie another class method)
  • Array#compact removes nil values
  • Using self.class to refer to class methods inside instance methods
  • ORM insert methods ignore nil columns, since the id hasn't been generated yet
  • ORM update methods ignore the id column. since it's an attr_accessor due to metaprogramming, we account for it here so we don't overwrite the original value.

Day 4: May 4th, 2019

Completed Dynamic ORMs with Inheritance

  • Why is it useful to have a generic ORM class that others can inherit from?
  • We don't have to code useful methods like find_by_name or save, we can just inherit from a generic super class.
  • Describe the code used to construct such a class
  • Uses class methods and the self keyword to extract the sub class names.
  • The .find_by_name method in the lab has a typo
  • sql = "SELECT * FROM #{self.table_name} WHERE name = '?'"
  • The '?' gets treated as a string literal instead of a bind parameter
  • several mentions of bind_param in the traceback, which is a clue.

Day 5: May 5th, 2019

Watched an ORM scraping video, and got the most useful explanation of the #tap method

  • self.new.tap {|room| room.id = id} #tap returns the object to the left of it, but it gives you access to it as a block scoped variable. It eliminates the need for a dangling return. Finished ORM section, started on ActiveRecord
  • the #send method allows us to access instance variables programmatically.

100-days-of-code's People

Contributors

big32mike 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.