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



1259
1260
1261
1262
1263
1264
1265
1266
1267
# File 'lib/sequel/adapters/shared/postgres.rb', line 1259

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.



1251
1252
1253
1254
1255
1256
1257
# File 'lib/sequel/adapters/shared/postgres.rb', line 1251

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