Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement