Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'mysql2'
- require 'sequel'
- require 'cgi'
- # Connect to the database
- DB = Sequel.connect(:adapter => 'mysql2', :host => 'localhost', :database => 'todo-ruby',
- :user => 'root', :password => nil)
- class TodoLib
- def self.list
- DB["SELECT * FROM todo"].all
- end
- def self.add(name)
- name = CGI::escape_html(name)
- DB[:todo].insert(:name => name, :created_at => Time.now.to_i)
- return name
- end
- def self.edit(id, new_name)
- end
- def self.delete(id)
- todo = DB[:todo].select(:id, :name).filter(:id => id).limit(1).first
- todo.delete
- return todo[:name]
- end
- end
Add Comment
Please, Sign In to add comment