Class | Amalgalite::Aggregate |
In: |
lib/amalgalite/aggregate.rb
lib/amalgalite/aggregate.rb |
Parent: | Object |
A Base class to inherit from for creating your own SQL aggregate functions in ruby.
These are SQL functions similar to _max(X)_, _count(X)_, _avg(X)_. The built in SQLite aggregate functions are:
If you choose to use Aggregate as a parent class of your SQL scalar function implementation you must:
For instance to implement a unique_word_count(X) aggregate function you could implement it as:
class UniqueWordCount < ::Amalgalite::Aggregate attr_accessor :words def initialize @name = 'unique_word_count' @arity = 1 @words = Hash.new { |h,k| h[k] = 0 } end def step( str ) str.split(/\W+/).each do |word| words[ word.downcase ] += 1 end return nil end def finalize return words.size end end
arity | [RW] | The arity of the SQL function |
arity | [RW] | The arity of the SQL function |
name | [RW] | The name of the SQL function |
name | [RW] | The name of the SQL function |