I'm trying to connect to a remote PostgreSQL database server using the prodigy.components.db.connect
method, as Ines advised in her reply to Post #108. When using prodigy.json to configure the db settings, all works well. But I'm unable to connect manually (e.g. from a custom recipe). The post is split into three parts (1) shares the (fake) database settings, (2) shows what works, (3) shows what doesn't work.
§1. Database
Suppose there is an accessible, remote PostgreSQL server with the following settings:
'host': 'db.com'
'dbname': 'prodigy'
'user': 'user'
'password': 'password'
§2. What works
When I add those settings to prodigy.json, the connection is established and I'm able to view the available datasets.
# prodigy.json
{
"db": "postgresql",
"db_settings": {
"postgresql": {
"host": "db.com",
"dbname": "prodigy",
"user": "user",
"password": "password"
}
}
}
# terminal
>>> from prodigy.components.db import connect
>>> db = connect()
>>> db.datasets
['', 'dataset_1', 'dataset_2'] # <-- Great!
§3. What does not work
When I remove those settings from prodigy.json, and repeat the same steps, something goes wrong. I can't figure out what I'm missing.
# prodigy.json
{
# ...nothing on 'db'...
}
# terminal
>>> from prodigy.components.db import connect
>>> db = connect('postgresql', {
'host': 'db.com', # <-- see (Note 1)
'dbname': 'prodigy',
'user': 'user',
'password': 'password'})
>>> db.datasets
[] # <-- Not great
Note 1. Ines didn't mention the host
entry in her response to Post #108, but I've added it here because otherwise I don't see how connect
will know about the db server address. I did try adding just the host
to prodigy.json, leaving the dbname, user, password
to be specified in the recipe. But no success there.
I'd dig a little more into this before posting, but the documentation is light on this topic (only PRODIGY_README.html#postgresql
seems relevant, but doesn't help) and the source for what exactly db.connect
does seems to be unavailable. Any help would be much appreciated.