[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] postgres-pr (pure Ruby PostgreSQL

Michael Neumann

11/18/2004 3:12:00 PM

Hi,

I'm proud to announce the first public "release" of postgres-pr. This is
a library to access PostgreSQL from Ruby without the need of any C
library.

* You can use it only with newer 7.x databases that use wire-protocol 3.
* Lot's of stuff is missing, only the wire-protocol is quite complete.

Quick Example:

> gem install postgres-pr
> irb -r rubygems

Then in the interactive Ruby interpreter type (replace DBNAME and DBUSER
accordingly):

require 'postgres-pr/connection'
c = Connection.new('DBNAME', 'DBUSER')
c.query('SELECT 1+2') # => [["3"]]

Regards,

Michael


29 Answers

David Ross

11/18/2004 4:26:00 PM

0

Michael Neumann wrote:

> Hi,
>
> I'm proud to announce the first public "release" of postgres-pr. This
> is a library to access PostgreSQL from Ruby without the need of any C
> library.
>
> * You can use it only with newer 7.x databases that use wire-protocol 3.
> * Lot's of stuff is missing, only the wire-protocol is quite complete.
>
> Quick Example:
>
> > gem install postgres-pr
> > irb -r rubygems
>
> Then in the interactive Ruby interpreter type (replace DBNAME and DBUSER
> accordingly):
>
> require 'postgres-pr/connection'
> c = Connection.new('DBNAME', 'DBUSER')
> c.query('SELECT 1+2') # => [["3"]]
>
> Regards,
>
> Michael
>
>
oh neato. I'm glad someone made a pure ruby version.

Is there an rpa?

David Ross



Michael Neumann

11/18/2004 4:44:00 PM

0

David Ross wrote:
> Michael Neumann wrote:
>
>> Hi,
>>
>> I'm proud to announce the first public "release" of postgres-pr. This
>> is a library to access PostgreSQL from Ruby without the need of any C
>> library.
>>
>> * You can use it only with newer 7.x databases that use wire-protocol 3.
>> * Lot's of stuff is missing, only the wire-protocol is quite complete.
>>
>> Quick Example:
>>
>> > gem install postgres-pr
>> > irb -r rubygems
>>
>> Then in the interactive Ruby interpreter type (replace DBNAME and DBUSER
>> accordingly):
>>
>> require 'postgres-pr/connection'
>> c = Connection.new('DBNAME', 'DBUSER')
>> c.query('SELECT 1+2') # => [["3"]]
>>
>> Regards,
>>
>> Michael
>>
>>
> oh neato. I'm glad someone made a pure ruby version.
>
> Is there an rpa?

nope. maybe later, if it's better tested.

Regards,

Michael


David Ross

11/18/2004 5:08:00 PM

0

Michael Neumann wrote:

> David Ross wrote:
>
>> Michael Neumann wrote:
>>
>>> Hi,
>>>
>>> I'm proud to announce the first public "release" of postgres-pr.
>>> This is a library to access PostgreSQL from Ruby without the need of
>>> any C
>>> library.
>>>
>>> * You can use it only with newer 7.x databases that use
>>> wire-protocol 3.
>>> * Lot's of stuff is missing, only the wire-protocol is quite complete.
>>>
>>> Quick Example:
>>>
>>> > gem install postgres-pr
>>> > irb -r rubygems
>>>
>>> Then in the interactive Ruby interpreter type (replace DBNAME and
>>> DBUSER
>>> accordingly):
>>>
>>> require 'postgres-pr/connection'
>>> c = Connection.new('DBNAME', 'DBUSER')
>>> c.query('SELECT 1+2') # => [["3"]]
>>>
>>> Regards,
>>>
>>> Michael
>>>
>>>
>> oh neato. I'm glad someone made a pure ruby version.
>>
>> Is there an rpa?
>
>
> nope. maybe later, if it's better tested.
>
> Regards,
>
> Michael
>
>
Maybe I'll throw it together then for batsman, I *love* postgres with a
passion, and was going to use postgres as a backend for my project. I'm
glad theres a pure ruby version, people hate compiling. Thanks a kilo
Neumann

Ross
--
Hazzle free packages for Ruby?
RPA is available from http://www.rubyar...



Michael Neumann

11/18/2004 5:45:00 PM

0

David Ross wrote:
> Maybe I'll throw it together then for batsman, I *love* postgres with a
> passion, and was going to use postgres as a backend for my project. I'm
> glad theres a pure ruby version, people hate compiling. Thanks a kilo
> Neumann

btw, I quickly hacked up a compat-library, so that you can use the
postgres-ActiveRecord adaptor. It thinks, it uses the C version of
postgres (and indeed loads it if it's available).

I was to lazy to rewrite the whole adaptor...

Regards,

Michael


Michael Neumann

11/18/2004 6:05:00 PM

0

Michael Neumann wrote:
> David Ross wrote:
>
>> Maybe I'll throw it together then for batsman, I *love* postgres with
>> a passion, and was going to use postgres as a backend for my project.
>> I'm glad theres a pure ruby version, people hate compiling. Thanks a
>> kilo Neumann
>
>
> btw, I quickly hacked up a compat-library, so that you can use the
> postgres-ActiveRecord adaptor. It thinks, it uses the C version of
> postgres (and indeed loads it if it's available).

it's now available as postgres-pr version 0.1.0. If you've installed
this and ActiveRecord, it should work out-of-the-box.

Regards,

Michael


Scott Barron

11/18/2004 6:47:00 PM

0

On Fri, 19 Nov 2004 03:04:35 +0900, Michael Neumann <mneumann@ntecs.de> wrote:
> Michael Neumann wrote:
>
> it's now available as postgres-pr version 0.1.0. If you've installed
> this and ActiveRecord, it should work out-of-the-box.
>
> Regards,
>
> Michael

Michael,

Very sweet! I'm playing with it and I've hit a few points of
incompatibility so far.

First up, AR will allow you to leave out the host for the postgresql adapter,
which effectively tells the postgres module to use the unix socket. Your
library seems to require it to be set to /dir for the directory the socket file
resides in. I rather prefer your method, but any existing Rails apps would
have to change.

Next, AR is expecting that PGResult have []. Mapping this to
@rows.res seems to fix the problem.

Next, your library doesn't seem to like integers that are quoted (eg
UPDATE foo set bar='' where id='1') and this makes a number of AR's
unit tests fail.

Finally, I haven't tracked down this problem just yet, but the AR unit
tests give a good deal of errors very similar to this one:

test_create(BasicsTest):
NoMethodError: undefined method `title=' for #<Topic:0x1027888
@attributes={}, @new_record=true>
./test/../lib/active_record/base.rb:817:in `method_missing'
./test/base_test.rb:108:in `test_create'

Where it is always failing on a method foo= for an AR class.

Using my own project, postgres-pr works out of the box, but the real
test seems to be making the AR unit tests pass. I'm really glad you
started this project, a gemmed, pure ruby postgres adapter will make
my life easier in a number of ways. Thanks!

-Scott


Tom Copeland

11/18/2004 7:27:00 PM

0

On Thu, 2004-11-18 at 13:47, Scott Barron wrote:
> I'm really glad you
> started this project, a gemmed, pure ruby postgres adapter will make
> my life easier in a number of ways. Thanks!

Let me add my thanks, too. I can see this library getting lots of heavy
usage for my Ruby scripts for admin'ing RubyForge; currently I'm doing
things like exec'ing "psql -c" :-)

Thanks,

Tom



Michael Neumann

11/18/2004 8:31:00 PM

0

Scott Barron wrote:
> On Fri, 19 Nov 2004 03:04:35 +0900, Michael Neumann <mneumann@ntecs.de> wrote:
>
>>Michael Neumann wrote:
>>
>>it's now available as postgres-pr version 0.1.0. If you've installed
>>this and ActiveRecord, it should work out-of-the-box.
>>
>>Regards,
>>
>> Michael
>
>
> Michael,
>
> Very sweet! I'm playing with it and I've hit a few points of
> incompatibility so far.
>
> First up, AR will allow you to leave out the host for the postgresql adapter,
> which effectively tells the postgres module to use the unix socket. Your
> library seems to require it to be set to /dir for the directory the socket file
> resides in. I rather prefer your method, but any existing Rails apps would
> have to change.

fixed!

> Next, AR is expecting that PGResult have []. Mapping this to
> @rows.res seems to fix the problem.

fixed!

> Next, your library doesn't seem to like integers that are quoted (eg
> UPDATE foo set bar='' where id='1') and this makes a number of AR's
> unit tests fail.

fixed!

> Finally, I haven't tracked down this problem just yet, but the AR unit
> tests give a good deal of errors very similar to this one:
>
> test_create(BasicsTest):
> NoMethodError: undefined method `title=' for #<Topic:0x1027888
> @attributes={}, @new_record=true>
> ./test/../lib/active_record/base.rb:817:in `method_missing'
> ./test/base_test.rb:108:in `test_create'
>
> Where it is always failing on a method foo= for an AR class.

I've run the test cases. of the 717 assertions, I get only 10 errors,
but they seem to be not postgres-pr specific. I've appended the output
of the test-cases at this email. Maybe someone can take a look at it.

I've released 0.1.1 which fixes all those bugs (except the remaining
10). Update the gem and run the test-cases.

Regards,

Michael
Using native PostgreSQL
Loaded suite -e
Started
........................................................................................................................................................................................................................EEEEEEEEEE.................
Finished in 9.688505 seconds.

1) Error:
test_string_key(PrimaryKeysTest):
RuntimeError: #<ErrorResponse:0x8510570 @field_type=83, @field_values=["ERROR", "C42P01", "Mrelation \"subscribers_nick_seq\" does not exist", "Fnamespace.c", "L193", "RRangeVarGetRelid"]>
/home/mneumann/Programs/usr/lib/ruby/gems/1.8/gems/postgres-pr-0.1.0/lib/postgres-pr/connection.rb:81:in `query'
/home/mneumann/Programs/usr/lib/ruby/gems/1.8/gems/postgres-pr-0.1.0/lib/postgres-pr/connection.rb:66:in `loop'
/home/mneumann/Programs/usr/lib/ruby/gems/1.8/gems/postgres-pr-0.1.0/lib/postgres-pr/connection.rb:66:in `query'
/home/mneumann/Programs/usr/lib/ruby/gems/1.8/gems/postgres-pr-0.1.0/lib/postgres-pr/connection.rb:61:in `synchronize'
/home/mneumann/Programs/usr/lib/ruby/gems/1.8/gems/postgres-pr-0.1.0/lib/postgres-pr/connection.rb:61:in `query'
/home/mneumann/Programs/usr/lib/ruby/gems/1.8/gems/postgres-pr-0.1.0/lib/postgres.rb:30:in `exec'
./../lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `last_insert_id'
./../lib/active_record/connection_adapters/postgresql_adapter.rb:60:in `insert'
./../lib/active_record/base.rb:776:in `create_without_callbacks'
./../lib/active_record/callbacks.rb:235:in `create'
./../lib/active_record/base.rb:761:in `create_or_update_without_callbacks'
./../lib/active_record/callbacks.rb:224:in `create_or_update'
./../lib/active_record/base.rb:647:in `save_without_validation'
./../lib/active_record/validations.rb:55:in `save_without_transactions'
./../lib/active_record/transactions.rb:115:in `save'
./../lib/active_record/transactions.rb:115:in `transaction'
./../lib/active_record/transactions.rb:86:in `transaction'
./../lib/active_record/transactions.rb:100:in `transaction'
./../lib/active_record/transactions.rb:115:in `save'
./pk_test.rb:37:in `test_string_key'

2) Error:
test_aggregation_reflection(ReflectionTest):
ActiveRecord::RecordNotFound: Couldn't find Topic with ID = 1
./../lib/active_record/base.rb:242:in `find'
./reflection_test.rb:13:in `setup_without_fixtures'
./../lib/active_record/fixtures.rb:242:in `setup'
./../lib/active_record/fixtures.rb:240:in `setup'

3) Error:
test_association_reflection(ReflectionTest):
ActiveRecord::RecordNotFound: Couldn't find Topic with ID = 1
./../lib/active_record/base.rb:242:in `find'
./reflection_test.rb:13:in `setup_without_fixtures'
./../lib/active_record/fixtures.rb:242:in `setup'
./../lib/active_record/fixtures.rb:240:in `setup'

4) Error:
test_association_reflection_in_modules(ReflectionTest):
ActiveRecord::RecordNotFound: Couldn't find Topic with ID = 1
./../lib/active_record/base.rb:242:in `find'
./reflection_test.rb:13:in `setup_without_fixtures'
./../lib/active_record/fixtures.rb:242:in `setup'
./../lib/active_record/fixtures.rb:240:in `setup'

5) Error:
test_column_string_type_and_limit(ReflectionTest):
ActiveRecord::RecordNotFound: Couldn't find Topic with ID = 1
./../lib/active_record/base.rb:242:in `find'
./reflection_test.rb:13:in `setup_without_fixtures'
./../lib/active_record/fixtures.rb:242:in `setup'
./../lib/active_record/fixtures.rb:240:in `setup'

6) Error:
test_columns(ReflectionTest):
ActiveRecord::RecordNotFound: Couldn't find Topic with ID = 1
./../lib/active_record/base.rb:242:in `find'
./reflection_test.rb:13:in `setup_without_fixtures'
./../lib/active_record/fixtures.rb:242:in `setup'
./../lib/active_record/fixtures.rb:240:in `setup'

7) Error:
test_content_columns(ReflectionTest):
ActiveRecord::RecordNotFound: Couldn't find Topic with ID = 1
./../lib/active_record/base.rb:242:in `find'
./reflection_test.rb:13:in `setup_without_fixtures'
./../lib/active_record/fixtures.rb:242:in `setup'
./../lib/active_record/fixtures.rb:240:in `setup'

8) Error:
test_human_name_for_column(ReflectionTest):
ActiveRecord::RecordNotFound: Couldn't find Topic with ID = 1
./../lib/active_record/base.rb:242:in `find'
./reflection_test.rb:13:in `setup_without_fixtures'
./../lib/active_record/fixtures.rb:242:in `setup'
./../lib/active_record/fixtures.rb:240:in `setup'

9) Error:
test_integer_columns(ReflectionTest):
ActiveRecord::RecordNotFound: Couldn't find Topic with ID = 1
./../lib/active_record/base.rb:242:in `find'
./reflection_test.rb:13:in `setup_without_fixtures'
./../lib/active_record/fixtures.rb:242:in `setup'
./../lib/active_record/fixtures.rb:240:in `setup'

10) Error:
test_read_attribute_names(ReflectionTest):
ActiveRecord::RecordNotFound: Couldn't find Topic with ID = 1
./../lib/active_record/base.rb:242:in `find'
./reflection_test.rb:13:in `setup_without_fixtures'
./../lib/active_record/fixtures.rb:242:in `setup'
./../lib/active_record/fixtures.rb:240:in `setup'

243 tests, 717 assertions, 0 failures, 10 errors

Scott Barron

11/18/2004 9:06:00 PM

0

On Fri, 19 Nov 2004 05:31:20 +0900, Michael Neumann <mneumann@ntecs.de> wrote:
> fixed!
> fixed!
> fixed!

Outstanding!

> I've run the test cases. of the 717 assertions, I get only 10 errors,
> but they seem to be not postgres-pr specific. I've appended the output
> of the test-cases at this email. Maybe someone can take a look at it.
>
> I've released 0.1.1 which fixes all those bugs (except the remaining
> 10). Update the gem and run the test-cases.

I just updated to 0.1.1 and ran the tests from AR CVS and they all
passed (well, see below).

> 1) Error:
> test_string_key(PrimaryKeysTest):
> RuntimeError: #<ErrorResponse:0x8510570 @field_type=83, @field_values=["ERROR", "C42P01", "Mrelation \"subscribers_nick_seq\" does not exist", "Fnamespace.c", "L193", "RRangeVarGetRelid"]>

... This one I still get but I believe it is a bug in the tests, not
your library (it happens with the C postgres extension as well). It
seems AR is looking for an auto increment sequence on a table using a
text primary key. Haven't looked at it much futher yet.

> 2) Error:
> test_aggregation_reflection(ReflectionTest):
> ActiveRecord::RecordNotFound: Couldn't find Topic with ID = 1
> ./../lib/active_record/base.rb:242:in `find'
> ./reflection_test.rb:13:in `setup_without_fixtures'
> ./../lib/active_record/fixtures.rb:242:in `setup'
> ./../lib/active_record/fixtures.rb:240:in `setup'

I was getting these with 0.1.0 but now I'm not with 0.1.1. They seem
to be working now. This rocks out loud.

-Scott


David Garamond

11/19/2004 7:43:00 AM

0

David Ross wrote:
> Michael Neumann wrote:
> oh neato. I'm glad someone made a pure ruby version.

ditto here. a wonderful news. i think i'm going to try to use it on a
regular basis instead of the "postgres" C-based library, solely because
only postgres-pr is available as a gem (yes, i'm that lazy :-). i use
ruby on lots of machines...

> Is there an rpa?

i thought the purpose of RPA is as a collection of _production_-level
(mostly mature, stable, well tested) libraries?

--
dave