class FTLTools::Adapters::Sqlite
Public Instance Methods
items_from_options( num = 1, unique = true )
click to toggle source
# File lib/ftl_tools/data_mine/sqlite_adapter.rb, line 13 def items_from_options( num = 1, unique = true ) # Needs a way to allow non unique. # With the "ORDER BY RANDOM() LIMIT #{num}" statement, # if num > count, returns all data, but no duplicates. data = Array.new data_store = @source[:data_store] table = @source[:table] db = SQLite3::Database.open data_store count_query = db.prepare "SELECT COUNT(*) from #{table}" count_query.close if count_query query = db.prepare "SELECT * FROM #{table} ORDER BY RANDOM() LIMIT #{num}" result = query.execute result.each { |r| data << r[0] } query.close if query db.close data end
start( source = {} )
click to toggle source
# File lib/ftl_tools/data_mine/sqlite_adapter.rb, line 9 def start( source = {} ) @source = source end