njlg / perl-rethinkdb

A Pure Perl RethinkDB Driver
http://njlg.info/perl-rethinkdb
Artistic License 2.0
22 stars 5 forks source link

Working with Rethinkdb #21

Closed vorobeez closed 9 years ago

vorobeez commented 9 years ago

Hello. I was tried to use your driver. But i failed. Can you help me, please?

#!/usr/bin/perl

package Bookmarks::Storage;

use warnings;
use strict;
use 5.010;

use Rethinkdb;

my $io = r->io;
r->io(Rethinkdb::IO->new);

r->connect('localhost', 8080);
r->db('test')->table('test_table')->create->run;
r->close;

1;

I am noob at perl and not familiar with that kind of drivers. What does mean io attribute? And why is my script freezes when i performing it? What i did wrong?

njlg commented 9 years ago

Thanks for checking out the driver!

If you are running RethinkDB on localhost:8080 then try this:

r->connect('localhost', 8080)->repl;
r->db('test')->create->run;
r->db('test')->table('test_table')->create->run;
r->db('test')->table('test_table')->insert([
  id => 1,
  name => 'test',
])->run;

If you use the repl method, it will keep track of your initial connection for you. Otherwise, just run my $io = r->connect(); and pass $io to all of the run methods. E.g.

my $io r->connect('localhost', 8080);
my $res = r->db('test')->table('test_table')->run($io);
say Dumper $res;

If you want to see the messages from the database (errors, success, etc) just look at the return value from any of the queries.

vorobeez commented 9 years ago

@njlg, greetings!

here is my script:

#!/usr/bin/perl

use warnings;
use strict;
use 5.022;

use Rethinkdb;

my $log;
open $log, '>', 'logfile';

my $res_connect = r->connect('localhost', 8080)->repl;
say $log $res_connect;

my $res_db_create = r->db('test')->create->run;
say $log $res_db_create;

my $res_table_create = r->db('test')->table('test_table')->create->run;
say $log $res_table_create;

my $res_row_insert = r->db('test')->table('test_table')->insert([
    id => 1,
    name => 'test',
])->run;
say $log $res_row_insert;

close $log;

I have the same problem. My script just freezes, no changes in database and logfile is empty.

njlg commented 9 years ago

Do you know for a fact that you are running RethinkDB on port 8080? By default it listens for database connections on port 28015. I believe that when you make a connection to the web interface, it will accept the connection but never respond. (Which might be a good issue for me to look into)

vorobeez commented 9 years ago

@njlg, Thank you very much for your help and for your wasted time. Sorry for my inattention =/ (Now everything work fine)

njlg commented 9 years ago

Great. No problem. Glad you are trying the driver out.