Skip to content

Commit e018fcd

Browse files
authored
docs(supabase): provide info for connecting to Supabase postgres (#397)
1 parent 7bcb422 commit e018fcd

File tree

1 file changed

+53
-28
lines changed

1 file changed

+53
-28
lines changed

docs/docs/core/initialization.mdx

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
---
22
title: Initialization
3-
description: Initialize the CocoIndex library
3+
description: Initialize and set environment for CocoIndex library
44
---
55

66
import Tabs from '@theme/Tabs';
77
import TabItem from '@theme/TabItem';
88

99
# Initialize the CocoIndex Library
1010

11-
Before everything starts, the `cocoindex` library needs to be initialized with settings.
12-
There're two options to do this:
11+
Before everything starts, the CocoIndex library needs to be initialized with settings.
12+
We'll talk about the code skeleton to initialize the library in your code, and the way to provide settings for CocoIndex.
1313

14-
* Using packaged main function. It's easier to start with.
14+
## Initialize the library
15+
16+
There're two options to initialize in your code:
17+
18+
* Use packaged main function. It's easier to start with.
1519
* Explicit initialization. It's more flexible.
1620

17-
## Using Packaged Main
21+
### Packaged Main
1822

1923
The easiest way is to use a packaged main function:
2024

@@ -45,33 +49,13 @@ This takes care of the following effects:
4549
See [CocoIndex CLI](/docs/core/cli) for more details.
4650
3. Otherwise, it will run the main function.
4751

48-
### Environment Variables
49-
50-
The following environment variables are supported:
52+
See [Environment Variables](#environment-variables) for supported environment variables.
5153

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

56-
## Explicit Initialization
55+
### Explicit Initialization
5756

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

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-
* `url` (type: `str`, required): The URL 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 `url`.
71-
* `password` (type: `str`, optional): The password for the Postgres database. If not provided, password will come from `url`.
72-
73-
### Example
74-
7559
<Tabs>
7660
<TabItem value="python" label="Python" default>
7761

@@ -93,4 +77,45 @@ if __name__ == "__main__":
9377
```
9478

9579
</TabItem>
96-
</Tabs>
80+
</Tabs>
81+
82+
## Settings
83+
84+
`cocoindex.Settings` is used to configure the CocoIndex library. It's a dataclass that contains the following fields:
85+
86+
* `database` (type: `DatabaseConnectionSpec`, required): The connection to the Postgres database.
87+
88+
### DatabaseConnectionSpec
89+
90+
`DatabaseConnectionSpec` configures the connection to a database. Only Postgres is supported for now. It has the following fields:
91+
92+
* `url` (type: `str`, required): The URL of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`.
93+
* `user` (type: `str`, optional): The username for the Postgres database. If not provided, username will come from `url`.
94+
* `password` (type: `str`, optional): The password for the Postgres database. If not provided, password will come from `url`.
95+
96+
:::tip
97+
98+
Please be careful that all values in `url` needs to be url-encoded if they contain special characters.
99+
For this reason, prefer to use the separated `user` and `password` fields for username and password.
100+
101+
:::
102+
103+
:::info
104+
105+
If you use the Postgres database hosted by [Supabase](https://supabase.com/), please click **Connect** on your project dashboard and find the following URL:
106+
107+
* If you're on a IPv6 network, use the URL under **Direct connection**. You can visit [IPv6 test](https://test-ipv6.com/) to see if you have IPv6 Internet connection.
108+
* Otherwise, use the URL under **Session pooler**.
109+
110+
:::
111+
112+
## Environment Variables
113+
114+
When you use the packaged main function, settings will be loaded from environment variables.
115+
Each setting field has a corresponding environment variable:
116+
117+
| environment variable | corresponding field in `Settings` | required? |
118+
|---------------------|-------------------|----------|
119+
| `COCOINDEX_DATABASE_URL` | `database.url` | Yes |
120+
| `COCOINDEX_DATABASE_USER` | `database.user` | No |
121+
| `COCOINDEX_DATABASE_PASSWORD` | `database.password` | No |

0 commit comments

Comments
 (0)