Skip to content

Instantly share code, notes, and snippets.

@maxlapshin
Created February 26, 2009 22:23
Show Gist options
  • Save maxlapshin/71161 to your computer and use it in GitHub Desktop.
Save maxlapshin/71161 to your computer and use it in GitHub Desktop.
Sqlite group_concat
module ActiveRecord
module ConnectionAdapters
class SQLite3Adapter
def initialize(*args)
Rails.logger.debug "Adding group_concat to SQLite database"
super
raw_connection.create_aggregate("group_concat", 2) do
step do |func, value, separator|
if String(func[:concat]).empty? then
func[:concat] = String(value)
else
func[:concat] = String(func[:concat]) + "#{separator}" + String(value)
end
end
finalize do |func|
func.result = func[:concat]
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment