Created
June 3, 2017 06:13
-
-
Save sushant12/706a9f1d681d14bb674e7655dc008c93 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Task | |
DB = PG.connect :hostaddr => "127.0.0.1", :port => 5432, :dbname => 'testdb', :user => "postgres", :password => "postgres" | |
#uncomment while deploying to heroku | |
#DB = PG.connect ENV["HEROKU_POSTGRESQL_SILVER_URL"] | |
# uncomment to create pg database | |
# DB = PG.connect(hostaddr: "127.0.0.1", port: 5432, dbname: 'postgres', user: 'postgres', password: "postgres") | |
# DB.exec("CREATE DATABASE testdb") | |
# uncomment to create table | |
# DB.exec "DROP TABLE IF EXISTS tasks" | |
# DB.exec "CREATE TABLE tasks(Id SERIAL PRIMARY KEY, Name VARCHAR(20), Finished INT)" | |
class << self | |
def all() | |
DB.exec("select * from tasks") | |
end | |
def update(task, finish, id) | |
DB.exec("UPDATE tasks set name = '#{task}', finished = '#{finish}' where id='#{id}'") | |
end | |
def save(task_name) | |
DB.exec("INSERT INTO tasks (name, finished) VALUES ('#{task_name}',0)") | |
end | |
def delete(id) | |
DB.exec("delete from tasks where id='#{id}'") | |
end | |
def where(id) | |
DB.exec("select * from tasks where id = '#{id}'") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment