identifier_mangling.rb

Path: lib/sequel/extensions/identifier_mangling.rb
Last Update: Fri Oct 06 03:25:22 +0000 2017

frozen-string-literal: true

The identifier_mangling extension adds support for to change the default identifier mangling for datasets, as well as all datasets for a given database.

  # Use uppercase identifiers in database, and lowercase in ruby.
  # Default behavior of Sequel, as the SQL standard behavior
  # folds unquoted identifiers to uppercase.
  DB.identifier_input_method = :upcase
  DB.identifier_output_method = :downcase

  # Don't modify identifiers.
  # Default behavior of Sequel on PostgreSQL, MySQL, SQLite,
  # as they fold unquoted identifiers to lowercase.
  DB.identifier_input_method = nil
  DB.identifier_output_method = nil

You can also choose to turn on or off identifier quoting:

  # Quote identifiers.  Sequel's default behavior.
  DB.quote_identifiers = true

  # Don't quote identifiers.  Sequel's default behavior on DB2.
  DB.quote_identifiers = false

To modify the identifiers on a per-dataset basis:

  ds = DB[:a].with_input_indentifier(:upcase).
              with_output_identifier(:downcase).
              with_quote_identifiers(true)

To load the extension into the database:

  DB.extension :identifier_mangling

Related modules: Sequel::IdentifierMangling::DatabaseMethods, Sequel::IdentifierMangling::DatasetMethods

[Validate]