Created
July 17, 2012 00:19
-
-
Save dladowitz/3126066 to your computer and use it in GitHub Desktop.
Active Record Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
require 'sqlite3' | |
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', | |
:database => 'db/students.db' | |
ActiveRecord::Base.connection.execute <<SQL | |
CREATE TABLE IF NOT EXISTS students ( | |
id INTEGER PRIMARY KEY AUTOINCREMENT, | |
first_name VARCHAR NOT NULL, | |
last_name VARCHAR NOT NULL, | |
birthday DATE, | |
gender VARCHAR(8), | |
email VARCHAR, | |
phone VARCHAR, | |
created_at DATETIME NOT NULL, | |
updated_at DATETIME NOT NULL | |
); | |
SQL | |
class Student < ActiveRecord::Base | |
end | |
Student.create(:first_name => 'Adam', :last_name => 'Flint', :birthday => '1977-07-28') | |
Student.create(:first_name => 'Brad', :last_name => 'Johnson', :birthday => '1977-01-07') | |
Student.create(:first_name => 'Adam', :last_name => 'Johnson', :birthday => '1977-11-28') | |
puts Student.select("first_name, last_name, created_at").inspect | |
puts Student.where("first_name Like 'A%' ").inspect | |
puts Student.where("strftime('%m',birthday) = '07'").inspect | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment