Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'active_record'
- require 'tiny_tds'
- require 'activerecord-sqlserver-adapter'
- require 'pp'
- ActiveRecord::Base.establish_connection(
- :adapter=> "sqlserver",
- :host => "localhost",
- :username => "sa",
- :password => "Yukon900",
- # :database => "SampleDB2"
- )
- ##CREATE DATABASE HERE
- #Create a new table called Tasks
- ActiveRecord::Schema.define do
- create_table :tasks, force: true do |t|
- t.string :taskname
- t.string :user
- t.date :duedate
- end
- end
- class Task < ActiveRecord::Base
- end
- #Create new tasks and users
- Task.create(taskname:'Install SQL Server 2017 on Windows', user:'Andrea', duedate: '2017-07-01')
- Task.create(taskname:'Upgrade from SQL Server 2014 to 2017', user:'Meet', duedate: '2017-07-01')
- Task.create(taskname:'Write new SQL Server content', user:'Luis', duedate: '2017-07-01')
- puts "Created new tasks:"
- pp Task.all
- #Update due date for specific task
- task_to_update = Task.where(taskname: 'Install SQL Server 2017 on Windows').where(user: 'Andrea')
- puts "Updating the following task:"
- pp task_to_update
- task_to_update.update(duedate: '2017-07-31')
- puts "Due date changed:"
- pp task_to_update
- #Destroy all tasks for specific user
- tasks_to_delete = Task.where(user: 'Meet')
- puts "Deleting all tasks for user:"
- pp tasks_to_delete
- tasks_to_delete.destroy_all
- #Read all tasks
- puts "Printing all tasks:"
- pp Task.all
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement