### Home Classes Methods

### Files

- CHANGELOG
- MIT-LICENSE
- README.rdoc
- active_record.rdoc
- advanced_associations.rdoc
- association_basics.rdoc
- bin_sequel.rdoc
- cheat_sheet.rdoc
- code_order.rdoc
- core_extensions.rdoc
- dataset_basics.rdoc
- dataset_filtering.rdoc
- mass_assignment.rdoc
- migration.rdoc
- model_hooks.rdoc
- object_model.rdoc
- opening_databases.rdoc
- postgresql.rdoc
- prepared_statements.rdoc
- querying.rdoc
- reflection.rdoc
- 1.0.txt
- 1.1.txt
- 1.3.txt
- 1.4.0.txt
- 1.5.0.txt
- 2.0.0.txt
- 2.1.0.txt
- 2.10.0.txt
- 2.11.0.txt
- 2.12.0.txt
- 2.2.0.txt
- 2.3.0.txt
- 2.4.0.txt
- 2.5.0.txt
- 2.6.0.txt
- 2.7.0.txt
- 2.8.0.txt
- 2.9.0.txt
- 3.0.0.txt
- 3.1.0.txt
- 3.10.0.txt
- 3.11.0.txt
- 3.12.0.txt
- 3.13.0.txt
- 3.14.0.txt
- 3.15.0.txt
- 3.16.0.txt
- 3.17.0.txt
- 3.18.0.txt
- 3.19.0.txt
- 3.2.0.txt
- 3.20.0.txt
- 3.21.0.txt
- 3.22.0.txt
- 3.23.0.txt
- 3.24.0.txt
- 3.25.0.txt
- 3.26.0.txt
- 3.27.0.txt
- 3.28.0.txt
- 3.29.0.txt
- 3.3.0.txt
- 3.30.0.txt
- 3.31.0.txt
- 3.32.0.txt
- 3.33.0.txt
- 3.34.0.txt
- 3.35.0.txt
- 3.36.0.txt
- 3.37.0.txt
- 3.38.0.txt
- 3.39.0.txt
- 3.4.0.txt
- 3.40.0.txt
- 3.41.0.txt
- 3.42.0.txt
- 3.43.0.txt
- 3.44.0.txt
- 3.45.0.txt
- 3.46.0.txt
- 3.47.0.txt
- 3.48.0.txt
- 3.5.0.txt
- 3.6.0.txt
- 3.7.0.txt
- 3.8.0.txt
- 3.9.0.txt
- 4.0.0.txt
- schema_modification.rdoc
- security.rdoc
- sharding.rdoc
- sql.rdoc
- testing.rdoc
- thread_safety.rdoc
- transactions.rdoc
- validations.rdoc
- virtual_rows.rdoc

### Class Index

Quicksearch

- Sequel
- Sequel::ADO
- Sequel::ADO::Access
- Sequel::ADO::Access::AdoSchema
- Sequel::ADO::Access::AdoSchema::Column
- Sequel::ADO::Access::DatabaseMethods
- Sequel::ADO::Access::Dataset
- Sequel::ADO::Database
- Sequel::ADO::Dataset
- Sequel::ADO::MSSQL
- Sequel::ADO::MSSQL::DatabaseMethods
- Sequel::ADO::MSSQL::Dataset
- Sequel::ASTTransformer
- Sequel::Access
- Sequel::Access::DatabaseMethods
- Sequel::Access::DatasetMethods
- Sequel::AdapterNotFound
- Sequel::Amalgalite
- Sequel::Amalgalite::Database
- Sequel::Amalgalite::Dataset
- Sequel::Amalgalite::SequelTypeMap
- Sequel::ArbitraryServers
- Sequel::BasicObject
- Sequel::BeforeHookFailed
- Sequel::CheckConstraintViolation
- Sequel::ColumnsIntrospection
- Sequel::ConnectionPool
- Sequel::ConnectionPool::ClassMethods
- Sequel::ConnectionValidator
- Sequel::ConnectionValidator::Retry
- Sequel::ConstraintValidations
- Sequel::ConstraintValidations::AlterTableGeneratorMethods
- Sequel::ConstraintValidations::CreateTableGeneratorMethods
- Sequel::ConstraintValidations::Generator
- Sequel::ConstraintViolation
- Sequel::CoreRefinements
- Sequel::Cubrid
- Sequel::Cubrid::Database
- Sequel::Cubrid::DatabaseMethods
- Sequel::Cubrid::Dataset
- Sequel::Cubrid::DatasetMethods
- Sequel::DB2
- Sequel::DB2::DB2Error
- Sequel::DB2::Database
- Sequel::DB2::DatabaseMethods
- Sequel::DB2::Dataset
- Sequel::DB2::DatasetMethods
- Sequel::DBI
- Sequel::DBI::Database
- Sequel::DBI::Dataset
- Sequel::DataObjects
- Sequel::DataObjects::Database
- Sequel::DataObjects::Dataset
- Sequel::DataObjects::MySQL
- Sequel::DataObjects::MySQL::DatabaseMethods
- Sequel::DataObjects::MySQL::Dataset
- Sequel::DataObjects::Postgres
- Sequel::DataObjects::Postgres::DatabaseMethods
- Sequel::DataObjects::SQLite
- Sequel::DataObjects::SQLite::DatabaseMethods
- Sequel::Database
- Sequel::Database::DatasetClass
- Sequel::Database::ResetIdentifierMangling
- Sequel::Database::SplitAlterTable
- Sequel::DatabaseConnectionError
- Sequel::DatabaseDisconnectError
- Sequel::DatabaseError
- Sequel::DatabaseQuery
- Sequel::Dataset
- Sequel::Dataset::ArgumentMapper
- Sequel::Dataset::NullDataset
- Sequel::Dataset::Nullifiable
- Sequel::Dataset::Pagination
- Sequel::Dataset::PreparedStatementMethods
- Sequel::Dataset::Query
- Sequel::Dataset::SplitArrayNil
- Sequel::Dataset::StoredProcedureMethods
- Sequel::Dataset::StoredProcedures
- Sequel::Dataset::UnnumberedArgumentMapper
- Sequel::DatasetPagination
- Sequel::DatasetPrinter
- Sequel::DatasetQuery
- Sequel::Deprecation
- Sequel::EmptyArrayIgnoreNulls
- Sequel::EmulateOffsetWithReverseAndCount
- Sequel::EmulateOffsetWithRowNumber
- Sequel::Error
- Sequel::Error::AdapterNotFound
- Sequel::Error::InvalidOperation
- Sequel::Error::InvalidValue
- Sequel::Error::PoolTimeoutError
- Sequel::Error::Rollback
- Sequel::EvalInspect
- Sequel::FilterHaving
- Sequel::Firebird
- Sequel::Firebird::Database
- Sequel::Firebird::DatabaseMethods
- Sequel::Firebird::Dataset
- Sequel::Firebird::DatasetMethods
- Sequel::ForeignKeyConstraintViolation
- Sequel::GraphEach
- Sequel::HashAliases
- Sequel::HookFailed
- Sequel::IBMDB
- Sequel::IBMDB::Connection
- Sequel::IBMDB::Connection::Error
- Sequel::IBMDB::Database
- Sequel::IBMDB::Dataset
- Sequel::IBMDB::Dataset::CallableStatementMethods
- Sequel::IBMDB::Dataset::PreparedStatementMethods
- Sequel::IBMDB::Statement
- Sequel::Inflections
- Sequel::Informix
- Sequel::Informix::Database
- Sequel::Informix::DatabaseMethods
- Sequel::Informix::Dataset
- Sequel::Informix::DatasetMethods
- Sequel::IntegerMigrator
- Sequel::InvalidOperation
- Sequel::InvalidValue
- Sequel::JDBC
- Sequel::JDBC::AS400
- Sequel::JDBC::AS400::DatabaseMethods
- Sequel::JDBC::AS400::Dataset
- Sequel::JDBC::Cubrid
- Sequel::JDBC::Cubrid::DatabaseMethods
- Sequel::JDBC::DB2
- Sequel::JDBC::DB2::DatabaseMethods
- Sequel::JDBC::DB2::Dataset
- Sequel::JDBC::Database
- Sequel::JDBC::Dataset
- Sequel::JDBC::Dataset::PreparedStatementMethods
- Sequel::JDBC::Dataset::StoredProcedureMethods
- Sequel::JDBC::Dataset::TYPE_TRANSLATOR
- Sequel::JDBC::Derby
- Sequel::JDBC::Derby::DatabaseMethods
- Sequel::JDBC::Derby::Dataset
- Sequel::JDBC::Firebird
- Sequel::JDBC::Firebird::DatabaseMethods
- Sequel::JDBC::H2
- Sequel::JDBC::H2::DatabaseMethods
- Sequel::JDBC::H2::Dataset
- Sequel::JDBC::HSQLDB
- Sequel::JDBC::HSQLDB::DatabaseMethods
- Sequel::JDBC::HSQLDB::Dataset
- Sequel::JDBC::Informix
- Sequel::JDBC::Informix::DatabaseMethods
- Sequel::JDBC::JTDS
- Sequel::JDBC::JTDS::DatabaseMethods
- Sequel::JDBC::JTDS::Dataset
- Sequel::JDBC::JavaLang
- Sequel::JDBC::JavaSQL
- Sequel::JDBC::JavaxNaming
- Sequel::JDBC::MSSQL
- Sequel::JDBC::MSSQL::DatabaseMethods
- Sequel::JDBC::MySQL
- Sequel::JDBC::MySQL::DatabaseMethods
- Sequel::JDBC::Oracle
- Sequel::JDBC::Oracle::DatabaseMethods
- Sequel::JDBC::Oracle::Dataset
- Sequel::JDBC::Postgres
- Sequel::JDBC::Postgres::DatabaseMethods
- Sequel::JDBC::Postgres::Dataset
- Sequel::JDBC::Postgres::Dataset::PGArrayConverter
- Sequel::JDBC::Progress
- Sequel::JDBC::Progress::DatabaseMethods
- Sequel::JDBC::SQLServer
- Sequel::JDBC::SQLServer::DatabaseMethods
- Sequel::JDBC::SQLServer::DatabaseMethods::MetadataDatasetMethods
- Sequel::JDBC::SQLite
- Sequel::JDBC::SQLite::DatabaseMethods
- Sequel::JDBC::Transactions
- Sequel::LiteralString
- Sequel::LooserTypecasting
- Sequel::MSSQL
- Sequel::MSSQL::DatabaseMethods
- Sequel::MSSQL::DatasetMethods
- Sequel::Metaprogramming
- Sequel::Migration
- Sequel::MigrationAlterTableReverser
- Sequel::MigrationDSL
- Sequel::MigrationReverser
- Sequel::Migrator
- Sequel::Migrator::Error
- Sequel::Migrator::NotCurrentError
- Sequel::Mock
- Sequel::Mock::Connection
- Sequel::Mock::Database
- Sequel::Mock::Dataset
- Sequel::Model
- Sequel::Model::Associations
- Sequel::Model::Associations::AssociationDatasetMethods
- Sequel::Model::Associations::AssociationReflection
- Sequel::Model::Associations::ClassMethods
- Sequel::Model::Associations::DatasetMethods
- Sequel::Model::Associations::EagerGraphLoader
- Sequel::Model::Associations::InstanceMethods
- Sequel::Model::Associations::ManyToManyAssociationReflection
- Sequel::Model::Associations::ManyToOneAssociationReflection
- Sequel::Model::Associations::OneToManyAssociationReflection
- Sequel::Model::Associations::OneToOneAssociationReflection
- Sequel::Model::ClassMethods
- Sequel::Model::DatasetMethods
- Sequel::Model::DatasetModule
- Sequel::Model::Errors
- Sequel::Model::InstanceMethods
- Sequel::MySQL
- Sequel::MySQL::Database
- Sequel::MySQL::DatabaseMethods
- Sequel::MySQL::Dataset
- Sequel::MySQL::DatasetMethods
- Sequel::MySQL::PreparedStatements
- Sequel::MySQL::PreparedStatements::DatabaseMethods
- Sequel::MySQL::PreparedStatements::DatasetMethods
- Sequel::MySQL::PreparedStatements::DatasetMethods::CallableStatementMethods
- Sequel::MySQL::PreparedStatements::DatasetMethods::PreparedStatementMethods
- Sequel::MySQL::PreparedStatements::DatasetMethods::StoredProcedureMethods
- Sequel::Mysql2
- Sequel::Mysql2::Database
- Sequel::Mysql2::Dataset
- Sequel::NamedTimezones
- Sequel::NamedTimezones::DatabaseMethods
- Sequel::NoExistingObject
- Sequel::NoMatchingRow
- Sequel::NotNullConstraintViolation
- Sequel::ODBC
- Sequel::ODBC::Database
- Sequel::ODBC::Dataset
- Sequel::ODBC::MSSQL
- Sequel::ODBC::MSSQL::DatabaseMethods
- Sequel::ODBC::MSSQL::Dataset
- Sequel::OpenBase
- Sequel::OpenBase::Database
- Sequel::OpenBase::Dataset
- Sequel::Oracle
- Sequel::Oracle::Database
- Sequel::Oracle::DatabaseMethods
- Sequel::Oracle::Dataset
- Sequel::Oracle::Dataset::ArgumentMapper
- Sequel::Oracle::Dataset::BindArgumentMethods
- Sequel::Oracle::Dataset::PreparedStatementMethods
- Sequel::Oracle::DatasetMethods
- Sequel::Plugins
- Sequel::Plugins::ActiveModel
- Sequel::Plugins::ActiveModel::ClassMethods
- Sequel::Plugins::ActiveModel::Errors
- Sequel::Plugins::ActiveModel::InstanceMethods
- Sequel::Plugins::AfterInitialize
- Sequel::Plugins::AfterInitialize::ClassMethods
- Sequel::Plugins::AfterInitialize::InstanceMethods
- Sequel::Plugins::AssociationAutoreloading
- Sequel::Plugins::AssociationDependencies
- Sequel::Plugins::AssociationDependencies::ClassMethods
- Sequel::Plugins::AssociationDependencies::InstanceMethods
- Sequel::Plugins::AssociationPks
- Sequel::Plugins::AssociationPks::ClassMethods
- Sequel::Plugins::AssociationPks::InstanceMethods
- Sequel::Plugins::AssociationProxies
- Sequel::Plugins::AssociationProxies::AssociationProxy
- Sequel::Plugins::AssociationProxies::ClassMethods
- Sequel::Plugins::AutoValidations
- Sequel::Plugins::AutoValidations::ClassMethods
- Sequel::Plugins::AutoValidations::InstanceMethods
- Sequel::Plugins::BlacklistSecurity
- Sequel::Plugins::BlacklistSecurity::ClassMethods
- Sequel::Plugins::BlacklistSecurity::InstanceMethods
- Sequel::Plugins::BlacklistSecurity::InstanceMethods::ExceptionList
- Sequel::Plugins::BooleanReaders
- Sequel::Plugins::BooleanReaders::ClassMethods
- Sequel::Plugins::Caching
- Sequel::Plugins::Caching::ClassMethods
- Sequel::Plugins::Caching::InstanceMethods
- Sequel::Plugins::ClassTableInheritance
- Sequel::Plugins::ClassTableInheritance::ClassMethods
- Sequel::Plugins::ClassTableInheritance::InstanceMethods
- Sequel::Plugins::Composition
- Sequel::Plugins::Composition::ClassMethods
- Sequel::Plugins::Composition::InstanceMethods
- Sequel::Plugins::ConstraintValidations
- Sequel::Plugins::ConstraintValidations::ClassMethods
- Sequel::Plugins::ConstraintValidations::DatabaseMethods
- Sequel::Plugins::ConstraintValidations::InstanceMethods
- Sequel::Plugins::DatasetAssociations
- Sequel::Plugins::DatasetAssociations::ClassMethods
- Sequel::Plugins::DatasetAssociations::DatasetMethods
- Sequel::Plugins::DefaultsSetter
- Sequel::Plugins::DefaultsSetter::ClassMethods
- Sequel::Plugins::DefaultsSetter::InstanceMethods
- Sequel::Plugins::Dirty
- Sequel::Plugins::Dirty::InstanceMethods
- Sequel::Plugins::EagerEach
- Sequel::Plugins::EagerEach::DatasetMethods
- Sequel::Plugins::ErrorSplitter
- Sequel::Plugins::ErrorSplitter::InstanceMethods
- Sequel::Plugins::ForceEncoding
- Sequel::Plugins::ForceEncoding::ClassMethods
- Sequel::Plugins::ForceEncoding::InstanceMethods
- Sequel::Plugins::HookClassMethods
- Sequel::Plugins::HookClassMethods::ClassMethods
- Sequel::Plugins::HookClassMethods::InstanceMethods
- Sequel::Plugins::InputTransformer
- Sequel::Plugins::InputTransformer::ClassMethods
- Sequel::Plugins::InputTransformer::InstanceMethods
- Sequel::Plugins::InstanceFilters
- Sequel::Plugins::InstanceFilters::Error
- Sequel::Plugins::InstanceFilters::InstanceMethods
- Sequel::Plugins::InstanceHooks
- Sequel::Plugins::InstanceHooks::InstanceMethods
- Sequel::Plugins::JsonSerializer
- Sequel::Plugins::JsonSerializer::ClassMethods
- Sequel::Plugins::JsonSerializer::DatasetMethods
- Sequel::Plugins::JsonSerializer::InstanceMethods
- Sequel::Plugins::JsonSerializer::Literal
- Sequel::Plugins::LazyAttributes
- Sequel::Plugins::LazyAttributes::ClassMethods
- Sequel::Plugins::LazyAttributes::InstanceMethods
- Sequel::Plugins::List
- Sequel::Plugins::List::ClassMethods
- Sequel::Plugins::List::InstanceMethods
- Sequel::Plugins::ManyThroughMany
- Sequel::Plugins::ManyThroughMany::ClassMethods
- Sequel::Plugins::ManyThroughMany::DatasetMethods
- Sequel::Plugins::ManyThroughMany::ManyThroughManyAssociationReflection
- Sequel::Plugins::ManyToOnePkLookup
- Sequel::Plugins::NestedAttributes
- Sequel::Plugins::NestedAttributes::ClassMethods
- Sequel::Plugins::NestedAttributes::InstanceMethods
- Sequel::Plugins::OptimisticLocking
- Sequel::Plugins::OptimisticLocking::ClassMethods
- Sequel::Plugins::OptimisticLocking::Error
- Sequel::Plugins::OptimisticLocking::InstanceMethods
- Sequel::Plugins::PgArrayAssociations
- Sequel::Plugins::PgArrayAssociations::ClassMethods
- Sequel::Plugins::PgArrayAssociations::DatasetMethods
- Sequel::Plugins::PgArrayAssociations::ManyToPgArrayAssociationReflection
- Sequel::Plugins::PgArrayAssociations::PgArrayToManyAssociationReflection
- Sequel::Plugins::PgRow
- Sequel::Plugins::PgRow::ClassMethods
- Sequel::Plugins::PgRow::DatabaseMethods
- Sequel::Plugins::PgRow::InstanceMethods
- Sequel::Plugins::PgTypecastOnLoad
- Sequel::Plugins::PgTypecastOnLoad::ClassMethods
- Sequel::Plugins::PgTypecastOnLoad::InstanceMethods
- Sequel::Plugins::PreparedStatements
- Sequel::Plugins::PreparedStatements::ClassMethods
- Sequel::Plugins::PreparedStatements::InstanceMethods
- Sequel::Plugins::PreparedStatementsAssociations
- Sequel::Plugins::PreparedStatementsAssociations::ClassMethods
- Sequel::Plugins::PreparedStatementsAssociations::InstanceMethods
- Sequel::Plugins::PreparedStatementsSafe
- Sequel::Plugins::PreparedStatementsSafe::ClassMethods
- Sequel::Plugins::PreparedStatementsSafe::InstanceMethods
- Sequel::Plugins::PreparedStatementsWithPk
- Sequel::Plugins::PreparedStatementsWithPk::ClassMethods
- Sequel::Plugins::PreparedStatementsWithPk::DatasetMethods
- Sequel::Plugins::RcteTree
- Sequel::Plugins::Schema
- Sequel::Plugins::Schema::ClassMethods
- Sequel::Plugins::Scissors
- Sequel::Plugins::Scissors::ClassMethods
- Sequel::Plugins::Serialization
- Sequel::Plugins::Serialization::ClassMethods
- Sequel::Plugins::Serialization::InstanceMethods
- Sequel::Plugins::SerializationModificationDetection
- Sequel::Plugins::SerializationModificationDetection::InstanceMethods
- Sequel::Plugins::Sharding
- Sequel::Plugins::Sharding::ClassMethods
- Sequel::Plugins::Sharding::DatasetMethods
- Sequel::Plugins::Sharding::InstanceMethods
- Sequel::Plugins::SingleTableInheritance
- Sequel::Plugins::SingleTableInheritance::ClassMethods
- Sequel::Plugins::SingleTableInheritance::InstanceMethods
- Sequel::Plugins::SkipCreateRefresh
- Sequel::Plugins::SkipCreateRefresh::InstanceMethods
- Sequel::Plugins::StaticCache
- Sequel::Plugins::StaticCache::ClassMethods
- Sequel::Plugins::StringStripper
- Sequel::Plugins::StringStripper::ClassMethods
- Sequel::Plugins::Subclasses
- Sequel::Plugins::Subclasses::ClassMethods
- Sequel::Plugins::TacticalEagerLoading
- Sequel::Plugins::TacticalEagerLoading::DatasetMethods
- Sequel::Plugins::TacticalEagerLoading::InstanceMethods
- Sequel::Plugins::Timestamps
- Sequel::Plugins::Timestamps::ClassMethods
- Sequel::Plugins::Timestamps::InstanceMethods
- Sequel::Plugins::Touch
- Sequel::Plugins::Touch::ClassMethods
- Sequel::Plugins::Touch::InstanceMethods
- Sequel::Plugins::Tree
- Sequel::Plugins::Tree::ClassMethods
- Sequel::Plugins::Tree::InstanceMethods
- Sequel::Plugins::Tree::SingleRoot
- Sequel::Plugins::Tree::SingleRoot::ClassMethods
- Sequel::Plugins::Tree::SingleRoot::InstanceMethods
- Sequel::Plugins::Tree::TreeMultipleRootError
- Sequel::Plugins::TypecastOnLoad
- Sequel::Plugins::TypecastOnLoad::ClassMethods
- Sequel::Plugins::TypecastOnLoad::InstanceMethods
- Sequel::Plugins::UnlimitedUpdate
- Sequel::Plugins::UnlimitedUpdate::InstanceMethods
- Sequel::Plugins::UpdatePrimaryKey
- Sequel::Plugins::UpdatePrimaryKey::InstanceMethods
- Sequel::Plugins::ValidationClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods::Generator
- Sequel::Plugins::ValidationClassMethods::InstanceMethods
- Sequel::Plugins::ValidationHelpers
- Sequel::Plugins::ValidationHelpers::InstanceMethods
- Sequel::Plugins::XmlSerializer
- Sequel::Plugins::XmlSerializer::ClassMethods
- Sequel::Plugins::XmlSerializer::DatasetMethods
- Sequel::Plugins::XmlSerializer::InstanceMethods
- Sequel::PoolTimeout
- Sequel::Postgres
- Sequel::Postgres::Adapter
- Sequel::Postgres::AlterTableGenerator
- Sequel::Postgres::ArrayOp
- Sequel::Postgres::ArrayOpMethods
- Sequel::Postgres::CreateTableGenerator
- Sequel::Postgres::Database
- Sequel::Postgres::DatabaseMethods
- Sequel::Postgres::Dataset
- Sequel::Postgres::Dataset::ArgumentMapper
- Sequel::Postgres::Dataset::BindArgumentMethods
- Sequel::Postgres::Dataset::PreparedStatementMethods
- Sequel::Postgres::DatasetMethods
- Sequel::Postgres::DatasetMethods::PreparedStatementMethods
- Sequel::Postgres::ExclusionConstraintViolation
- Sequel::Postgres::HStore
- Sequel::Postgres::HStore::DatabaseMethods
- Sequel::Postgres::HStore::Parser
- Sequel::Postgres::HStoreOp
- Sequel::Postgres::HStoreOpMethods
- Sequel::Postgres::InetDatabaseMethods
- Sequel::Postgres::InetDatasetMethods
- Sequel::Postgres::IntervalDatabaseMethods
- Sequel::Postgres::IntervalDatabaseMethods::Parser
- Sequel::Postgres::IntervalDatasetMethods
- Sequel::Postgres::JSONArray
- Sequel::Postgres::JSONDatabaseMethods
- Sequel::Postgres::JSONHash
- Sequel::Postgres::JSONOp
- Sequel::Postgres::JSONOpMethods
- Sequel::Postgres::PGArray
- Sequel::Postgres::PGArray::Creator
- Sequel::Postgres::PGArray::DatabaseMethods
- Sequel::Postgres::PGArray::JSONCreator
- Sequel::Postgres::PGArray::Parser
- Sequel::Postgres::PGRange
- Sequel::Postgres::PGRange::DatabaseMethods
- Sequel::Postgres::PGRange::DatasetMethods
- Sequel::Postgres::PGRange::Parser
- Sequel::Postgres::PGRow
- Sequel::Postgres::PGRow::ArrayRow
- Sequel::Postgres::PGRow::DatabaseMethods
- Sequel::Postgres::PGRow::HashRow
- Sequel::Postgres::PGRow::Parser
- Sequel::Postgres::PGRow::Splitter
- Sequel::Postgres::PGRowOp
- Sequel::Postgres::PGRowOp::ExpressionMethods
- Sequel::Postgres::RangeOp
- Sequel::Postgres::RangeOpMethods
- Sequel::PrettyTable
- Sequel::Progress
- Sequel::Progress::DatabaseMethods
- Sequel::Progress::DatasetMethods
- Sequel::Qualifier
- Sequel::QueryLiterals
- Sequel::Rollback
- Sequel::SQL
- Sequel::SQL::AliasMethods
- Sequel::SQL::AliasedExpression
- Sequel::SQL::BitwiseMethods
- Sequel::SQL::Blob
- Sequel::SQL::BooleanConstant
- Sequel::SQL::BooleanExpression
- Sequel::SQL::BooleanMethods
- Sequel::SQL::Builders
- Sequel::SQL::CaseExpression
- Sequel::SQL::Cast
- Sequel::SQL::CastMethods
- Sequel::SQL::ColumnAll
- Sequel::SQL::ComplexExpression
- Sequel::SQL::ComplexExpressionMethods
- Sequel::SQL::Constant
- Sequel::SQL::Constants
- Sequel::SQL::DateAdd
- Sequel::SQL::DateAdd::DatasetMethods
- Sequel::SQL::DelayedEvaluation
- Sequel::SQL::EmulatedFunction
- Sequel::SQL::Expression
- Sequel::SQL::Function
- Sequel::SQL::GenericExpression
- Sequel::SQL::Identifier
- Sequel::SQL::InequalityMethods
- Sequel::SQL::JoinClause
- Sequel::SQL::JoinOnClause
- Sequel::SQL::JoinUsingClause
- Sequel::SQL::NegativeBooleanConstant
- Sequel::SQL::NumericExpression
- Sequel::SQL::NumericMethods
- Sequel::SQL::OperatorBuilders
- Sequel::SQL::OrderMethods
- Sequel::SQL::OrderedExpression
- Sequel::SQL::PlaceholderLiteralString
- Sequel::SQL::QualifiedIdentifier
- Sequel::SQL::QualifyingMethods
- Sequel::SQL::StringConcatenationMethods
- Sequel::SQL::StringExpression
- Sequel::SQL::StringMethods
- Sequel::SQL::Subscript
- Sequel::SQL::SubscriptMethods
- Sequel::SQL::ValueList
- Sequel::SQL::VirtualRow
- Sequel::SQL::Window
- Sequel::SQL::WindowFunction
- Sequel::SQL::Wrapper
- Sequel::SQLTime
- Sequel::SQLite
- Sequel::SQLite::Database
- Sequel::SQLite::DatabaseMethods
- Sequel::SQLite::Dataset
- Sequel::SQLite::Dataset::ArgumentMapper
- Sequel::SQLite::Dataset::BindArgumentMethods
- Sequel::SQLite::Dataset::PreparedStatementMethods
- Sequel::SQLite::DatasetMethods
- Sequel::Schema
- Sequel::Schema::AlterTableGenerator
- Sequel::Schema::CreateTableGenerator
- Sequel::Schema::Generator
- Sequel::SchemaCaching
- Sequel::SchemaDumper
- Sequel::SelectRemove
- Sequel::Sequel3DatasetMethods
- Sequel::SerializationFailure
- Sequel::ServerBlock
- Sequel::SetOverrides
- Sequel::ShardedSingleConnectionPool
- Sequel::ShardedThreadedConnectionPool
- Sequel::SimpleMigration
- Sequel::SingleConnectionPool
- Sequel::Swift
- Sequel::Swift::Database
- Sequel::Swift::Dataset
- Sequel::Swift::MySQL
- Sequel::Swift::MySQL::DatabaseMethods
- Sequel::Swift::MySQL::Dataset
- Sequel::Swift::Postgres
- Sequel::Swift::Postgres::DatabaseMethods
- Sequel::Swift::SQLite
- Sequel::Swift::SQLite::DatabaseMethods
- Sequel::Swift::SQLite::Dataset
- Sequel::ThreadLocalTimezones
- Sequel::ThreadedConnectionPool
- Sequel::ThreadedServerBlock
- Sequel::TimestampMigrator
- Sequel::Timezones
- Sequel::TinyTDS
- Sequel::TinyTDS::Database
- Sequel::TinyTDS::Dataset
- Sequel::TinyTDS::Dataset::ArgumentMapper
- Sequel::TinyTDS::Dataset::PreparedStatementMethods
- Sequel::ToDot
- Sequel::ToDot::DatasetMethods
- Sequel::UnbindDuplicate
- Sequel::Unbinder
- Sequel::UndefinedAssociation
- Sequel::UniqueConstraintViolation
- Sequel::UnthreadedServerBlock
- Sequel::ValidationFailed
- String
- String::Inflections
- Array
- FalseClass
- Hash
- NilClass
- Numeric
- Object
- PGconn
- PGresult
- Range
- Symbol
- TrueClass

No matching classes.

# Sequel for ActiveRecord Users

This guide is aimed at helping ActiveRecord users transition to Sequel. It assumes the user is familiar with ActiveRecord 2, but if you are familiar with a newer ActiveRecord version, the transition should be even easier.

## Introduction

Both Sequel and ActiveRecord use the active record pattern of database access, where model instances are objects that wrap a row in a database table or view, encapsulating the database access, and adding domain logic on that data. Just like ActiveRecord, Sequel supports both associations and inheritance, though Sequel does so in a more flexible manner than ActiveRecord.

Let's quickly run through the ActiveRecord README and show how it applies to Sequel.

## Automatic Mapping

Just like ActiveRecord, Sequel maps classes to tables and automatically creates accessor methods for the columns in the table, so if you have an albums table with a primary key named "id" and a string/varchar column named "name", the minimal model class is:

    class Album < Sequel::Model
    end

Sequel will autogenerate the column accessors, so you can do:

    album = Album.new
    album.name = 'RF'

If the table name for the class doesn't match the default one Sequel will choose, you can specify it manually:

    class Album < Sequel::Model(:records)
    end

## Associations

Sequel supports most of the same association types as ActiveRecord, but it uses names that reflect the database relationships instead of ones that imply ownership:

    class Album < Sequel::Model
      many_to_one :artist
      one_to_many :tracks
      many_to_many :tags
    end

## Compositions

Sequel's `composition` plugin allows you to easily create accessor methods that are composed of one or more of the database's columns, similar to ActiveRecord's `composed_of`:

    class Artist < Sequel::Model
      plugin :composition
      composition :address, :mapping=>[:street, :city, :state, :zip]
    end

## Validations

Sequel's `validation_class_methods` plugin is modeled directly on ActiveRecord's validations, but the recommended approach is to use the `validation_helpers` plugin inside a `validate` instance method:

    class Album < Sequel::Model
      plugin :validation_helpers

      def validate
        super
        validates_presence [:name, :copies_sold]
        validates_unique [:name, :artist_id]
      end
    end

## Hooks/Callbacks

Sequel's `hook_class_methods` plugin is modeled directly on ActiveRecord's callbacks, but the recommended approach is to define your hooks/callbacks as instance methods:

    class Album < Sequel::Model
      def before_create
        self.copies_sold ||= 0
        super
      end

      def after_update
        super
        AuditLog.create(:log=>"Updated Album #{id}")
      end
    end

Observers can be implemented completely by hooks, so Sequel doesn't offer a separate observer class.

## Inheritance

Sequel supports both single table inheritance and class table inheritance using plugins:

    class Employee < Sequel::Model
      plugin :single_table_inheritance, :class_name_column
      # or
      plugin :class_table_inheritance
    end

    class Staff < Employee
    end

    class Manager < Employee
    end

    class Executive < Manager
    end

## Transactions

Sequel supports transactions via the Database object (we recommend using the DB constant for single database applications):

    DB.transaction do
      album.artist.num_albums -= 1
      album.artist.save
      album.delete
    end

For model classes, you can always access the database via `db`:

    Album.db.transaction do
      album.artist.num_albums -= 1
      album.artist.save
      album.delete
    end

## Reflection

Just like ActiveRecord, Sequel has full reflection support for columns, associations, and many other things:

    Album.columns # => [:id, :name, :artist_id, :copies_sold]
    reflection = Album.association_reflection(:artist)
    reflection[:type] == :many_to_one

## Direct Manipulation

Just like ActiveRecord, Sequel doesn't use sessions, it lets you modify objects and have them be saved inside the call to `save`:

    album = Album[1234]
    # modify album
    album.save

## Database Abstraction

Sequel supports far more database abstractions than ActiveRecord, and setting up the database connection is easy:

    DB = Sequel.sqlite # memory database
    DB = Sequel.connect('postgres://user:pass@host/database') # connection string
    DB = Sequel.connect(:adapter=>'postgres', :user=>'?', :password=>'?',
      :host=>'?', :database=>'?') # option hash

## Logging

Sequel supports logging of all database queries by allowing multiple loggers for each database:

    DB.loggers << Logger.new($stdout)

## Migrations

Sequel supports migrations and has a migrator similar to ActiveRecord:

    Sequel.migration do
      change do
        create_table(:albums) do
          primary_key :id
          String :name
        end
      end
    end

## Differences

By now, you should have the idea that Sequel supports most things that ActiveRecord supports. The rest of this guide is going to go over how Sequel differs from ActiveRecord in terms of operation.

### Method Chaining

Unlike ActiveRecord 2 (and similar to ActiveRecord 3+), Sequel uses method chains on datasets for retrieving objects, so instead of:

    Album.find(:all, :conditions=>['name > ? AND artist_id = ?', 'RF', 1],
      :order=>'copies_sold', :select=>'id, name')

Sequel uses:

    Album.where{name > 'RF'}.where(:artist_id=>1).order(:copies_sold).
      select(:id, :name).all

Note that the records aren't retrieved until `all` is called.

ActiveRecord 3 adopts this method chaining approach, so if you are familiar with it, it should be even easier to transition to Sequel.

### No Need for SQL String Fragments

Like the example above, most ActiveRecord code uses SQL string fragments. With Sequel, you rarely need to. Sequel's DSL allows you to create complex queries without ever specifying SQL string fragments (called literal strings in Sequel).

If you want to use SQL string fragments, Sequel makes it easy by using the `Sequel.lit` method:

    Album.select(Sequel.lit('id, name'))

This usage is not encouraged, though. The recommended way is to use symbols to represent the columns:

    Album.select(:id, :name)

Sequel keeps datasets in an abstract format, allowing for powerful capabilities. For example, let's say you wanted to join to the artists table. Sequel can automatically qualify all references in the current dataset, so that it can be safely joined:

    Album.select(:id, :name).qualify.join(:artists, :id=>:artist_id)

This isn't possible when you use an SQL string fragment. Another case where using an SQL string fragment hurts you is when the SQL syntax cannot handle all cases:

    Album.filter('id NOT IN ?', ids_array)

That will work fine if `ids_array` is not empty, but will not work correctly if it is empty. With Sequel, you do:

    Album.exclude(:id=>ids_array)

That will handle cases where `ids_array` is empty correctly.

A third reason to not use SQL string fragments is database independence. For example, if you want a case insensitive search that works on both PostgreSQL and MySQL, the following won't work:

    Album.filter('name LIKE ?', 'A%')

This is because LIKE is case sensitive on PostgreSQL, but case insensitive on MySQL. With Sequel, you would do:

    Album.filter(Sequel.ilike(:name, 'A%'))

This will do a case insensitive search on both databases. If you want a case sensitive search on both, you can use `like` instead of `ilike`.

String concatenation is a similar area, where MySQL and PostgreSQL handle things differently. With Sequel, the same code can work on both databases:

    Album.select(Sequel.join([:name, ' - Name']))

## Flexible Overriding

Unlike ActiveRecord 2, which forces you to alias methods if you want to override them, with Sequel you just override the methods and call super:

    class Sequel::Model
      def after_update
        super
        AuditLog.create(:log=>"#{model.name} with primary key #{pk} updated")
      end
    end

With that code, you have enabled auditing for all model object updates.

Let's say you want to override accessor methods. In Sequel, instead of using `read_attribute` and `write_attribute`, you can just call super:

    class Track < Sequel::Model
      # database holds length in integer seconds,
      # but you want it in minutes as a float

      def length=(minutes)
        super((minutes*60).to_i)
      end

      def length
        super/60.0
      end
    end

You can override almost all model class or instance methods this way, just remember to call `super`.

## `method_missing` Missing

Sequel does not use `method_missing` unless it's required that the object respond to potentially any method. Neither `Sequel::Model` nor `Sequel::Dataset` nor `Sequel::Database` implement `method_missing` at either a class or instance level. So if you call `methods`, you can see which methods are available, and if they aren't listed, then the object won't respond to them. Among other things, this means Sequel does not support dynamic finders. So instead of:

    Album.find_or_create_by_name("RF")

You just use:

    Album.find_or_create(:name=>"RF")

At the instance level, this means that if you select columns that aren't in the models table, you need to use `Model#[]` to access them:

    album = Album.join(:artist, :id=>:artist_id).
     select(:albums__id, :albums__name, :artists__name___artist).first
     # SELECT albums.id, albums.name, artists.name AS artist

    album.artist # Error!
    album[:artist] # Works

## Associations

Sequel associations are similar to ActiveRecord associations in some ways, and much different in others. Sequel provides four association creation methods that map to ActiveRecord's associations:

ActiveRecord | Sequel
`belongs_to` | `many_to_one`
`has_one` | `one_to_one`
`has_many` | `one_to_many`
`has_and_belongs_to_many` | `many_to_many`

Like ActiveRecord, when you create an association in Sequel, it creates an instance method with the same name that returns either the matching object or nil for the `*_to_one` associations, or an array of matching objects for the `*_to_many` associations.

Updating `*_to_many` associations is very different, however. ActiveRecord makes the association method returns an association proxy that looks like an array, but has a bunch of added methods to manipulate the associated records. Sequel uses instance methods on the object instead of a proxy to modify the association. Here's a basic example:

    Artist.one_to_many :albums
    Album.many_to_one :artist

    artist = Artist[1]
    album = Album[1]

    artist.albums # array of albums
    album.artist # Artist instance or nil

    artist.add_album(album) # associate album to artist
    artist.remove_album(album) # disassociate album from artist
    artist.remove_all_albums # disassociate all albums from artist

Sequel doesn't have a `has_many :through` association, instead you can use a `many_to_many` association in most cases. Sequel ships with a `many_through_many` plugin that allows you to set up a many to many relationship through an arbitrary number of join tables.

Sequel doesn't come with support for polymorphic associations. Using polymorphic associations is generally bad from a database design perspective, as it violates referential integrity. If you have an old database and must have polymorphic associations, there is an external `sequel_polymorphic` plugin that can handle them, just by using the standard association options provided by Sequel.

Sequel doesn't directly support creating a bunch of associated objects and delaying saving them to the database until the main object is saved, like you can with the `association.build` methods in ActiveRecord. You can use +before_save or `after_save` hooks, or the `nested_attributes` or `instance_hooks` plugins to get similar support.

Sequel supports the same basic association hooks/callbacks as ActiveRecord. It also supports `:after_load`, which is run after the associated objects are loaded. For `*_to_one` associations, it supports `before_set` and `after_set` hooks, since a setter method is used instead of an add/remove method pair.

If you pass a block to an association method, it's used to return a modified dataset used for the association, instead of to create an association extension:

    Artist.one_to_many :gold_albums, :class=>:Album do |ds|
      ds.where{copies_sold > 500000}
    end

If you want to create an association extension, you can use the `:extend` association option with a module, which ActiveRecord also supports. In Sequel, the extensions are applied to the association dataset, not to the array of associated objects. You can access the association dataset using the `association_dataset` method:

    artist.albums_dataset
    album.artist_dataset

Association datasets are just like any other Sequel dataset, in that you can filter them and manipulate them further:

    gold_albums = artist.albums_dataset.where{copies_sold > 500000}.order(:name).all

Sequel caches associated objects similarly to ActiveRecord, and you can skip the cache by passing `true` to the association method, just like ActiveRecord.

### Eager Loading

ActiveRecord 2 tries to guess whether to use preloading or JOINs for eager loading by scanning the SQL string fragments you provide for table names. This is error prone and Sequel avoids it by giving you separate methods. In Sequel, `eager` is used for preloading and `eager_graph` is used for JOINs. Both have the same API:

    Artist.eager(:albums=>[:tags, :tracks])
    Album.eager_graph(:artist, :tracks)

With either way of eager loading, you must call `all` to retrieve all records at once. You cannot use `each`, `map`, or one of the other Enumerable methods. Just like `each`, `all` takes a block that iterates over the records:

    Artist.eager(:albums=>[:tags, :tracks]).each{|a| ...} # No cookie
    Artist.eager(:albums=>[:tags, :tracks]).all{|a| ...} # Cookie

Like ActiveRecord, Sequel supports cascading of eager loading for both methods of eager loading.

Unlike ActiveRecord, Sequel allows you to eager load custom associations using the `:eager_loader` and `:eager_grapher` association options. See the Advanced Associations guide for more details.

Table aliasing when eager loading via `eager_graph` is different in Sequel than ActiveRecord. Sequel will always attempt to use the association name, not the table name, for any associations. If the association name has already been used, Sequel will append _N to it, where N starts at 0 and increases by 1. For example, for a self referential association:

    class Node < Sequel::Model
      many_to_one :parent, :class=>self
      one_to_many :children, :class=>self, :key=>:parent_id
    end

    Node.eager_graph(:parent=>:parent, :children=>{:children=>:children}).all

    # SELECT nodes.id, nodes.parent_id, -- main table
    #  parent.id AS parent_id_0, parent.parent_id AS parent_parent_id, -- parent
    #  parent_0.id AS parent_0_id, parent_0.parent_id AS parent_0_parent_id, -- grandparent
    #  children.id AS children_id, children.parent_id AS children_parent_id, -- children
    #  children_0.id AS children_0_id, children_0.parent_id AS children_0_parent_id, -- grandchildren
    #  children_1.id AS children_1_id, children_1.parent_id AS children_1_parent_id -- great grandchidren
    # FROM nodes -- main table
    #  LEFT OUTER JOIN nodes AS parent ON (parent.id = nodes.parent_id) -- parent
    #  LEFT OUTER JOIN nodes AS parent_0 ON (parent_0.id = parent.parent_id) -- grandparent
    #  LEFT OUTER JOIN nodes AS children ON (children.parent_id = nodes.id) -- children
    #  LEFT OUTER JOIN nodes AS children_0 ON (children_0.parent_id = children.id) -- grandchildren
    #  LEFT OUTER JOIN nodes AS children_1 ON (children_1.parent_id = children_0.id) -- great grandchildren

You can specify aliases on a per join basis, too:

    Node.eager_graph(:parent=>Sequel.as(:parent, :grandparent),
      :children=>{Sequel.as(:children, :grandchildren)=>Sequel.as(:children, :great_grandchildren)}).all

    # SELECT nodes.id, nodes.parent_id,
    #  parent.id AS parent_id_0, parent.parent_id AS parent_parent_id,
    #  grandparent.id AS grandparent_id, grandparent.parent_id AS grandparent_parent_id,
    #  children.id AS children_id, children.parent_id AS children_parent_id,
    #  grandchildren.id AS grandchildren_id, grandchildren.parent_id AS grandchildren_parent_id,
    # great_grandchildren.id AS great_grandchildren_id, great_grandchildren.parent_id AS great_grandchildren_parent_id
    # FROM nodes
    #  LEFT OUTER JOIN nodes AS parent ON (parent.id = nodes.parent_id)
    #  LEFT OUTER JOIN nodes AS grandparent ON (grandparent.id = parent.parent_id)
    #  LEFT OUTER JOIN nodes AS children ON (children.parent_id = nodes.id)
    #  LEFT OUTER JOIN nodes AS grandchildren ON (grandchildren.parent_id = children.id)
    #  LEFT OUTER JOIN nodes AS great_grandchildren ON (great_grandchildren.parent_id = grandchildren.id)

### Options

Sequel supports many more association options than ActiveRecord, but here's a mapping of ActiveRecord association options to Sequel association options. Note that when you specify columns in Sequel, you use symbols, not strings. Where ActiveRecord would use an SQL string fragment with embedded commas for multiple columns, Sequel would use an array of column symbols.

### Shared options

These options are shared by more than one ActiveRecord association.

ActiveRecord option | Sequel option
`:class_name` | `:class`
`:conditions` | `:conditions`
`:select` | `:select`
`:order` | `:order`
`:extend` | `:extend`
`:limit` | `:limit`
`:offset` | `:limit` with an array with the second element being the offset
`:uniq` | `:uniq`
`:validate` | `:validate`
`:dependent` | The `associations_dependencies` plugin
`:polymorphic`, `:as`, `:source_type` | The `sequel_polymorphic` external plugin
`:include` | `:eager`, `:eager_graph`
`:readonly` | No equivalent, the Sequel `:read_only` option just means the modification methods are not created (it makes the association read only, not records retrieved through the association)
`:through`, `:source` | Use a `many_to_many` association, or the `many_through_many` plugin
`:touch` | The `touch` plugin
`:autosave` | A `before_save` or `after_save` hook
`:finder_sql` | `:dataset` to set a custom dataset
`:counter_sql` | No direct equivalent, but a count on the dataset will use the custom dataset specified by `:dataset`
`:group` | Use the association block to add the group to the dataset
`:having` | Use the association block to add the having to the dataset

### `belongs_to`

`belongs_to` option | `many_to_one` option
`:foreign_key` | `:key`
`:primary_key` | `:primary_key`
`:counter_cache` | No equivalent

### `has_one`, `has_many`

`has_one`, `has_many` option | `one_to_one`, `one_to_many` option
`:foreign_key` | `:key`

### `has_and_belongs_to_many`

`has_and_belongs_to_many` option | `many_to_many` option
`:foreign_key` | `:left_key`
`:association_foreign_key` | `:right_key`
`:join_table` | `:join_table`
`:delete_sql` | `:remover`
`:insert_sql` | `:adder`

## Validation Errors

If there are errors when validating an object in Sequel, they are stored in a `Sequel::Model::Errors` instance. It's mostly similar to `ActiveRecord::Errors`, so this section will just go over the differences.

`Sequel::Model::Errors` is a hash subclass where keys are usually column symbols (not required), and values are arrays of error messages. So if you have two error messages on the same column, `each` will only yield once, not twice.

The `add_on_blank`, `add_on_empty`, `add_to_base`, `each_full`, `generate_message`, `invalid?`, `on_base`, and `to_xml` methods don't exist. `[]` should not be used directly, instead you should use `on`.

You can think of `Sequel::Model::Errors` as a subset of `ActiveRecord::Errors` if you stick to `on`, `add`, and `full_messages`.

## Sequel Configuration Flags

Unlike ActiveRecord, Sequel's behavior depends on how you configure it. In Sequel, you can set flags at the global, class, and instance level that change the behavior of Sequel. Here's a brief description of the flags:

`raise_on_save_failure` | Whether to raise an error instead of returning nil on a failure to save/create/save_changes/etc due to a validation failure or a before_* hook returning false. By default, an error is raised, when this is set to false, nil is returned instead.
`raise_on_typecast_failure` | Whether to raise an error when unable to typecast data for a column (default: true). This should be set to false if you want to use validations to display nice error messages to the user (e.g. most web applications). You can use the `validates_schema_types` validation in connection with this option to check for typecast failures.
`require_modification` | Whether to raise an error if an UPDATE or DELETE query related to a model instance does not modify exactly 1 row. If set to false, Sequel will not check the number of rows modified (default: true if the database supports it).
`strict_param_setting` | Whether new/set/update and their variants should raise an error if an invalid key is used. A key is invalid if no setter method exists for that key or the access to the setter method is restricted (e.g. due to it being a primary key field). If set to false, silently skip any key where the setter method doesn't exist or access to it is restricted.
`typecast_empty_string_to_nil` | Whether to typecast the empty string (") to nil for columns that are not string or blob. In most cases the empty string would be the way to specify a NULL SQL value in string form (nil.to_s == "), and an empty string would not usually be typecast correctly for other types, so the default is true.
`typecast_on_assignment` | Whether to typecast attribute values on assignment (default: true). If set to false, no typecasting is done, so it will be left up to the database to typecast the value correctly.
`use_transactions` | Whether to use a transaction by default when saving/deleting records (default: true). If you are sending database queries in before or after hooks, you shouldn't change the default setting without a good reason.

## ActiveRecord Method to Sequel Method Mapping

This part of the guide will list Sequel equivalents for ActiveRecord methods, hopefully allowing you to convert your existing ActiveRecord code to Sequel code more easily.

### Class Methods with Significantly Different Behavior

#### `abstract_class`, `abstract_class=`, `abstract_class?`

With Sequel, these methods don't exist because it doesn't default to using single table inheritance in subclasses. ActiveRecord assumes that subclasses of Model classes use single table inheritance, and you have to set `abstract_class = true` to use an abstract class. In Sequel, you must use the `single_table_inheritance` or `class_table_inheritance` plugin to configure inheritance in the database.

#### `all`

In both Sequel and ActiveRecord, calling `all` will give you an array of all records. However, while in ActiveRecord you pass options to `all` to filter or order the results, in Sequel you call dataset methods to filter or order the results, and then end the method chain with a call to `all` to return the records.

#### `column_names`

Sequel uses symbols for columns, so the `columns` method returns an array of symbols. If you want an array of strings:

    Album.columns.map{|x| x.to_s}

#### `columns`

`Sequel::Model.columns` returns an array of column name symbols. The closest similar thing would be to get the database schema hash for each column:

    Album.columns.map{|x| Album.db_schema[x]}

#### `composed_of`

As mentioned earlier, Sequel uses the `composition` plugin for this:

    class Artist < Sequel::Model
      plugin :composition
      composition :address, :mapping=>[:street, :city, :state, :zip]
    end

#### `connected?`

`Sequel::Model` raises an exception if you haven't instantiated a `Sequel::Database` object before loading the model class. However, if you want to test the connection to the database:

    Sequel::Model.db.test_connection

Note that `test_connection` will return true if a connection can be made, but will probably raise an exception if it cannot be made.

#### `connection`

Sequel only uses connections for the minimum amount of time necessary, checking them out to do a query, and returning them as soon as the query finishes. If you do want direct access to the connection object:

    Sequel::Model.db.synchronize do |connection|
      ...
    end

Note that the connection is yielded to the block, and the block ensures it is returned to the pool. Sequel doesn't have a method that returns a connection, since that would check it out with no ability to ensure it is returned to the pool.

#### `count_by_sql`

You can call `with_sql` to set the SQL to use, and the `single_value` to retrieve the result.

    Album.with_sql("SELECT COUNT(*) ...").single_value

#### `delete`, `delete_all`

You probably want to filter first, then call `delete`:

    Album.where(:id=>id).delete
    Album.where("artist_id = ?", 5).delete

If you really want to delete all rows in the table,call `delete` on the Model's dataset:

    Album.dataset.delete

#### `destroy`, `destroy_all`

Similar to `delete`, you filter first, then `destroy`:

    Album.where(:id=>id).destroy
    Album.where("artist_id = ?", 5).destroy

If you really want to destroy all rows in the table,call `destroy` on the Model's dataset:

    Album.dataset.destroy

#### `establish_connection`

If you want to use a specific `Sequel::Database` object, you can use `db=`:

    BACKUP_DB = Sequel.connect(...)
    Album.db = BACKUP_DB

If you want a specific dataset in that database, you can use `set_dataset` or `dataset=`:

    Album.set_dataset BACKUP_DB[:albums]
    Album.dataset = BACKUP_DB[:albums]

#### `exists?`

You need to filter the dataset first, then call `empty?` and invert the result:

    !Album.where(:id=>1).empty?

#### `find`

ActiveRecord's `find` can be used for a lot of different things. If you are trying to find a single object given a primary key:

    Album[1]

Note that Sequel returns nil if no record is found, it doesn't raise an exception. To raise an exception if no record is found:

    Album.with_pk!(1)

If you want to find multiple objects using an array of primary keys:

    Album.where(:id=>[1, 2, 3]).all

If you are using `find(:first, ...)`, you use a method chain instead of passing the options, and end it with `first`:

    Album.where(:artist_id=>1).order(:name).first

If you are using `find(:last, ...)`, you need to specify an order in Sequel, but the same method chain approach is used, which you end with `last`:

    Album.where(:artist_id=>1).order(:name).last
    # You could also do:
    Album.where(:artist_id=>1).reverse_order(:name).first

If you are using `find(:all, ...)`, you use a method chain instead of passing the options, and end it with `all`:

    Album.where(:artist_id=>1).order(:name).all

Here's a mapping of ActiveRecord `find` options to `Sequel::Dataset` methods:

:conditions | filter, where
:order | order
:group | group
:limit | limit
:offset | limit # second entry in limit array
:joins | join, left_join, etc. # many other join methods
:include | eager, eager_graph # eager does preloading, eager_graph does JOINs
:select | select
:from | from
:read_only | # No Sequel equivalent
:lock | for_update, lock_style

#### `find_by_sql`

Similar to `count_by_sql`, you use `with_sql`, followed by `all`:

    Album.with_sql("SELECT * FROM albums WHERE ...").all

#### `first`

Just like with `find(:first, ...)`, you use a method chain instead of passing the options, and end it with `first`:

    Album.where(:artist_id=>1).order(:name).first

#### `last`

Just like with `find(:last, ...)`, you use a method chain instead of passing the options, make sure it includes an order, and end it with `last`:

    Album.where(:artist_id=>1).order(:name).last

#### `named_scope`

For a pure filter, you can use `subset`:

    Album.subset(:debut, :position => 1)
    Album.subset(:gold){copies_sold > 500000}

For anything more complex, you can use `dataset_module`:

    Album.dataset_module do
      def by_artist(artist_id)
        where(:artist_id=>artist_id)
      end

      def by_release_date
        order(:release_date)
      end
    end

#### `reset_column_information`

If you want to completely reload the schema for the table:

    Album.instance_variable_set(:@db_schema, nil)
    Album.send(:get_db_schema, true)

#### `serialize`, `seralized_attributes`

Sequel ships with a `serialization` plugin that you can use.

    class Album < Sequel::Model
      plugin :serialization, :json, :permissions
    end

For `serialized_attributes`, you can use `serialization_map`, which is also a hash, but keys are column symbols and values are callable objects used to serialize the values.

#### `set_inheritance_column`

This is something that must be specified when you are loading the `single_table_inheritance` plugin:

    class Album < Sequel::Model
      plugin :single_table_inheritance, :column
    end

#### `set_sequence_name`

Sequel will usually auto discover the sequence to use. However, on Oracle this should be specified by making sure the model's dataset includes a sequence:

    class Album < Sequel::Model(ORACLE_DB[:albums].sequence('albums_seq'))
    end

#### `table_exists?`

This is a `Sequel::Database` method:

    Album.db.table_exists?(Album.table_name)

With the `schema` plugin, you can use it directly:

    Album.plugin :schema
    Album.table_exists?

#### `transaction`

As mentioned earlier, `transaction` is a database method in Sequel, which you can access via the `db` method:

    Album.db.transaction{}

#### `update`, `update_all`

Just like `delete` and `destroy`, you filter first, then `update`:

    Album.where(:id=>id).update(:name=>'RF')
    Album.where("artist_id = ?", 5).update(:copies_sold=>0)

Likewise, to update all rows in the model:

    Album.dataset.update(:name=>'RF')

Note that `update` in that case will operate on a dataset, so it won't run model validations or hooks. If you want those run:

    Album[id].update(:name=>'RF')
    Album.where("artist_id = ?", 5).all{|a| a.update(:copies_sold=>0)}

#### `with_scope`

Sequel works a little differently than with_scope. Instead of using nested blocks, you just use a cleaner method chain. `with_scope` is often used as an around_filter or similar construct, where in Sequel, you would just need to assign to a dataset in a before filter, and use that dataset in the action.

### Class Methods with Roughly the Same Behavior

Note that Sequel uses symbols almost everywhere to represent columns, while ActiveRecord often returns columns as strings.

ActiveRecord Method | Sequel Method
`attr_accessible` | `set_allowed_columns`
`attr_protected` | `set_restricted_columns`
`average` | `avg`
`belongs_to` | `many_to_one`
`columns_hash` | `db_schema`
`count` | `count`
`changed` | `changed_columns`
`create` | `create`
`has_and_belongs_to_many` | `many_to_many`
`has_one` | `one_to_one`
`has_many` | `one_to_many`
`inheritance_column` | `sti_key`
`inspect` | `inspect`
`maximum` | `max`
`minimum` | `min`
`new` | `new`
`primary_key` | `primary_key`
`respond_to?` | `respond_to?`
`set_primary_key` | `set_primary_key`
`sum` | `sum`
`table_name` | `table_name`
`unscoped` | `unfiltered`

### Class Methods without an Equivalent

ActiveRecord Method | Notes, Workarounds
`accepts_nested_attributes_for` | Use the `nested_attributes` plugin
`attr_readonly` | Don't update the columns (duh!), or add a before_update hook that deletes them from the values hash
`attribute_method_suffix` | No equivalent
`alias_attribute_with_dirty` | No equivalent
`base_class` | Not needed internally, you can probably use `sti_dataset.model` if you are using single table inheritance
`benchmark` | Just use the `benchmark` library from ruby's stdlib
`calculate` | No direct equivalent, just build the query manually and execute it
`cache` | No equivalent
`cache_attribute?` | No equivalent
`cache_attributes` | No equivalent
`cached_attributes` | No equivalent
`changed?` | `changed_columns.include?(column)`
`changes` | No equivalent
`clear_active_connections!` | Sequel doesn't leak connections like ActiveRecord, so you don't need to worry about this
`clear_reloadable_connections!` | Sequel doesn't leak connections like ActiveRecord, so you don't need to worry about this
`content_columns` | Not needed internally, you can probably do `Album.columns.map{|x| x.to_s}.delete_if{|x| x == Album.primary_key || x =~ /_(id|count)\z/}`
`decrement_counter` | `Album.where(:id=>:id).update(:counter_name=>:counter_name - 1)`
`define_attribute_methods`, `define_read_methods` | `def_column_accessor(*columns)`, a private method
`descends_from_active_record?` | Not needed internally, if using single table inheritance, `Album.sti_dataset.model == Album`
`find_each`, `find_in_batches` | Use the `pagination` extension
`generated_methods?` | No equivalent
`increment_counter` | `Album.where(:id=>:id).update(:counter_name=>:counter_name + 1)`
`instance_method_already_implemented?` | No equivalent, Sequel does not create column accessors that override other methods, it just skips them.
`match_attribute_method?` | No equivalent
`readonly_attributes` | No equivalent
`remove_connection` | Not necessary in Sequel. If you want to disconnect an existing connection: `Album.db.disconnect`
`require_mysql` | A public method, really?
`silence` | No equivalent. Because the logger is handled at the `Sequel::Database` level, there is no thread-safe way to turn it off for specific blocks.
`scopes` | No equivalent
`sti_name` | No equivalent.
`update_counters` | `Album.where(:id=>:id).update(:counter_name=>:counter_name + 1, :other_counter=>:other_counter - 1)`
`uncached` | No equivalent

### Instance Methods with Significantly Different Behavior

#### `attribute_names`

`keys` returns the columns as unsorted symbols, so:

    album.keys.map{|x| x.to_s}.sort

#### `becomes`

Assuming the record already exists in the database:

    gold_album = GoldAlbum[1]
    album = Album.load(gold_album.values)

If it is a new record:

    gold_album = GoldAlbum.new(:name=>'a')
    album = Album.new
    album.send(:set_values, gold_album.values)

#### `column_for_attribute`

You can access this through the `db_schema` hash:

    album.db_schema[:column]

#### `connection`

Just like in the class method, you have to access it through the database:

    album.db.synchronize do |connection|
    end

#### `decrement`, `increment`

You can just modify the values hash directly:

    album.values[:column] ||= 0
    album.values[:column] -= 1 # or += 1 for increment

#### `decrement!`, `increment!`

Assuming you want the full behavior of saving just one column without validating:

    album.values[:column] ||= 0
    album.values[:column] -= 1 # or += 1 for increment!
    album.save(:columns=>[:column], :validate=>false)

#### `has_attribute?`

You have to check the values hash:

    album.values.has_key?(:column)

#### `invalid?`

You can use `unless valid?` or `!valid?`.

#### `save`, `save!`, `save_with_validation`, `save_with_validation!`

Sequel defaults to raising exceptions when `save` fails, but this is configurable behavior by setting the `raise_on_save_failure` flag on the class or instance:

    album.raise_on_save_failure = true
    album.save # raise exception if failure
    album.raise_on_save_failure = false
    album.save # return nil if failure

You can pass the `:validate=>false` option to not validate the object when saving.

#### `toggle`, `toggle`

No equivalent, but very easy to add:

    album.column = !album.column

If you want to save just that column:

    album.save(:columns=>[:column], :validate=>false)

#### `transaction`

Just like in the class, you can access the transaction method through the `db`:

    album.db.transaction{}

#### `update_attribute`

To only set and save a specific column:

    album.set(:column => value)
    album.save(:columns=>[:column], :validate=>false)

#### `update_attributes`, `update_attributes!`

These would both use `update`, but see the notes on the `raise_on_save_failure` flag:

    album.update(:column1=>value1, :column2=>value2)

### Instance Methods with Roughly the Same Behavior

Note that Sequel uses symbols almost everywhere to represent columns, while ActiveRecord often returns columns as strings.

ActiveRecord Method | Sequel Method
`==` | `===`, `==` compares by all values, not just id
`[]` | `[]`
`[]=` | `[]=`
`after_create` | `after_create`
`after_destroy` | `after_destroy`
`after_save` | `after_save`
`after_update` | `after_update`
`after_validation` | `after_validation`
`attributes` | `values`
`attributes=` | `set`
`before_create` | `before_create`
`before_destroy` | `before_destroy`
`before_save` | `before_save`
`before_update` | `before_update`
`before_validation` | `before_validation`
`cache_key` | `cache_key`, if using the `caching` plugin
`destroy` | `destroy`
`eql?` | `===`
`errors` | `errors`
`freeze` | `freeze`
`frozen?` | `frozen?`
`hash` | `hash`
`id` | `pk`
`inspect` | `inspect`
`lock!` | `lock!`
`new_record?` | `new?`
`reload_with_autosave_associations` | `reload`
`to_param` | `to_param`, if using the `active_model` plugin
`touch` | `touch`, if using the `touch` plugin
`valid?` | `valid?`

### Instance Methods without an Equivalent

ActiveRecord Method | Notes, Workarounds
`after_validation_on_create`, `after_validation_on_update` | Use `after_validation` and `if new?` or `unless new?`
`as_json`, `from_json`, `to_json` | Use the `json_serializer` plugin
`from_xml`, `to_xml` | Use the `xml_serializer` plugin
`attribute_for_inspect` | `album[:column].inspect`
`attribute_present?` | `!album[:column].blank?` if using the `blank` extension
`attributes_before_type_cast` | Sequel typecasts at a low level, so model objects never see values before they are type cast
`before_validation_on_create`, `before_validation_on_update` | Use `before_validation` and `if new?` or `unless new?`
`id=` | Sequel doesn't have a special primary key setter method, but you can use: `album.send("#{Album.primary_key}=", value)`
`mark_for_destruction`, `marked_for_destruction?` | Use a `before_save` or `after_save` hook or the `instance_hooks` plugin
`readonly!` | No equivalent
`readonly?` | No equivalent
`rollback_active_record_state!` | No equivalent
`with_transaction_returning_status` | No equivalent

[Validate]

Generated with the Darkfish Rdoc Generator 2.