really create schema

This commit is contained in:
2019-12-19 15:00:24 +01:00
parent f7a97cf575
commit 77ed63784b
9 changed files with 100 additions and 30 deletions

View File

@ -2,6 +2,7 @@ from tiramisu import Config
from traceback import print_exc
from copy import copy
from typing import Dict, Callable
from json import dumps, loads
from .utils import _
from .error import CallError, NotAllowedError
@ -104,6 +105,12 @@ class CallDispatcher:
db_conf = get_config().get('database')
pool = await asyncpg.create_pool(database=db_conf.get('dbname'), user=db_conf.get('user'))
async with pool.acquire() as connection:
await connection.set_type_codec(
'json',
encoder=dumps,
decoder=loads,
schema='pg_catalog'
)
risotto_context.connection = connection
async with connection.transaction():
returns = await risotto_context.function(self.injected_self[function_obj['module']], **kw)
@ -177,10 +184,18 @@ class PublishDispatcher:
if function_obj['risotto_context']:
kw['risotto_context'] = risotto_context
# send event
if function_obj['database']:
if function_obj['database'] and hasattr(old_risotto_context, 'connection'):
risotto_context.connection = old_risotto_context.connection
if function_obj['database'] and not hasattr(risotto_context, 'connection'):
db_conf = get_config().get('database')
pool = await asyncpg.create_pool(database=db_conf.get('dbname'), user=db_conf.get('user'))
async with pool.acquire() as connection:
await connection.set_type_codec(
'json',
encoder=dumps,
decoder=loads,
schema='pg_catalog'
)
risotto_context.connection = connection
async with connection.transaction():
returns = await function(self.injected_self[function_obj['module']], **kw)