Skip to content

Commit c7f6fbc

Browse files
authored
docs(postgres): configure db username/password separately (#394)
1 parent 08655cb commit c7f6fbc

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

docs/docs/core/initialization.mdx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,29 @@ This takes care of the following effects:
4949

5050
The following environment variables are supported:
5151

52-
* `COCOINDEX_DATABASE_URL`: The URL of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`
52+
* `COCOINDEX_DATABASE_URL` (required): The URI of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`
53+
* `COCOINDEX_DATABASE_USER` (optional): The username for the Postgres database. If not provided, username will come from `COCOINDEX_DATABASE_URL`.
54+
* `COCOINDEX_DATABASE_PASSWORD` (optional): The password for the Postgres database. If not provided, password will come from `COCOINDEX_DATABASE_URL`.
5355

5456
## Explicit Initialization
5557

5658
Alternatively, for flexibility, you can also explicitly initialize the library by the `init()` function:
5759

60+
### Settings
61+
62+
It takes a `Settings` object as argument, which is a dataclass that contains the following fields:
63+
64+
* `database` (type: `DatabaseConnectionSpec`, required): The connection to the Postgres database.
65+
66+
#### DatabaseConnectionSpec
67+
68+
`DatabaseConnectionSpec` has the following fields:
69+
* `uri` (type: `str`, required): The URI of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`.
70+
* `user` (type: `str`, optional): The username for the Postgres database. If not provided, username will come from `uri`.
71+
* `password` (type: `str`, optional): The password for the Postgres database. If not provided, password will come from `uri`.
72+
73+
### Example
74+
5875
<Tabs>
5976
<TabItem value="python" label="Python" default>
6077

@@ -63,7 +80,11 @@ import cocoindex
6380

6481
def main():
6582
...
66-
cocoindex.init(cocoindex.Settings(database_url="postgres://cocoindex:cocoindex@localhost/cocoindex"))
83+
cocoindex.init(
84+
cocoindex.Settings(
85+
database=cocoindex.DatabaseConnectionSpec(
86+
uri="postgres://cocoindex:cocoindex@localhost/cocoindex"
87+
)))
6788
...
6889

6990
...

docs/docs/ops/storages.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ It should be a unique table, meaning that no other export target should export t
3636

3737
The spec takes the following fields:
3838

39-
* `database_url` (type: `str`, optional): The URL of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`. If unspecified, will use the same database as the [internal storage](/docs/core/basics#internal-storage).
39+
* `database` (type: [auth reference](../core/flow_def#auth-registry) to `DatabaseConnectionSpec`, optional): The connection to the Postgres database.
40+
See [DatabaseConnectionSpec](../core/initialization#databaseconnectionspec) for its specific fields.
41+
If not provided, will use the same database as the [internal storage](/docs/core/basics#internal-storage).
4042

4143
* `table_name` (type: `str`, optional): The name of the table to store to. If unspecified, will generate a new automatically. We recommend specifying a name explicitly if you want to directly query the table. It can be omitted if you want to use CocoIndex's query handlers to query the table.
4244

0 commit comments

Comments
 (0)