Class: Daru::IO::Importers::SQL
- Defined in:
- lib/daru/io/importers/sql.rb
Overview
SQL Importer Class, that extends from_sql
and read_sql
methods to Daru::DataFrame
Class Method Summary collapse
-
.from(dbh) ⇒ Daru::IO::Importers::SQL
Loads from a DBI connection.
-
.read(path) ⇒ Daru::IO::Importers::SQL
Reads from a sqlite.db file.
Instance Method Summary collapse
-
#call(query) ⇒ Daru::DataFrame
Imports a
Daru::DataFrame
from SQL Importer instance. -
#from(dbh) ⇒ Daru::IO::Importers::SQL
Loads from a DBI connection.
-
#initialize ⇒ SQL
constructor
Checks for required gem dependencies of SQL Importer.
-
#read(path) ⇒ Daru::IO::Importers::SQL
Reads from a sqlite.db file.
Methods inherited from Base
Constructor Details
#initialize ⇒ SQL
Checks for required gem dependencies of SQL Importer
12 13 14 15 16 17 |
# File 'lib/daru/io/importers/sql.rb', line 12 def initialize optional_gem 'dbd-sqlite3', requires: 'dbd/SQLite3' optional_gem 'activerecord', '~> 4.0', requires: 'active_record' optional_gem 'dbi' optional_gem 'sqlite3' end |
Class Method Details
.from(dbh) ⇒ Daru::IO::Importers::SQL
Loads from a DBI connection
29 30 31 32 |
# File 'lib/daru/io/importers/sql.rb', line 29 def from(dbh) @dbh = dbh self end |
.read(path) ⇒ Daru::IO::Importers::SQL
Reads from a sqlite.db file
44 45 46 47 |
# File 'lib/daru/io/importers/sql.rb', line 44 def read(path) @dbh = attempt_sqlite3_connection(path) if Pathname(path).exist? self end |
Instance Method Details
#call(query) ⇒ Daru::DataFrame
Imports a Daru::DataFrame
from SQL Importer instance
62 63 64 65 66 67 |
# File 'lib/daru/io/importers/sql.rb', line 62 def call(query) @query = query @conn, @adapter = choose_adapter(@dbh, @query) df_hash = result_hash Daru::DataFrame.new(df_hash).tap(&:update) end |
#from(dbh) ⇒ Daru::IO::Importers::SQL
Loads from a DBI connection
29 30 31 32 |
# File 'lib/daru/io/importers/sql.rb', line 29 def from(dbh) @dbh = dbh self end |
#read(path) ⇒ Daru::IO::Importers::SQL
Reads from a sqlite.db file
44 45 46 47 |
# File 'lib/daru/io/importers/sql.rb', line 44 def read(path) @dbh = attempt_sqlite3_connection(path) if Pathname(path).exist? self end |