Module: Sequel::MakeReadyable

Defined in:
lib/sequel/extensions/make_readyable.rb

Overview

MakeReadyable

Sequel extension that provides database readiness functionality, primarily geared towards Spark SQL-based databases. This extension allows setting up temporary views and schema configurations to prepare a database for use.

Examples:

Basic schema usage

db.extension :make_readyable
db.make_ready(use_schema: :my_schema)

Search path with schema precedence

db.make_ready(search_path: [:schema1, :schema2])

External file sources

db.make_ready(search_path: [Pathname.new('data.parquet')])

Instance Method Summary collapse

Instance Method Details

#make_ready(opts = {}) ⇒ Object

Prepares the database by setting up schemas, views, and external data sources.

This method is primarily geared towards Spark SQL-based databases. Given some options, prepares a set of views to represent a set of tables across a collection of different schemas and external, unmanaged tables.

Examples:

Set primary schema

DB.make_ready(use_schema: :schema)
# => USE `schema`

Search path with precedence

# Assuming tables: schema1.a, schema2.a, schema2.b
DB.make_ready(search_path: [:schema1, :schema2])
# => CREATE TEMPORARY VIEW `a` AS SELECT * FROM `schema1`.`a;`
# => CREATE TEMPORARY VIEW `b` AS SELECT * FROM `schema2`.`b;`

External file sources

DB.make_ready(search_path: [Pathname.new("c.parquet"), Pathname.new("d.orc")])
# => CREATE TEMPORARY VIEW `c` USING parquet OPTIONS ('path'='c.parquet')
# => CREATE TEMPORARY VIEW `d` USING orc OPTIONS ('path'='d.orc')

Parameters:

  • (defaults to: {})

    the options used to prepare the database

Options Hash (opts):

  • :use_schema (Symbol)

    The schema to be used as the primary schema

  • :search_path (Array)

    A set of symbols (schemas) or Pathnames (external files)

  • :only (Array)

    Limit view creation to these tables only

  • :except (Array)

    Skip view creation for these tables



48
49
50
# File 'lib/sequel/extensions/make_readyable.rb', line 48

def make_ready(opts = {})
  ReadyMaker.new(self, opts).run
end