aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/nodes/extract.rb
blob: 1c9ee788163037bf37e42ebe20e5252557a0432d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Arel
  module Nodes

    class Extract < Arel::Nodes::Unary
      include Arel::Expression
      include Arel::Predications

      attr_accessor :field
      attr_accessor :alias

      def initialize expr, field, aliaz = nil
        super(expr)
        @field = field
        @alias = aliaz && SqlLiteral.new(aliaz)
      end

      def as aliaz
        self.alias = SqlLiteral.new(aliaz)
        self
      end
    end
  end
end