forked from mneumann/postgres-pr
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* moved classes and modules into PostgresPR module
* moved main part from postgres.rb into postgres-pr/postgres-compat.rb. postgres.rb now only contains the LoadError dispatch. * new version 0.2.2
- Loading branch information
Showing
8 changed files
with
68 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# This is a compatibility layer for using the pure Ruby postgres-pr instead of | ||
# the C interface of postgres. | ||
|
||
require 'postgres-pr/connection' | ||
|
||
class PGconn | ||
class << self | ||
alias connect new | ||
end | ||
|
||
def initialize(host, port, options, tty, database, user, auth) | ||
uri = | ||
if host.nil? | ||
nil | ||
elsif host[0] != ?/ | ||
"tcp://#{ host }:#{ port }" | ||
else | ||
"unix:#{ host }/.s.PGSQL.#{ port }" | ||
end | ||
|
||
@db = database | ||
@conn = PostgresPR::Connection.new(database, user, auth, uri) | ||
end | ||
|
||
attr_reader :db | ||
|
||
def query(sql) | ||
PGresult.new(@conn.query(sql)) | ||
end | ||
|
||
alias exec query | ||
end | ||
|
||
class PGresult | ||
attr_reader :fields, :result | ||
|
||
def initialize(res) | ||
@res = res | ||
@fields = @res.fields.map {|f| f.name} | ||
@result = @res.rows | ||
end | ||
|
||
include Enumerable | ||
|
||
def each(&block) | ||
@result.each(&block) | ||
end | ||
|
||
def [](index) | ||
@result[index] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters