Module: ROM::SQL

Defined in:
lib/rom/sql.rb,
lib/rom/sql/header.rb,
lib/rom/sql/gateway.rb,
lib/rom/sql/version.rb,
lib/rom/sql/relation.rb,
lib/rom/sql/migration.rb,
lib/rom/sql/commands/create.rb,
lib/rom/sql/commands/delete.rb,
lib/rom/sql/commands/update.rb,
lib/rom/sql/plugin/associates.rb,
lib/rom/sql/plugin/pagination.rb,
lib/rom/sql/migration/migrator.rb,
lib/rom/sql/relation/inspection.rb,
lib/rom/sql/commands/transaction.rb,
lib/rom/sql/commands_ext/postgres.rb,
lib/rom/sql/relation/associations.rb,
lib/rom/sql/commands/error_wrapper.rb,
lib/rom/sql/relation/class_methods.rb,
lib/rom/sql/support/rails_log_subscriber.rb

Defined Under Namespace

Modules: Commands, Migration, Plugin Classes: Error, Gateway, Header, RailsLogSubscriber, Relation

Constant Summary collapse

NoAssociationError =
Class.new(StandardError)
DatabaseError =
Class.new(Error)
ConstraintError =
Class.new(Error)
NotNullConstraintError =
Class.new(ConstraintError)
UniqueConstraintError =
Class.new(ConstraintError)
ForeignKeyConstraintError =
Class.new(ConstraintError)
CheckConstraintError =
Class.new(ConstraintError)
ERROR_MAP =
{
  Sequel::DatabaseError => DatabaseError,
  Sequel::NotNullConstraintViolation => NotNullConstraintError,
  Sequel::UniqueConstraintViolation => UniqueConstraintError,
  Sequel::ForeignKeyConstraintViolation => ForeignKeyConstraintError,
  Sequel::CheckConstraintViolation => CheckConstraintError
}.freeze
VERSION =
'0.5.2'.freeze
Rollback =
Class.new(Sequel::Rollback)

Class Method Summary collapse

Class Method Details

.gatewayObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return first sql gateway for migrations

This is used by migration tasks, they only support a single sql gateway



40
41
42
43
44
# File 'lib/rom/sql/migration.rb', line 40

def self.gateway
  ROM.gateways
    .keys
    .detect { |gateway| gateway.instance_of?(Gateway) }
end

.migration(gateway = :default, &block) ⇒ Object

Create a database migration for a specific gateway

Examples:

ROM.setup(
  default: [:sql, 'sqlite::memory'],
  other: [:sql, 'postgres://localhost/test']
)

ROM.finalize

ROM::SQL.migration do
  change do
    create_table(:users) do
      primary_key :id
      String :name
    end
  end
end

# for a non-default gateway
ROM::SQL.migration(:other) do
  # ...
end


30
31
32
33
# File 'lib/rom/sql/migration.rb', line 30

def self.migration(gateway = :default, &block)
  gateways = ROM.boot ? ROM.boot.gateways : ROM.env.gateways
  gateways[gateway].migration(&block)
end