Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/docs/core/initialization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ This takes care of the following effects:

The following environment variables are supported:

* `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_URL` (required): The URL 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`.

Expand All @@ -66,9 +66,9 @@ It takes a `Settings` object as argument, which is a dataclass that contains the
#### 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`.
* `url` (type: `str`, required): The URL 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 `url`.
* `password` (type: `str`, optional): The password for the Postgres database. If not provided, password will come from `url`.

### Example

Expand All @@ -83,7 +83,7 @@ def main():
cocoindex.init(
cocoindex.Settings(
database=cocoindex.DatabaseConnectionSpec(
uri="postgres://cocoindex:cocoindex@localhost/cocoindex"
url="postgres://cocoindex:cocoindex@localhost/cocoindex"
)))
...

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/ops/storages.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ Please read and agree the license before starting the instance.
The `Neo4j` storage exports each row as a relationship to Neo4j Knowledge Graph. The spec takes the following fields:

* `connection` (type: [auth reference](../core/flow_def#auth-registry) to `Neo4jConnectionSpec`): The connection to the Neo4j database. `Neo4jConnectionSpec` has the following fields:
* `uri` (type: `str`): The URI of the Neo4j database to use as the internal storage, e.g. `bolt://localhost:7687`.
* `url` (type: `str`): The URI of the Neo4j database to use as the internal storage, e.g. `bolt://localhost:7687`.
* `user` (type: `str`): Username for the Neo4j database.
* `password` (type: `str`): Password for the Neo4j database.
* `db` (type: `str`, optional): The name of the Neo4j database to use as the internal storage, e.g. `neo4j`.
Expand Down
4 changes: 2 additions & 2 deletions python/cocoindex/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _load_field(target: dict[str, str], name: str, env_name: str, required: bool

@dataclass
class DatabaseConnectionSpec:
uri: str
url: str
user: str | None = None
password: str | None = None

Expand All @@ -38,7 +38,7 @@ def from_env(cls) -> Self:
"""Load settings from environment variables."""

db_kwargs: dict[str, str] = dict()
_load_field(db_kwargs, "uri", "COCOINDEX_DATABASE_URL", required=True)
_load_field(db_kwargs, "url", "COCOINDEX_DATABASE_URL", required=True)
_load_field(db_kwargs, "user", "COCOINDEX_DATABASE_USER")
_load_field(db_kwargs, "password", "COCOINDEX_DATABASE_PASSWORD")
database = DatabaseConnectionSpec(**db_kwargs)
Expand Down
4 changes: 2 additions & 2 deletions src/lib_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ pub struct DbPools {
impl DbPools {
pub async fn get_pool(&self, conn_spec: &settings::DatabaseConnectionSpec) -> Result<PgPool> {
let db_pool_cell = {
let key = (conn_spec.uri.clone(), conn_spec.user.clone());
let key = (conn_spec.url.clone(), conn_spec.user.clone());
let mut db_pools = self.pools.lock().unwrap();
db_pools.entry(key).or_default().clone()
};
let pool = db_pool_cell
.get_or_try_init(|| async move {
let mut pg_options: PgConnectOptions = conn_spec.uri.parse()?;
let mut pg_options: PgConnectOptions = conn_spec.url.parse()?;
if let Some(user) = &conn_spec.user {
pg_options = pg_options.username(user);
}
Expand Down
2 changes: 1 addition & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::Deserialize;

#[derive(Deserialize, Debug)]
pub struct DatabaseConnectionSpec {
pub uri: String,
pub url: String,
pub user: Option<String>,
pub password: Option<String>,
}
Expand Down