Skip to content

Added JSON decoder #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 10 additions & 0 deletions src/opal_fetcher_postgres/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
from typing import Optional, List

import json
import asyncpg
from asyncpg.transaction import Transaction
from asyncpg.exceptions import DataError
Expand Down Expand Up @@ -139,6 +140,15 @@ async def __aenter__(self):
self._connection: asyncpg.Connection = await asyncpg.connect(
dsn, **connection_params
)

# add support for json decoder
await self._connection.set_type_codec(
'json',
encoder=json.dumps,
decoder=json.loads,
schema='pg_catalog'
)

# start a readonly transaction (we don't want OPAL client writing data due to security!)
self._transaction: Transaction = self._connection.transaction(readonly=True)
await self._transaction.__aenter__()
Expand Down