Sha256: c19c9cf0754b4eaf275ffe0de3d2bf0082a13f7a2d2ffb9f27954e823d51906f

Contents?: true

Size: 986 Bytes

Versions: 2

Compression:

Stored size: 986 Bytes

Contents

This gem adds the `Sequel::Dataset#replace_select_with_alias` method. The
method replaces selected columns from a dataset with aliases for the same
column names. It preserves the order in which columns are already selected.

If the aliased column isn't already selected in the dataset then the method
returns the existing dataset unchanged.

This functionality is particularly useful when building up a `SELECT` statement
as the input for an `INSERT` when some columns need to be transformed (i.e.
replaced with an alias) before they are inserted.

Example usages:

    DB[:items].select(:a, :b).replace_select_with_alias(Sequel.as("1", :a))
    # SELECT '1' AS a, b FROM items

    DB[:items].replace_select_with_alias(Sequel.as("1", :a))
    # SELECT * FROM items

    DB[:items].select(:a).replace_select_with_alias(Sequel.as("1", :b))
    # SELECT a FROM items

    DB[:items].select(:a, :b).replace_select_with_alias { |o| Sequel.as("1", o.a) }
    # SELECT '1' AS a, b FROM items

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sequel_replace_select_with_alias-0.0.2 README.md
sequel_replace_select_with_alias-0.0.1 README.md