diff --git a/docs/docs/core/initialization.mdx b/docs/docs/core/initialization.mdx index 2d5b83462..0c9e54c15 100644 --- a/docs/docs/core/initialization.mdx +++ b/docs/docs/core/initialization.mdx @@ -49,12 +49,29 @@ This takes care of the following effects: The following environment variables are supported: -* `COCOINDEX_DATABASE_URL`: The URL of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex` +* `COCOINDEX_DATABASE_URL` (required): The URI of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex` +* `COCOINDEX_DATABASE_USER` (optional): The username for the Postgres database. If not provided, username will come from `COCOINDEX_DATABASE_URL`. +* `COCOINDEX_DATABASE_PASSWORD` (optional): The password for the Postgres database. If not provided, password will come from `COCOINDEX_DATABASE_URL`. ## Explicit Initialization Alternatively, for flexibility, you can also explicitly initialize the library by the `init()` function: +### Settings + +It takes a `Settings` object as argument, which is a dataclass that contains the following fields: + +* `database` (type: `DatabaseConnectionSpec`, required): The connection to the Postgres database. + +#### DatabaseConnectionSpec + +`DatabaseConnectionSpec` has the following fields: +* `uri` (type: `str`, required): The URI of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`. +* `user` (type: `str`, optional): The username for the Postgres database. If not provided, username will come from `uri`. +* `password` (type: `str`, optional): The password for the Postgres database. If not provided, password will come from `uri`. + +### Example + @@ -63,7 +80,11 @@ import cocoindex def main(): ... - cocoindex.init(cocoindex.Settings(database_url="postgres://cocoindex:cocoindex@localhost/cocoindex")) + cocoindex.init( + cocoindex.Settings( + database=cocoindex.DatabaseConnectionSpec( + uri="postgres://cocoindex:cocoindex@localhost/cocoindex" + ))) ... ... diff --git a/docs/docs/ops/storages.md b/docs/docs/ops/storages.md index de4efd0be..fa88ba8ac 100644 --- a/docs/docs/ops/storages.md +++ b/docs/docs/ops/storages.md @@ -36,7 +36,9 @@ It should be a unique table, meaning that no other export target should export t The spec takes the following fields: -* `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). +* `database` (type: [auth reference](../core/flow_def#auth-registry) to `DatabaseConnectionSpec`, optional): The connection to the Postgres database. + See [DatabaseConnectionSpec](../core/initialization#databaseconnectionspec) for its specific fields. + If not provided, will use the same database as the [internal storage](/docs/core/basics#internal-storage). * `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.