Permalink
Browse files

Include Sequel::SQL::AliasMethods in Sequel::Postgres::PGArray to all…

…ow aliasing PGArrays without having to use Sequel.as()
  • Loading branch information...
treydempsey committed Sep 30, 2012
1 parent 56bd06d commit c59f6ce63b88ab8ee466905ae457da95b39e2277
Showing with 6 additions and 0 deletions.
  1. +2 −0 lib/sequel/extensions/pg_array.rb
  2. +4 −0 spec/extensions/pg_array_spec.rb
@@ -99,6 +99,8 @@ module Sequel
module Postgres
# Represents a PostgreSQL array column value.
class PGArray < DelegateClass(Array)
+ include Sequel::SQL::AliasMethods
+
ARRAY = "ARRAY".freeze
DOUBLE_COLON = '::'.freeze
EMPTY_BRACKET = '[]'.freeze
@@ -231,6 +231,10 @@
proc{@db.typecast_value(:integer_array, {})}.should raise_error(Sequel::InvalidValue)
end
+ it "should support SQL::AliasMethods" do
+ @db.select(Sequel.pg_array([1], :integer).as(:col1)).sql.should == 'SELECT ARRAY[1]::integer[] AS col1'
+ end
+
it "should support registering custom array types" do
Sequel::Postgres::PGArray.register('foo')
@db.typecast_value(:foo_array, []).should be_a_kind_of(Sequel::Postgres::PGArray)

0 comments on commit c59f6ce

Please sign in to comment.