module Sequel

  1. lib/sequel/ast_transformer.rb
  2. lib/sequel/connection_pool.rb
  3. lib/sequel/connection_pool/sharded_single.rb
  4. lib/sequel/connection_pool/sharded_threaded.rb
  5. lib/sequel/connection_pool/sharded_timed_queue.rb
  6. lib/sequel/connection_pool/single.rb
  7. lib/sequel/connection_pool/threaded.rb
  8. lib/sequel/connection_pool/timed_queue.rb
  9. lib/sequel/core.rb
  10. lib/sequel/database.rb
  11. lib/sequel/database/connecting.rb
  12. lib/sequel/database/dataset.rb
  13. lib/sequel/database/dataset_defaults.rb
  14. lib/sequel/database/features.rb
  15. lib/sequel/database/logging.rb
  16. lib/sequel/database/misc.rb
  17. lib/sequel/database/query.rb
  18. lib/sequel/database/schema_generator.rb
  19. lib/sequel/database/schema_methods.rb
  20. lib/sequel/database/transactions.rb
  21. lib/sequel/dataset.rb
  22. lib/sequel/dataset/actions.rb
  23. lib/sequel/dataset/dataset_module.rb
  24. lib/sequel/dataset/deprecated_singleton_class_methods.rb
  25. lib/sequel/dataset/features.rb
  26. lib/sequel/dataset/graph.rb
  27. lib/sequel/dataset/misc.rb
  28. lib/sequel/dataset/placeholder_literalizer.rb
  29. lib/sequel/dataset/prepared_statements.rb
  30. lib/sequel/dataset/query.rb
  31. lib/sequel/dataset/sql.rb
  32. lib/sequel/deprecated.rb
  33. lib/sequel/exceptions.rb
  34. lib/sequel/extensions/migration.rb
  35. lib/sequel/model.rb
  36. lib/sequel/model/associations.rb
  37. lib/sequel/model/base.rb
  38. lib/sequel/model/dataset_module.rb
  39. lib/sequel/model/default_inflections.rb
  40. lib/sequel/model/errors.rb
  41. lib/sequel/model/exceptions.rb
  42. lib/sequel/model/inflections.rb
  43. lib/sequel/model/plugins.rb
  44. lib/sequel/sql.rb
  45. lib/sequel/timezones.rb
  46. lib/sequel/version.rb
  47. show all

Top level module for Sequel

There are some module 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 Sequel.connect. For example:

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

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

Methods

Public Class

  1. inflections
  2. migration
  3. version

Included modules

  1. SQL::Constants

Constants

ADAPTER_MAP = {}  

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

AdapterNotFound = Class.new(Error)  

Error raised when the adapter requested doesn’t exist or can’t be loaded.

AdvisoryLockError = Class.new(Error)  

Error raised when there is a failed attempt to acquire an advisory lock.

CheckConstraintViolation = Class.new(ConstraintViolation)  

Error raised when Sequel determines a database check constraint has been violated.

ConstraintViolation = Class.new(DatabaseError)  

Generic error raised when Sequel determines a database constraint has been violated.

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 use the :keep_reference Database option or a block when connecting) or they will not get garbage collected.

DEFAULT_INFLECTIONS_PROC = proc do plural(/$/, 's') plural(/s$/i, 's') plural(/(alias|(?:stat|octop|vir|b)us)$/i, '\1es') plural(/(buffal|tomat)o$/i, '\1oes') plural(/([ti])um$/i, '\1a') plural(/sis$/i, 'ses') plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves') plural(/(hive)$/i, '\1s') plural(/([^aeiouy]|qu)y$/i, '\1ies') plural(/(x|ch|ss|sh)$/i, '\1es') plural(/(matr|vert|ind)ix|ex$/i, '\1ices') plural(/([m|l])ouse$/i, '\1ice') singular(/s$/i, '') singular(/([ti])a$/i, '\1um') singular(/(analy|ba|cri|diagno|parenthe|progno|synop|the)ses$/i, '\1sis') singular(/([^f])ves$/i, '\1fe') singular(/([h|t]ive)s$/i, '\1') singular(/([lr])ves$/i, '\1f') singular(/([^aeiouy]|qu)ies$/i, '\1y') singular(/(m)ovies$/i, '\1ovie') singular(/(x|ch|ss|sh)es$/i, '\1') singular(/([m|l])ice$/i, '\1ouse') singular(/buses$/i, 'bus') singular(/oes$/i, 'o') singular(/shoes$/i, 'shoe') singular(/(alias|(?:stat|octop|vir|b)us)es$/i, '\1') singular(/(vert|ind)ices$/i, '\1ex') singular(/matrices$/i, 'matrix') irregular('person', 'people') irregular('man', 'men') irregular('child', 'children') irregular('sex', 'sexes') irregular('move', 'moves') irregular('quiz', 'quizzes') irregular('testis', 'testes') uncountable(%w(equipment information rice money species series fish sheep news)) end  

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

DatabaseConnectionError = Class.new(DatabaseError)  

Error raised when the Sequel is unable to connect to the database with the connection parameters it was given.

DatabaseDisconnectError = Class.new(DatabaseError)  

Error raised by adapters when they determine that the connection to the database has been lost. Instructs the connection pool code to remove that connection from the pool so that other connections can be acquired automatically.

DatabaseError = Class.new(Error)  

Generic error raised by the database adapters, indicating a problem originating from the database server. Usually raised because incorrect SQL syntax is used.

DatabaseLockTimeout = Class.new(DatabaseError)  

Error raised when Sequel determines the database could not acquire a necessary lock before timing out. Use of Dataset#nowait can often cause this exception when retrieving rows.

ForeignKeyConstraintViolation = Class.new(ConstraintViolation)  

Error raised when Sequel determines a database foreign key constraint has been violated.

InvalidOperation = Class.new(Error)  

Error raised on an invalid operation, such as trying to update or delete a joined or grouped dataset when the database does not support that.

InvalidValue = Class.new(Error)  

Error raised when attempting an invalid type conversion.

MAJOR = 5  

The major version of Sequel. Only bumped for major changes.

MINOR = 78  

The minor version of Sequel. Bumped for every non-patch level release, generally around once a month.

NoExistingObject = Class.new(Error)  

Exception class raised when require_modification is set and an UPDATE or DELETE statement to modify the dataset doesn’t modify a single row.

NotNullConstraintViolation = Class.new(ConstraintViolation)  

Error raised when Sequel determines a database NOT NULL constraint has been violated.

OPTS = {}.freeze  

Frozen hash used as the default options hash for most options.

PoolTimeout = Class.new(Error)  

Error raised when the connection pool cannot acquire a database connection before the timeout.

Rollback = Class.new(Error)  

Error that you should raise to signal a rollback of the current transaction. The transaction block will catch this exception, rollback the current transaction, and won’t reraise it (unless a reraise is requested).

SHARED_ADAPTER_MAP = {}  

Hash of shared adapters that have been registered. The key is the adapter scheme symbol, and the value is the Sequel module containing the shared adapter.

SPLIT_SYMBOL_CACHE = {}  
SerializationFailure = Class.new(DatabaseError)  

Error raised when Sequel determines a serialization failure/deadlock in the database.

TINY = 0  

The tiny version of Sequel. Usually 0, only bumped for bugfix releases that fix regressions from previous versions.

Timezones = SequelMethods  

Backwards compatible alias

UndefinedAssociation = Class.new(Error)  

Raised when an undefined association is used when eager loading.

UniqueConstraintViolation = Class.new(ConstraintViolation)  

Error raised when Sequel determines a database unique constraint has been violated.

VERSION = [MAJOR, MINOR, TINY].join('.').freeze  

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

VERSION_NUMBER = MAJOR*10000 + MINOR*10 + TINY  

The version of Sequel you are using, as a number (2.11.0 -> 20110)

VIRTUAL_ROW = new  

Public Class methods

inflections()

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

[show source]
  # File lib/sequel/model/inflections.rb
6 def self.inflections
7   yield Inflections if defined?(yield)
8   Inflections
9 end
migration(&block)

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.

[show source]
    # File lib/sequel/extensions/migration.rb
308 def self.migration(&block)
309   MigrationDSL.create(&block)
310 end
version()

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

[show source]
   # File lib/sequel/version.rb
22 def self.version
23   VERSION
24 end