### Home Classes Methods

### In Files

- lib/sequel/timezones.rb
- lib/sequel/database/dataset_defaults.rb
- lib/sequel/database/schema_generator.rb
- lib/sequel/database/dataset.rb
- lib/sequel/database/connecting.rb
- lib/sequel/database/query.rb
- lib/sequel/database/logging.rb
- lib/sequel/database/schema_methods.rb
- lib/sequel/database/misc.rb
- lib/sequel/sql.rb
- lib/sequel/plugins/serialization.rb
- lib/sequel/plugins/update_primary_key.rb
- lib/sequel/plugins/schema.rb
- lib/sequel/plugins/association_proxies.rb
- lib/sequel/plugins/lazy_attributes.rb
- lib/sequel/plugins/optimistic_locking.rb
- lib/sequel/plugins/single_table_inheritance.rb
- lib/sequel/plugins/composition.rb
- lib/sequel/plugins/active_model.rb
- lib/sequel/plugins/typecast_on_load.rb
- lib/sequel/plugins/instance_hooks.rb
- lib/sequel/plugins/instance_filters.rb
- lib/sequel/plugins/touch.rb
- lib/sequel/plugins/association_pks.rb
- lib/sequel/plugins/nested_attributes.rb
- lib/sequel/plugins/skip_create_refresh.rb
- lib/sequel/plugins/many_through_many.rb
- lib/sequel/plugins/caching.rb
- lib/sequel/plugins/class_table_inheritance.rb
- lib/sequel/plugins/identity_map.rb
- lib/sequel/plugins/hook_class_methods.rb
- lib/sequel/plugins/rcte_tree.rb
- lib/sequel/plugins/string_stripper.rb
- lib/sequel/plugins/timestamps.rb
- lib/sequel/plugins/subclasses.rb
- lib/sequel/plugins/tactical_eager_loading.rb
- lib/sequel/plugins/validation_helpers.rb
- lib/sequel/plugins/boolean_readers.rb
- lib/sequel/plugins/force_encoding.rb
- lib/sequel/plugins/validation_class_methods.rb
- lib/sequel/plugins/sharding.rb
- lib/sequel/plugins/association_dependencies.rb
- lib/sequel/dataset/sql.rb
- lib/sequel/dataset/prepared_statements.rb
- lib/sequel/dataset/features.rb
- lib/sequel/dataset/actions.rb
- lib/sequel/dataset/mutation.rb
- lib/sequel/dataset/graph.rb
- lib/sequel/dataset/query.rb
- lib/sequel/dataset/misc.rb
- lib/sequel/exceptions.rb
- lib/sequel/model.rb
- lib/sequel/dataset.rb
- lib/sequel/extensions/thread_local_timezones.rb
- lib/sequel/extensions/sql_expr.rb
- lib/sequel/extensions/pagination.rb
- lib/sequel/extensions/migration.rb
- lib/sequel/extensions/named_timezones.rb
- lib/sequel/extensions/looser_typecasting.rb
- lib/sequel/extensions/schema_dumper.rb
- lib/sequel/extensions/pretty_table.rb
- lib/sequel/extensions/query.rb
- lib/sequel/core.rb
- lib/sequel/adapters/ado/mssql.rb
- lib/sequel/adapters/mysql.rb
- lib/sequel/adapters/openbase.rb
- lib/sequel/adapters/oracle.rb
- lib/sequel/adapters/do/mysql.rb
- lib/sequel/adapters/do/postgres.rb
- lib/sequel/adapters/do/sqlite.rb
- lib/sequel/adapters/do.rb
- lib/sequel/adapters/postgres.rb
- lib/sequel/adapters/amalgalite.rb
- lib/sequel/adapters/utils/stored_procedures.rb
- lib/sequel/adapters/shared/mysql.rb
- lib/sequel/adapters/shared/oracle.rb
- lib/sequel/adapters/shared/progress.rb
- lib/sequel/adapters/shared/postgres.rb
- lib/sequel/adapters/shared/sqlite.rb
- lib/sequel/adapters/shared/mssql.rb
- lib/sequel/adapters/db2.rb
- lib/sequel/adapters/jdbc/as400.rb
- lib/sequel/adapters/jdbc/mysql.rb
- lib/sequel/adapters/jdbc/oracle.rb
- lib/sequel/adapters/jdbc/sqlite.rb
- lib/sequel/adapters/jdbc/mssql.rb
- lib/sequel/adapters/jdbc/postgresql.rb
- lib/sequel/adapters/jdbc/h2.rb
- lib/sequel/adapters/jdbc.rb
- lib/sequel/adapters/informix.rb
- lib/sequel/adapters/sqlite.rb
- lib/sequel/adapters/odbc/mssql.rb
- lib/sequel/adapters/ado.rb
- lib/sequel/adapters/firebird.rb
- lib/sequel/adapters/odbc.rb
- lib/sequel/adapters/dbi.rb
- lib/sequel/metaprogramming.rb
- lib/sequel/model/base.rb
- lib/sequel/model/errors.rb
- lib/sequel/model/exceptions.rb
- lib/sequel/model/associations.rb
- lib/sequel/model/inflections.rb
- lib/sequel/model/plugins.rb
- lib/sequel/model/default_inflections.rb
- lib/sequel/database.rb
- lib/sequel/version.rb

### Namespace

- MODULE Sequel::ADO
- MODULE Sequel::Amalgalite
- MODULE Sequel::DB2
- MODULE Sequel::DBI
- MODULE Sequel::DataObjects
- MODULE Sequel::Firebird
- MODULE Sequel::Inflections
- MODULE Sequel::Informix
- MODULE Sequel::JDBC
- MODULE Sequel::LooserTypecasting
- MODULE Sequel::MSSQL
- MODULE Sequel::Metaprogramming
- MODULE Sequel::MySQL
- MODULE Sequel::NamedTimezones
- MODULE Sequel::ODBC
- MODULE Sequel::OpenBase
- MODULE Sequel::Oracle
- MODULE Sequel::Plugins
- MODULE Sequel::Postgres
- MODULE Sequel::PrettyTable
- MODULE Sequel::Progress
- MODULE Sequel::SQL
- MODULE Sequel::SQLite
- MODULE Sequel::Schema
- MODULE Sequel::ThreadLocalTimezones
- MODULE Sequel::Timezones
- CLASS Sequel::AdapterNotFound
- CLASS Sequel::BasicObject
- CLASS Sequel::BeforeHookFailed
- CLASS Sequel::ConnectionPool
- CLASS Sequel::Database
- CLASS Sequel::DatabaseConnectionError
- CLASS Sequel::DatabaseDisconnectError
- CLASS Sequel::DatabaseError
- CLASS Sequel::Dataset
- CLASS Sequel::Error
- CLASS Sequel::IntegerMigrator
- CLASS Sequel::InvalidOperation
- CLASS Sequel::InvalidValue
- CLASS Sequel::LiteralString
- CLASS Sequel::Migration
- CLASS Sequel::MigrationDSL
- CLASS Sequel::Migrator
- CLASS Sequel::Model
- CLASS Sequel::NoExistingObject
- CLASS Sequel::NotImplemented
- CLASS Sequel::PoolTimeout
- CLASS Sequel::Rollback
- CLASS Sequel::ShardedSingleConnectionPool
- CLASS Sequel::ShardedThreadedConnectionPool
- CLASS Sequel::SimpleMigration
- CLASS Sequel::SingleConnectionPool
- CLASS Sequel::ThreadedConnectionPool
- CLASS Sequel::TimestampMigrator
- CLASS Sequel::ValidationFailed

### Methods

- ::Model
- ::condition_specifier?
- ::connect
- ::convert_exception_class
- ::extension
- ::identifier_input_method=
- ::identifier_output_method=
- ::inflections
- ::k_require
- ::migration
- ::quote_identifiers=
- ::require
- ::single_threaded=
- ::string_to_date
- ::string_to_datetime
- ::string_to_time
- ::ts_require
- ::tsk_require
- ::version
- ::virtual_row

### Included Modules

- Sequel::SQL::Constants

### Files

- CHANGELOG
- COPYING
- README.rdoc
- advanced_associations.rdoc
- association_basics.rdoc
- cheat_sheet.rdoc
- dataset_basics.rdoc
- dataset_filtering.rdoc
- migration.rdoc
- model_hooks.rdoc
- opening_databases.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.2.0.txt
- 3.3.0.txt
- 3.4.0.txt
- 3.5.0.txt
- 3.6.0.txt
- 3.7.0.txt
- 3.8.0.txt
- 3.9.0.txt
- sharding.rdoc
- sql.rdoc
- virtual_rows.rdoc

### Class/Module Index

Quicksearch

- Sequel
- Sequel::ADO
- Sequel::ADO::Database
- Sequel::ADO::Dataset
- Sequel::ADO::MSSQL
- Sequel::ADO::MSSQL::DatabaseMethods
- Sequel::ADO::MSSQL::Dataset
- Sequel::AdapterNotFound
- Sequel::Amalgalite
- Sequel::Amalgalite::Database
- Sequel::Amalgalite::Dataset
- Sequel::Amalgalite::SequelTypeMap
- Sequel::BasicObject
- Sequel::BeforeHookFailed
- Sequel::ConnectionPool
- Sequel::ConnectionPool::ClassMethods
- Sequel::DB2
- Sequel::DB2::Database
- Sequel::DB2::Dataset
- 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::AdapterMethods
- Sequel::DataObjects::Postgres::DatabaseMethods
- Sequel::DataObjects::Postgres::Dataset
- Sequel::DataObjects::SQLite
- Sequel::DataObjects::SQLite::DatabaseMethods
- Sequel::DataObjects::SQLite::Dataset
- Sequel::Database
- Sequel::DatabaseConnectionError
- Sequel::DatabaseDisconnectError
- Sequel::DatabaseError
- Sequel::Dataset
- Sequel::Dataset::ArgumentMapper
- Sequel::Dataset::Pagination
- Sequel::Dataset::PreparedStatementMethods
- Sequel::Dataset::QueryBlockCopy
- Sequel::Dataset::StoredProcedureMethods
- Sequel::Dataset::StoredProcedures
- Sequel::Dataset::UnnumberedArgumentMapper
- Sequel::Error
- Sequel::Error::AdapterNotFound
- Sequel::Error::InvalidOperation
- Sequel::Error::InvalidValue
- Sequel::Error::PoolTimeoutError
- Sequel::Error::Rollback
- Sequel::Firebird
- Sequel::Firebird::Database
- Sequel::Firebird::Dataset
- Sequel::Inflections
- Sequel::Informix
- Sequel::Informix::Database
- Sequel::Informix::Dataset
- Sequel::IntegerMigrator
- Sequel::InvalidOperation
- Sequel::InvalidValue
- Sequel::JDBC
- Sequel::JDBC::AS400
- Sequel::JDBC::AS400::DatabaseMethods
- Sequel::JDBC::AS400::Dataset
- Sequel::JDBC::Database
- Sequel::JDBC::Dataset
- Sequel::JDBC::Dataset::PreparedStatementMethods
- Sequel::JDBC::Dataset::StoredProcedureMethods
- Sequel::JDBC::H2
- Sequel::JDBC::H2::DatabaseMethods
- Sequel::JDBC::H2::Dataset
- Sequel::JDBC::JavaLang
- Sequel::JDBC::JavaSQL
- Sequel::JDBC::JavaxNaming
- Sequel::JDBC::MSSQL
- Sequel::JDBC::MSSQL::DatabaseMethods
- Sequel::JDBC::MSSQL::Dataset
- Sequel::JDBC::MySQL
- Sequel::JDBC::MySQL::DatabaseMethods
- Sequel::JDBC::MySQL::Dataset
- Sequel::JDBC::Oracle
- Sequel::JDBC::Oracle::DatabaseMethods
- Sequel::JDBC::Oracle::Dataset
- Sequel::JDBC::Postgres
- Sequel::JDBC::Postgres::AdapterMethods
- Sequel::JDBC::Postgres::DatabaseMethods
- Sequel::JDBC::Postgres::Dataset
- Sequel::JDBC::SQLite
- Sequel::JDBC::SQLite::DatabaseMethods
- Sequel::JDBC::SQLite::Dataset
- Sequel::LiteralString
- Sequel::LooserTypecasting
- Sequel::MSSQL
- Sequel::MSSQL::DatabaseMethods
- Sequel::MSSQL::DatasetMethods
- Sequel::Metaprogramming
- Sequel::Migration
- Sequel::MigrationDSL
- Sequel::Migrator
- Sequel::Migrator::Error
- Sequel::Model
- Sequel::Model::Associations
- Sequel::Model::Associations::AssociationDatasetMethods
- Sequel::Model::Associations::AssociationReflection
- Sequel::Model::Associations::ClassMethods
- Sequel::Model::Associations::DatasetMethods
- 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::Errors
- Sequel::Model::InstanceMethods
- Sequel::MySQL
- Sequel::MySQL::Database
- Sequel::MySQL::DatabaseMethods
- Sequel::MySQL::Dataset
- Sequel::MySQL::Dataset::CallableStatementMethods
- Sequel::MySQL::Dataset::PreparedStatementMethods
- Sequel::MySQL::Dataset::StoredProcedureMethods
- Sequel::MySQL::DatasetMethods
- Sequel::NamedTimezones
- Sequel::NoExistingObject
- Sequel::NotImplemented
- 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::DatasetMethods
- Sequel::Plugins
- Sequel::Plugins::ActiveModel
- Sequel::Plugins::ActiveModel::InstanceMethods
- Sequel::Plugins::AssociationDependencies
- Sequel::Plugins::AssociationDependencies::ClassMethods
- Sequel::Plugins::AssociationDependencies::InstanceMethods
- Sequel::Plugins::AssociationPks
- Sequel::Plugins::AssociationPks::ClassMethods
- Sequel::Plugins::AssociationProxies
- Sequel::Plugins::AssociationProxies::AssociationProxy
- Sequel::Plugins::AssociationProxies::ClassMethods
- 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::ForceEncoding
- Sequel::Plugins::ForceEncoding::ClassMethods
- Sequel::Plugins::ForceEncoding::InstanceMethods
- Sequel::Plugins::HookClassMethods
- Sequel::Plugins::HookClassMethods::ClassMethods
- Sequel::Plugins::HookClassMethods::InstanceMethods
- Sequel::Plugins::IdentityMap
- Sequel::Plugins::IdentityMap::ClassMethods
- Sequel::Plugins::IdentityMap::InstanceMethods
- Sequel::Plugins::InstanceFilters
- Sequel::Plugins::InstanceFilters::InstanceMethods
- Sequel::Plugins::InstanceHooks
- Sequel::Plugins::InstanceHooks::InstanceMethods
- Sequel::Plugins::LazyAttributes
- Sequel::Plugins::LazyAttributes::ClassMethods
- Sequel::Plugins::LazyAttributes::InstanceMethods
- Sequel::Plugins::ManyThroughMany
- Sequel::Plugins::ManyThroughMany::ClassMethods
- Sequel::Plugins::ManyThroughMany::ManyThroughManyAssociationReflection
- Sequel::Plugins::NestedAttributes
- Sequel::Plugins::NestedAttributes::ClassMethods
- Sequel::Plugins::NestedAttributes::InstanceMethods
- Sequel::Plugins::OptimisticLocking
- Sequel::Plugins::OptimisticLocking::ClassMethods
- Sequel::Plugins::OptimisticLocking::InstanceMethods
- Sequel::Plugins::RcteTree
- Sequel::Plugins::Schema
- Sequel::Plugins::Schema::ClassMethods
- Sequel::Plugins::Serialization
- Sequel::Plugins::Serialization::ClassMethods
- Sequel::Plugins::Serialization::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::StringStripper
- Sequel::Plugins::StringStripper::InstanceMethods
- 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::TypecastOnLoad
- Sequel::Plugins::TypecastOnLoad::ClassMethods
- Sequel::Plugins::TypecastOnLoad::InstanceMethods
- Sequel::Plugins::UpdatePrimaryKey
- Sequel::Plugins::UpdatePrimaryKey::ClassMethods
- 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::PoolTimeout
- Sequel::Postgres
- Sequel::Postgres::Adapter
- Sequel::Postgres::AdapterMethods
- 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::PrettyTable
- Sequel::Progress
- Sequel::Progress::DatabaseMethods
- Sequel::Progress::DatasetMethods
- 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::CaseExpression
- Sequel::SQL::Cast
- Sequel::SQL::CastMethods
- Sequel::SQL::ColumnAll
- Sequel::SQL::ComplexExpression
- Sequel::SQL::ComplexExpressionMethods
- Sequel::SQL::Constant
- Sequel::SQL::Constants
- Sequel::SQL::Expression
- Sequel::SQL::Function
- Sequel::SQL::GenericComplexExpression
- Sequel::SQL::GenericExpression
- Sequel::SQL::Identifier
- Sequel::SQL::IdentifierMethods
- Sequel::SQL::InequalityMethods
- Sequel::SQL::JoinClause
- Sequel::SQL::JoinOnClause
- Sequel::SQL::JoinUsingClause
- Sequel::SQL::NegativeBooleanConstant
- Sequel::SQL::NoBooleanInputMethods
- Sequel::SQL::NumericExpression
- Sequel::SQL::NumericMethods
- Sequel::SQL::OrderMethods
- Sequel::SQL::OrderedExpression
- Sequel::SQL::PlaceholderLiteralString
- Sequel::SQL::QualifiedIdentifier
- Sequel::SQL::QualifyingMethods
- Sequel::SQL::SQLArray
- Sequel::SQL::StringConcatenationMethods
- Sequel::SQL::StringExpression
- Sequel::SQL::StringMethods
- Sequel::SQL::Subscript
- Sequel::SQL::SubscriptMethods
- Sequel::SQL::VirtualRow
- Sequel::SQL::Window
- Sequel::SQL::WindowFunction
- Sequel::SQLite
- Sequel::SQLite::Database
- Sequel::SQLite::DatabaseMethods
- Sequel::SQLite::Dataset
- Sequel::SQLite::Dataset::ArgumentMapper
- Sequel::SQLite::Dataset::PreparedStatementMethods
- Sequel::SQLite::DatasetMethods
- Sequel::Schema
- Sequel::Schema::AlterTableGenerator
- Sequel::Schema::Generator
- Sequel::ShardedSingleConnectionPool
- Sequel::ShardedThreadedConnectionPool
- Sequel::SimpleMigration
- Sequel::SingleConnectionPool
- Sequel::ThreadLocalTimezones
- Sequel::ThreadedConnectionPool
- Sequel::TimestampMigrator
- Sequel::Timezones
- Sequel::ValidationFailed
- String
- String::Inflections
- Array
- FalseClass
- Hash
- NilClass
- Numeric
- Object
- PGconn
- PGresult
- Proc
- Symbol
- TrueClass

No matching classes.

# Sequel

The thread_local_timezones extension allows you to set a per-thread timezone that will override the default global timezone while the thread is executing. The main use case is for web applications that execute each request in its own thread, and want to set the timezones based on the request. The most common example is having the database always store time in UTC, but have the application deal with the timezone of the current user. That can be done with:

    Sequel.database_timezone = :utc
    # In each thread:
    Sequel.thread_application_timezone = current_user.timezone

This extension is designed to work with the named_timezones extension.

This extension adds the thread_application_timezone=, thread_database_timezone=, and thread_typecast_timezone= methods to the Sequel module. It overrides the application_timezone, database_timezone, and typecast_timezone methods to check the related thread local timezone first, and use it if present. If the related thread local timezone is not present, it falls back to the default global timezone.

There is one special case of note. If you have a default global timezone and you want to have a nil thread local timezone, you have to set the thread local value to :nil instead of nil:

    Sequel.application_timezone = :utc
    Sequel.thread_application_timezone = nil
    Sequel.application_timezone # => :utc
    Sequel.thread_application_timezone = :nil
    Sequel.application_timezone # => nil

The sql_expr extension adds the sql_expr method to every object, which returns an object that works nicely with Sequel’s DSL. This is best shown by example:

    1.sql_expr < :a     # 1 < a
    false.sql_expr & :a # FALSE AND a
    true.sql_expr | :a  # TRUE OR a
    ~nil.sql_expr       # NOT NULL
    "a".sql_expr + "b"  # 'a' || 'b'

The pagination extension adds the Sequel::Dataset#paginate and each_page methods, which return paginated (limited and offset) datasets with some helpful methods that make creating a paginated display easier.

Adds the Sequel::Migration and Sequel::Migrator classes, which allow the user to easily group schema changes and migrate the database to a newer version or revert to a previous version.

The LooserTypecasting extension changes the float and integer typecasting to use the looser .to_f and .to_i instead of the more strict Kernel.Float and Kernel.Integer. To use it, you should extend the database with the Sequel::LooserTypecasting module after loading the extension:

    Sequel.extension :looser_typecasting
    DB.extend(Sequel::LooserTypecasting)

The schema_dumper extension supports dumping tables and indexes in a Sequel::Migration format, so they can be restored on another database (which can be the same type or a different type than the current database). The main interface is through Sequel::Database#dump_schema_migration.

The pretty_table extension adds Sequel::Dataset#print and the Sequel::PrettyTable class for creating nice-looking plain-text tables.

The query extension adds Sequel::Dataset#query which allows a different way to construct queries instead of the usual method chaining.

Top level module for Sequel

There are some class methods that are added via metaprogramming, one for each supported adapter. For example:

    DB = Sequel.sqlite # Memory database
    DB = Sequel.sqlite('blog.db')
    DB = Sequel.postgres('database_name', :user=>'user',
           :password=>'password', :host=>'host', :port=>5432,
           :max_connections=>10)

If a block is given to these methods, it is passed the opened Database object, which is closed (disconnected) when the block exits, just like a block passed to connect. For example:

    Sequel.sqlite('blog.db'){|db| puts db[:users].count}

Sequel doesn't pay much attention to timezones by default, but you can set it handle timezones if you want. There are three separate timezone settings:

- application_timezone - The timezone you want the application to use. This is the timezone that incoming times from the database and typecasting are converted to.

- database_timezone - The timezone for storage in the database. This is the timezone to which Sequel will convert timestamps before literalizing them for storage in the database. It is also the timezone that Sequel will assume database timestamp values are already in (if they don’t include an offset).

- typecast_timezone - The timezone that incoming data that Sequel needs to typecast is assumed to be already in (if they don’t include an offset).

You can set also set all three timezones to the same value at once via Sequel.default_timezone=.

    Sequel.application_timezone = :utc # or :local or nil
    Sequel.database_timezone = :utc # or :local or nil
    Sequel.typecast_timezone = :utc # or :local or nil
    Sequel.default_timezone = :utc # or :local or nil

The only timezone values that are supported by default are :utc (convert to UTC), :local (convert to local time), and nil (don’t convert). If you need to convert to a specific timezone, or need the timezones being used to change based on the environment (e.g. current user), you need to use an extension (and use DateTime as the datetime_class).

You can set the SEQUEL_NO_CORE_EXTENSIONS constant or environment variable to have Sequel not extend the core classes.

For a more expanded introduction, see the README. For a quicker introduction, see the cheat sheet.

### Constants

ADAPTER_MAP

  Hash of adapters that have been used. The key is the adapter scheme symbol, and the value is the Database subclass.

DATABASES

  Array of all databases to which Sequel has connected. If you are developing an application that can connect to an arbitrary number of databases, delete the database objects from this or they will not get garbage collected.

DEFAULT_INFLECTIONS_PROC

  Proc that is instance evaled to create the default inflections for both the model inflector and the inflector extension.

LOCAL_DATETIME_OFFSET

  The offset of the current time zone from UTC, as a fraction of a day.

LOCAL_DATETIME_OFFSET_SECS

  The offset of the current time zone from UTC, in seconds.

MAJOR
MINOR
TINY
VERSION

### Attributes

convert_two_digit_years[RW]

Sequel converts two digit years in Dates and DateTimes by default, so 01/02/03 is interpreted at January 2nd, 2003, and 12/13/99 is interpreted as December 13, 1999. You can override this to treat those dates as January 2nd, 0003 and December 13, 0099, respectively, by setting this to false.

datetime_class[RW]

Sequel can use either Time or DateTime for times returned from the database. It defaults to Time. To change it to DateTime, set this to DateTime.

virtual_row_instance_eval[RW]

### Public Class Methods

Model(source) click to toggle source

Lets you create a Model subclass with its dataset already set. source can be an existing dataset or a symbol (in which case it will create a dataset using the default database with the given symbol as the table name).

The purpose of this method is to set the dataset automatically for a model class, if the table name doesn’t match the implicit name. This is neater than using set_dataset inside the class, doesn’t require a bogus query for the schema, and allows it to work correctly in a system that uses code reloading.

Example:

    class Comment < Sequel::Model(:something)
      table_name # => :something
    end

    # File lib/sequel/model.rb, line 19
    def self.Model(source)
      Model::ANONYMOUS_MODEL_CLASSES[source] ||= if source.is_a?(Database)
        c = Class.new(Model)
        c.db = source
        c
      else
        Class.new(Model).set_dataset(source)
      end
    end

condition_specifier?(obj) click to toggle source

Returns true if the passed object could be a specifier of conditions, false otherwise. Currently, Sequel considers hashes and arrays of all two pairs as condition specifiers.

    # File lib/sequel/core.rb, line 97
    def self.condition_specifier?(obj)
      case obj
      when Hash
        true
      when Array
        !obj.empty? && obj.all?{|i| (Array === i) && (i.length == 2)}
      else
        false
      end
    end

connect(*args, &block) click to toggle source

Creates a new database object based on the supplied connection string and optional arguments. The specified scheme determines the database class used, and the rest of the string specifies the connection options. For example:

    DB = Sequel.connect('sqlite:/') # Memory database
    DB = Sequel.connect('sqlite://blog.db') # ./blog.db
    DB = Sequel.connect('sqlite:///blog.db') # /blog.db
    DB = Sequel.connect('postgres://user:password@host:port/database_name')
    DB = Sequel.connect('sqlite:///blog.db', :max_connections=>10)

If a block is given, it is passed the opened Database object, which is closed when the block exits. For example:

    Sequel.connect('sqlite://blog.db'){|db| puts db[:users].count}

For details, see the “Connecting to a Database” guide. To set up a master/slave or sharded database connection, see the “Master/Slave Databases and Sharding” guide.

    # File lib/sequel/core.rb, line 126
    def self.connect(*args, &block)
      Database.connect(*args, &block)
    end

convert_exception_class(exception, klass) click to toggle source

Convert the exception to the given class. The given class should be Sequel::Error or a subclass. Returns an instance of klass with the message and backtrace of exception.

    # File lib/sequel/core.rb, line 133
    def self.convert_exception_class(exception, klass)
      return exception if exception.is_a?(klass)
      e = klass.new("#{exception.class}: #{exception.message}")
      e.wrapped_exception = exception
      e.set_backtrace(exception.backtrace)
      e
    end

extension(*extensions) click to toggle source

Load all Sequel extensions given. Only loads extensions included in this release of Sequel, doesn’t load external extensions.

    Sequel.extension(:schema_dumper)
    Sequel.extension(:pagination, :query)

    # File lib/sequel/core.rb, line 146
    def self.extension(*extensions)
      extensions.each{|e| tsk_require "sequel/extensions/#{e}"}
    end

identifier_input_method=(value) click to toggle source

Set the method to call on identifiers going into the database. This affects the literalization of identifiers by calling this method on them before they are input. Sequel upcases identifiers in all SQL strings for most databases, so to turn that off:

    Sequel.identifier_input_method = nil

to downcase instead:

    Sequel.identifier_input_method = :downcase

Other String instance methods work as well.

    # File lib/sequel/core.rb, line 161
    def self.identifier_input_method=(value)
      Database.identifier_input_method = value
    end

identifier_output_method=(value) click to toggle source

Set the method to call on identifiers coming out of the database. This affects the literalization of identifiers by calling this method on them when they are retrieved from the database. Sequel downcases identifiers retrieved for most databases, so to turn that off:

    Sequel.identifier_output_method = nil

to upcase instead:

    Sequel.identifier_output_method = :upcase

Other String instance methods work as well.

    # File lib/sequel/core.rb, line 177
    def self.identifier_output_method=(value)
      Database.identifier_output_method = value
    end

inflections() click to toggle source

Yield the Inflections module if a block is given, and return the Inflections module.

    # File lib/sequel/model/inflections.rb, line 4
    def self.inflections
      yield Inflections if block_given?
      Inflections
    end

k_require(files, subdir=nil) click to toggle source

Alias to the standard version of require

Alias for: require
migration(&block) click to toggle source

The preferred method for writing Sequel migrations, using a DSL:

    Sequel.migration do
      up do
        create_table(:artists) do
          primary_key :id
          String :name
        end
      end

      down do
        drop_table(:artists)
      end
    end

Designed to be used with the `Migrator` class, part of the `migration` extension.

    # File lib/sequel/extensions/migration.rb, line 124
    def self.migration(&block)
      MigrationDSL.create(&block)
    end

quote_identifiers=(value) click to toggle source

Set whether to quote identifiers for all databases by default. By default, Sequel quotes identifiers in all SQL strings, so to turn that off:

    Sequel.quote_identifiers = false

    # File lib/sequel/core.rb, line 185
    def self.quote_identifiers=(value)
      Database.quote_identifiers = value
    end

require(files, subdir=nil) click to toggle source

Require all given files which should be in the same or a subdirectory of this file. If a subdir is given, assume all files are in that subdir.

    # File lib/sequel/core.rb, line 191
    def self.require(files, subdir=nil)
      Array(files).each{|f| super("#{File.dirname(__FILE__)}/#{"#{subdir}/" if subdir}#{f}")}
    end

Also aliased as: k_require
single_threaded=(value) click to toggle source

Set whether to set the single threaded mode for all databases by default. By default, Sequel uses a threadsafe connection pool, which isn’t as fast as the single threaded connection pool. If your program will only have one thread, and speed is a priority, you may want to set this to true:

    Sequel.single_threaded = true

    # File lib/sequel/core.rb, line 201
    def self.single_threaded=(value)
      Database.single_threaded = value
    end

string_to_date(s) click to toggle source

Converts the given string into a Date object.

    # File lib/sequel/core.rb, line 206
    def self.string_to_date(s)
      begin
        Date.parse(s, Sequel.convert_two_digit_years)
      rescue => e
        raise convert_exception_class(e, InvalidValue)
      end
    end

string_to_datetime(s) click to toggle source

Converts the given string into a Time or DateTime object, depending on the value of Sequel.datetime_class.

    # File lib/sequel/core.rb, line 216
    def self.string_to_datetime(s)
      begin
        if datetime_class == DateTime
          DateTime.parse(s, convert_two_digit_years)
        else
          datetime_class.parse(s)
        end
      rescue => e
        raise convert_exception_class(e, InvalidValue)
      end
    end

string_to_time(s) click to toggle source

Converts the given string into a Time object.

    # File lib/sequel/core.rb, line 229
    def self.string_to_time(s)
      begin
        Time.parse(s)
      rescue => e
        raise convert_exception_class(e, InvalidValue)
      end
    end

ts_require(*args) click to toggle source

Same as Sequel.require, but wrapped in a mutex in order to be thread safe.

    # File lib/sequel/core.rb, line 238
    def self.ts_require(*args)
      check_requiring_thread{require(*args)}
    end

tsk_require(*args) click to toggle source

Same as Kernel.require, but wrapped in a mutex in order to be thread safe.

    # File lib/sequel/core.rb, line 243
    def self.tsk_require(*args)
      check_requiring_thread{k_require(*args)}
    end

version() click to toggle source

The version of Sequel you are using, as a string (e.g. “2.11.0”)

    # File lib/sequel/version.rb, line 9
    def self.version
      VERSION
    end

virtual_row(&block) click to toggle source

If the supplied block takes a single argument, yield a new SQL::VirtualRow instance to the block argument. Otherwise, evaluate the block in the context of a new SQL::VirtualRow instance.

    # File lib/sequel/core.rb, line 251
    def self.virtual_row(&block)
      vr = SQL::VirtualRow.new
      case block.arity
      when -1, 0
        vr.instance_eval(&block)
      else
        block.call(vr)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.