Module: Sequel::MoreSql

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

Overview

Provides additional SQL helper methods for database operations.

The more_sql extension adds convenience methods for SQL operations that aren't covered by Sequel's core functionality, particularly schema-related operations like CREATE SCHEMA.

Examples:

Load the extension

DB.extension :more_sql

Create a schema

DB.create_schema(:analytics)
# Executes: CREATE SCHEMA "analytics"

Create schema if it doesn't exist

DB.create_schema(:staging, if_not_exists: true)
# Executes: CREATE SCHEMA IF NOT EXISTS "staging"

Instance Method Summary collapse

Instance Method Details

#create_schema(schema_name, opts = {}) ⇒ nil

Creates a database schema.

Generates and executes a CREATE SCHEMA statement with optional IF NOT EXISTS clause for idempotent schema creation.

Examples:

Basic schema creation

DB.create_schema(:reports)
# Executes: CREATE SCHEMA "reports"

Idempotent schema creation

DB.create_schema(:analytics, if_not_exists: true)
# Executes: CREATE SCHEMA IF NOT EXISTS "analytics"

With string schema name

DB.create_schema('user_data')
# Executes: CREATE SCHEMA "user_data"

Parameters:

  • schema_name (Symbol, String)

    The name of the schema to create

  • opts (Hash) (defaults to: {})

    Options for schema creation

Options Hash (opts):

  • :if_not_exists (Boolean) — default: false

    Only create the schema if it doesn't already exist

Returns:

  • (nil)


45
46
47
# File 'lib/sequel/extensions/more_sql.rb', line 45

def create_schema(schema_name, opts = {})
  run(create_schema_sql(schema_name, opts))
end