Module: ROM::SQL

Extended by:
Dry::Core::Extensions
Included in:
Relation
Defined in:
lib/rom/sql/dsl.rb,
lib/rom/sql/wrap.rb,
lib/rom/sql/error.rb,
lib/rom/sql/index.rb,
lib/rom/sql/types.rb,
lib/rom/sql/errors.rb,
lib/rom/sql/schema.rb,
lib/rom/sql/gateway.rb,
lib/rom/sql/version.rb,
lib/rom/sql/function.rb,
lib/rom/sql/join_dsl.rb,
lib/rom/sql/relation.rb,
lib/rom/sql/type_dsl.rb,
lib/rom/sql/attribute.rb,
lib/rom/sql/group_dsl.rb,
lib/rom/sql/migration.rb,
lib/rom/sql/order_dsl.rb,
lib/rom/sql/extensions.rb,
lib/rom/sql/schema/dsl.rb,
lib/rom/sql/foreign_key.rb,
lib/rom/sql/transaction.rb,
lib/rom/sql/plugin/nullify.rb,
lib/rom/sql/projection_dsl.rb,
lib/rom/sql/commands/create.rb,
lib/rom/sql/commands/delete.rb,
lib/rom/sql/commands/update.rb,
lib/rom/sql/mapper_compiler.rb,
lib/rom/sql/restriction_dsl.rb,
lib/rom/sql/schema/inferrer.rb,
lib/rom/sql/type_extensions.rb,
lib/rom/sql/type_serializer.rb,
lib/rom/sql/migration/runner.rb,
lib/rom/sql/migration/writer.rb,
lib/rom/sql/relation/reading.rb,
lib/rom/sql/relation/writing.rb,
lib/rom/sql/schema/index_dsl.rb,
lib/rom/sql/associations/core.rb,
lib/rom/sql/plugin/associates.rb,
lib/rom/sql/plugin/pagination.rb,
lib/rom/sql/attribute_aliasing.rb,
lib/rom/sql/attribute_wrapping.rb,
lib/rom/sql/migration/migrator.rb,
lib/rom/sql/migration/recorder.rb,
lib/rom/sql/schema/type_builder.rb,
lib/rom/sql/associations/self_ref.rb,
lib/rom/sql/migration/schema_diff.rb,
lib/rom/sql/plugin/schema_indexes.rb,
lib/rom/sql/commands/error_wrapper.rb,
lib/rom/sql/associations/one_to_one.rb,
lib/rom/sql/extensions/sqlite/types.rb,
lib/rom/sql/migration/inline_runner.rb,
lib/rom/sql/associations/many_to_one.rb,
lib/rom/sql/associations/one_to_many.rb,
lib/rom/sql/associations/many_to_many.rb,
lib/rom/sql/extensions/postgres/types.rb,
lib/rom/sql/schema/attributes_inferrer.rb,
lib/rom/sql/extensions/postgres/commands.rb,
lib/rom/sql/extensions/mysql/type_builder.rb,
lib/rom/sql/extensions/postgres/types/json.rb,
lib/rom/sql/extensions/sqlite/type_builder.rb,
lib/rom/sql/associations/one_to_one_through.rb,
lib/rom/sql/extensions/postgres/types/array.rb,
lib/rom/sql/extensions/postgres/types/ltree.rb,
lib/rom/sql/extensions/postgres/types/range.rb,
lib/rom/sql/extensions/rails_log_subscriber.rb,
lib/rom/sql/extensions/postgres/type_builder.rb,
lib/rom/sql/extensions/postgres/types/network.rb,
lib/rom/sql/extensions/postgres/type_serializer.rb,
lib/rom/sql/extensions/postgres/types/geometric.rb,
lib/rom/sql/extensions/postgres/types/array_types.rb,
lib/rom/sql/extensions/active_support_notifications.rb

Defined Under Namespace

Modules: ActiveSupportInstrumentation, Associations, AttributeAliasing, AttributeWrapping, Commands, Migration, MySQL, Plugin, Postgres, SQLite, TypeExtensions, Types Classes: Attribute, DSL, Error, ForeignKey, Function, Gateway, GroupDSL, Index, JoinDSL, MapperCompiler, OrderDSL, ProjectionDSL, RailsLogSubscriber, Relation, RestrictionDSL, Schema, Transaction, TypeDSL, TypeSerializer, Wrap

Constant Summary collapse

MissingConfigurationError =
Class.new(StandardError)
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)
UnknownDBTypeError =
Class.new(StandardError)
MissingPrimaryKeyError =
Class.new(StandardError)
MigrationError =
Class.new(StandardError)
UnsupportedConversion =
Class.new(MigrationError)
ERROR_MAP =
{
  Sequel::DatabaseError => DatabaseError,
  Sequel::ConstraintViolation => ConstraintError,
  Sequel::NotNullConstraintViolation => NotNullConstraintError,
  Sequel::UniqueConstraintViolation => UniqueConstraintError,
  Sequel::ForeignKeyConstraintViolation => ForeignKeyConstraintError,
  Sequel::CheckConstraintViolation => CheckConstraintError
}.freeze
VERSION =
"4.0.0.alpha1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.current_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.



67
68
69
# File 'lib/rom/sql/migration.rb', line 67

def current_gateway
  @current_gateway
end

Class Method Details

.migration(container, gateway) ⇒ Object

Trap for the migration runner. By default migrations are bound to the gateway you're using to run them. You also can explicitly pass a configuration object and a gateway name but this normally won't be not required.

Examples:

# Ordinary migration
ROM::SQL.migration do
  change do
    create_table(:users) do
      primary_key :id
      String :name
    end
  end
end
# Providing a config
rom = ROM::Configuration.new(
  default: [:sql, 'sqlite::memory'],
  other: [:sql, 'postgres://localhost/test']
)

# default gateway migrations
ROM::SQL.migration(rom) do
  change do
    create_table(:users) do
      primary_key :id
      String :name
    end
  end
end

# other gateway migrations
ROM::SQL.migration(rom, :other) do
  change do
    create_table(:users) do
      primary_key :id
      String :name
    end
  end
end

Parameters:

  • container (ROM::Container)

    The container instance used for accessing gateways

  • gateway (Symbol)

    The gateway name, :default by default



57
58
59
60
61
62
63
64
# File 'lib/rom/sql/migration.rb', line 57

def migration(*args, &block)
  if args.any?
    container, gateway, * = args
    with_gateway(container.gateways[gateway || :default]) { migration(&block) }
  else
    current_gateway.migration(&block)
  end
end

.with_gateway(gateway) ⇒ Object

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.

This method is used on loading migrations. Temporally sets the global "current_gateway", you shouln't access it.



73
74
75
76
77
78
79
80
# File 'lib/rom/sql/migration.rb', line 73

def with_gateway(gateway)
  current = @current_gateway
  @current_gateway = gateway

  yield
ensure
  @current_gateway = current
end