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



1285
1286
1287
1288
1289
1290
1291
1292
1293
# File 'lib/sequel/adapters/shared/postgres.rb', line 1285

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.



1277
1278
1279
1280
1281
1282
1283
# File 'lib/sequel/adapters/shared/postgres.rb', line 1277

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