Summary
This connector reads the result of a SQL query from a Postgres database and turns each row into a document in a Moss search index.
It uses psycopg (version 3) for the connection, so it works against any Postgres-compatible database — Postgres itself, Neon, Supabase (via direct URL), CockroachDB, Amazon RDS, Timescale, and pgvector.
To get started
- Read
_template/README.md.
- Copy the template:
cd packages/moss-data-connector
cp -r _template moss-connector-postgres
cd moss-connector-postgres
- Rename
TemplateConnector → PostgresConnector in src/connector.py, update src/__init__.py to re-export it, and fill in pyproject.toml.
- Implement
__iter__ using psycopg. Set row_factory=dict_row so rows come back as dicts instead of tuples.
Deliverables
The caller should be able to write:
from moss_connector_postgres import PostgresConnector, ingest
from moss import DocumentInfo
source = PostgresConnector(
dsn="postgresql://user:pass@host:5432/dbname",
query="SELECT id, title, body FROM articles",
mapper=lambda row: DocumentInfo(
id=str(row["id"]),
text=row["body"],
metadata={"title": row["title"]},
),
)
await ingest(source, project_id="...", project_key="...", index_name="articles")
Files:
Required for review / PR acceptance
Summary
This connector reads the result of a SQL query from a Postgres database and turns each row into a document in a Moss search index.
It uses
psycopg(version 3) for the connection, so it works against any Postgres-compatible database — Postgres itself, Neon, Supabase (via direct URL), CockroachDB, Amazon RDS, Timescale, and pgvector.To get started
_template/README.md.TemplateConnector→PostgresConnectorinsrc/connector.py, updatesrc/__init__.pyto re-export it, and fill inpyproject.toml.__iter__usingpsycopg. Setrow_factory=dict_rowso rows come back as dicts instead of tuples.Deliverables
The caller should be able to write:
Files:
src/connector.py—PostgresConnectorclasssrc/__init__.py— re-exportsPostgresConnectorandingestsrc/ingest.py— copy from_template/src/ingest.pypyproject.toml— listspsycopg[binary]>=3.1tests/test_postgres.py— unit test with mockedpsycopg.connectandMossClienttests/test_integration_postgres_moss.py— live test, skips withoutPOSTGRES_DSNand Moss credsREADME.mdpackages/moss-data-connector/README.mdRequired for review / PR acceptance