Re: [Pharo-users] Pharo connect to PostgreSQL

2020-01-20 Thread Sven Van Caekenberghe
Hi,

You are not saying which library/framework you are trying to use.

One up to date option is P3, the "lean and mean PostgreSQL client for Pharo " [ 
https://github.com/svenvc/P3 ].

A connection to your database could then be specified using a URL.

To test the connection:

(P3Client url: 'psql://postgres:lucian@localhost:5432/mydb') in: [ :client | [ 
client isWorking ] ensure: [ client close ] ].

To do a query:

(P3Client url: 'psql://postgres:lucian@localhost:5432/mydb') in: [ :client | [ 
(client query: 'SELECT * FROM some_table') recordsAsDictionaries ] ensure: [ 
client close ] ].

Of course, you first have to make sure external clients can connect to your db 
(try the psql command line client over TCP first).

HTH,

Sven

Apart from https://postgresql.org, the following site is pretty good: 
https://www.postgresqltutorial.com. On macOS, I recommend 
https://postgresapp.com.

> On 20 Jan 2020, at 12:37, Macmus via Pharo-users 
>  wrote:
> 
> 
> From: Macmus 
> Subject: Pharo connect to PostgreSQL
> Date: 20 January 2020 at 12:37:13 GMT+1
> To: pharo-users@lists.pharo.org
> 
> 
> I am trying to connect to a PostgreSQL database from Pharo but I keep getting
> "SubscriptOutOfBounds: 11" error (I am a beginner). The server is started
> and the database is working fine. What am I missing?
> 
> 
> |connectionArguments connection resultSets resultSet rows firstRow|
> 
> connectionArguments := PG3ConnectionArguments new 
>   hostname: 'localhost'; 
>   port: 5432; 
>   username: 'postgres'; 
>   password: 'lucian'; 
>   databaseName: 'mydb' 
>   yourself.
> connection := connectionArguments newConnection. 
> 
> connection startup.
> 
> resultSets := connection execute: 'select 3 + 4, now()'. 
> resultSet := resultSets first.
> rows := resultSet rows.
> firstRow := rows first.
> firstRow at: 1.
> firstRow at: 2.
> 
> connection terminate.
> 
> 
> 
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
> 
> 
> 




[Pharo-users] Pharo connect to PostgreSQL

2020-01-20 Thread Macmus via Pharo-users
--- Begin Message ---
I am trying to connect to a PostgreSQL database from Pharo but I keep getting
"SubscriptOutOfBounds: 11" error (I am a beginner). The server is started
and the database is working fine. What am I missing?


|connectionArguments connection resultSets resultSet rows firstRow|

connectionArguments := PG3ConnectionArguments new 
hostname: 'localhost'; 
port: 5432; 
username: 'postgres'; 
password: 'lucian'; 
databaseName: 'mydb' 
yourself.
connection := connectionArguments newConnection. 

connection startup.

resultSets := connection execute: 'select 3 + 4, now()'. 
resultSet := resultSets first.
rows := resultSet rows.
firstRow := rows first.
firstRow at: 1.
firstRow at: 2.

connection terminate.



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

--- End Message ---