lib/chatterbot/db.rb in chatterbot-0.5.0 vs lib/chatterbot/db.rb in chatterbot-0.5.1

- old
+ new

@@ -1,34 +1,34 @@ module Chatterbot - + # # routines for optionally interacting with a database for logging # tweets, and storing config data there. Uses Sequel to handle the # heavy lifing. - module DB + module DB # # connect to the database, and generate any missing tables def db @_db ||= connect_and_validate end def display_db_config_notice puts "ERROR: You have specified a DB connection, but you need to install the sequel gem to use it" end - - protected + protected + # # get a DB object from Sequel def get_connection if ! has_sequel? && config.has_key?(:db_uri) display_db_config_notice elsif has_sequel? Sequel.connect(config[:db_uri]) end end - + # # try and connect to the DB, and create tables that are missing. def connect_and_validate conn = get_connection return if conn.nil? @@ -37,20 +37,20 @@ conn.create_table :blacklist do String :user, :primary_key => true DateTime :created_at end end - + if ! conn.tables.include?(:tweets) conn.create_table :tweets do primary_key :id String :txt String :bot String :user String :source_id String :source_tweet - + DateTime :created_at end end if ! conn.tables.include?(:config) @@ -61,15 +61,15 @@ String :secret String :token String :consumer_secret String :consumer_key - + DateTime :created_at DateTime :updated_at end end - + conn end end end