Class: Sequel::Postgres::Dataset

Class | Sequel::Postgres::Dataset
In: | lib/sequel_core/adapters/postgres.rb
Parent: | Sequel::Dataset

Dataset class for PostgreSQL datasets that use the pg, postgres, or postgres-pr driver.

### Methods

call fetch_rows literal prepare prepared_arg_placeholder

### Included Modules

Sequel::Postgres::DatasetMethods

### Classes and Modules

Module Sequel::Postgres::Dataset::ArgumentMapper
Module Sequel::Postgres::Dataset::BindArgumentMethods
Module Sequel::Postgres::Dataset::PreparedStatementMethods

### Constants

PREPARED_ARG_PLACEHOLDER | = | '$'.lit.freeze

### Public Instance methods

call(type, hash, values=nil, &block)

Execute the given type of statement with the hash of values.

[Source]

         # File lib/sequel_core/adapters/postgres.rb, line 428
    428:         def call(type, hash, values=nil, &block)
    429:           ps = to_prepared_statement(type, values)
    430:           ps.extend(BindArgumentMethods)
    431:           ps.call(hash, &block)
    432:         end

fetch_rows(sql) {|converted_rec| ...}

Yield all rows returned by executing the given SQL and converting the types.

[Source]

         # File lib/sequel_core/adapters/postgres.rb, line 311
    311:       def fetch_rows(sql)
    312:         cols = []
    313:         execute(sql) do |res|
    314:           res.nfields.times do |fieldnum|
    315:             cols << [fieldnum, PG_TYPES[res.ftype(fieldnum)], output_identifier(res.fname(fieldnum))]
    316:           end
    317:           @columns = cols.map{|c| c.at(2)}
    318:           res.ntuples.times do |recnum|
    319:             converted_rec = {}
    320:             cols.each do |fieldnum, type_proc, fieldsym|
    321:               value = res.getvalue(recnum, fieldnum)
    322:               converted_rec[fieldsym] = (value && type_proc) ? type_proc.call(value) : value
    323:             end
    324:             yield converted_rec
    325:           end
    326:         end
    327:       end

literal(v)

Literalize strings and blobs using code from the native adapter.

[Source]

         # File lib/sequel_core/adapters/postgres.rb, line 330
    330:       def literal(v)
    331:         case v
    332:         when LiteralString
    333:           v
    334:         when SQL::Blob
    335:           db.synchronize{|c| "'#{c.escape_bytea(v)}'"}
    336:         when String
    337:           db.synchronize{|c| "'#{c.escape_string(v)}'"}
    338:         else
    339:           super
    340:         end
    341:       end

prepare(type, name=nil, values=nil)

Prepare the given type of statement with the given name, and store it in the database to be called later.

[Source]

         # File lib/sequel_core/adapters/postgres.rb, line 436
    436:         def prepare(type, name=nil, values=nil)
    437:           ps = to_prepared_statement(type, values)
    438:           ps.extend(PreparedStatementMethods)
    439:           if name
    440:             ps.prepared_statement_name = name
    441:             db.prepared_statements[name] = ps
    442:           end
    443:           ps
    444:         end

prepared_arg_placeholder()

PostgreSQL uses $N for placeholders instead of ?, so use a $ as the placeholder.

[Source]

         # File lib/sequel_core/adapters/postgres.rb, line 450
    450:         def prepared_arg_placeholder
    451:           PREPARED_ARG_PLACEHOLDER
    452:         end

[Validate]