Class: Threatinator::Amqp::Rcvr::Backends::SQLite
- Inherits:
-
Object
- Object
- Threatinator::Amqp::Rcvr::Backends::SQLite
- Defined in:
- lib/threatinator/amqp/rcvr/backends/sqlite.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize ⇒ SQLite
constructor
A new instance of SQLite.
- #insert(import_time, host, feed_provider, feed_name) ⇒ Object
- #prep ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ SQLite
Returns a new instance of SQLite.
8 9 10 11 12 |
# File 'lib/threatinator/amqp/rcvr/backends/sqlite.rb', line 8 def initialize() @connection=_connect(Threatinator::Amqp::Rcvr::Settings.sql_file_location) @connection.results_as_hash = true @connection end |
Instance Method Details
#close ⇒ Object
32 33 34 35 |
# File 'lib/threatinator/amqp/rcvr/backends/sqlite.rb', line 32 def close @stmt.close @connection.close end |
#insert(import_time, host, feed_provider, feed_name) ⇒ Object
28 29 30 |
# File 'lib/threatinator/amqp/rcvr/backends/sqlite.rb', line 28 def insert(import_time, host, feed_provider, feed_name) @stmt.execute(:import_time => import_time, :name => host, :feed_provider => feed_provider, :feed_name => feed_name) end |
#prep ⇒ Object
14 15 16 17 18 19 |
# File 'lib/threatinator/amqp/rcvr/backends/sqlite.rb', line 14 def prep @stmt = @connection.prepare(<<-EOS) INSERT INTO #{Threatinator::Amqp::Rcvr::Settings.sql_table_name}(import_time, name, feed_provider, feed_name) VALUES(:import_time, :name, :feed_provider, :feed_name) EOS @connection end |
#validate! ⇒ Object
21 22 23 24 25 26 |
# File 'lib/threatinator/amqp/rcvr/backends/sqlite.rb', line 21 def validate! @connection.execute("PRAGMA table_info(#{Threatinator::Amqp::Rcvr::Settings.sql_table_name});") do |row| raise UnknownDBSchemaError, "Unknown Schema" unless ["id","feed_provider","feed_name", "import_time","name"].include? row["name"] end puts "#[threatinator-ampq-rcvr] schema validated" if Threatinator::Amqp::Rcvr::Settings.verbose end |