Module: RDBr::Query

Defined in:
lib/rdbr/query.rb,
lib/rdbr/query/page.rb,
lib/rdbr/query/mysql.rb,
lib/rdbr/query/errors.rb,
lib/rdbr/query/lookup.rb,
lib/rdbr/query/sqlite.rb,
lib/rdbr/query/connection.rb,
lib/rdbr/query/postgresql.rb,
lib/rdbr/query/relational.rb,
lib/rdbr/query/type_support.rb,
lib/rdbr/query/value_limiter.rb,
lib/rdbr/query/postgresql_dialect.rb

Defined Under Namespace

Modules: Lookup, PostgresqlDialect, TypeSupport Classes: AccessDeniedError, AccessViolationError, ConfigurationError, Connection, ConnectionUnavailableError, Error, ExecutionError, InvalidQueryError, Mysql, Page, Postgresql, RelationNotFoundError, Relational, Sqlite, TimeoutError, UnsupportedAdapterError, ValueLimiter

Class Method Summary collapse

Class Method Details

.build(database_url:, catalog:, max_results: 100, connection_options: {}, access_policy: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rdbr/query.rb', line 17

def build(database_url:, catalog:, max_results: 100, connection_options: {}, access_policy: nil)
  adapter = catalog.adapter&.to_sym
  query_class = { postgresql: Postgresql, sqlite: Sqlite, mysql: Mysql, mariadb: Mysql }[adapter]
  raise UnsupportedAdapterError, "Data queries are not supported for #{catalog.adapter}" unless query_class

  connection = Connection.new(
    database_url,
    options: connection_options,
    access_policy: access_policy
  )
  query_class.new(connection: connection, catalog: catalog, max_results: max_results)
rescue ArgumentError, TypeError => e
  raise ConfigurationError, e.message
end