Re: [Pharo-users] Pharo connect to PostgreSQL
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 <pharo-users@lists.pharo.org> wrote:
From: Macmus <luci.barcan@yahoo.com> 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
participants (1)
-
Sven Van Caekenberghe