Module: Sequel::Postgres::DatasetMethods::PreparedStatementMethods

Defined in:
lib/sequel/adapters/shared/postgres.rb

Overview

Shared methods for prepared statements when used with PostgreSQL databases.

Instance Method Summary collapse

Instance Method Details

#prepared_sqlObject



1235
1236
1237
1238
1239
1240
1241
1242
1243
# File 'lib/sequel/adapters/shared/postgres.rb', line 1235

def prepared_sql
  return @prepared_sql if @prepared_sql
  if @prepared_type == :insert && !opts[:returning]
    @opts[:returning] = insert_pk
    @opts[:returning_pk] = true
  end
  super
  @prepared_sql
end

#runObject

Override insert action to use RETURNING if the server supports it.



1227
1228
1229
1230
1231
1232
1233
# File 'lib/sequel/adapters/shared/postgres.rb', line 1227

def run
  if @prepared_type == :insert && (opts[:returning_pk] || !opts[:returning])
    fetch_rows(prepared_sql){|r| return r.values.first}
  else
    super
  end
end