Skip to content
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

Getting rid of databases dependency (just asyncpg) #5

Open
wants to merge 1 commit into
base: master
from

Conversation

@jordic
Copy link
Contributor

jordic commented Nov 30, 2019

Just provide a raw asyncpg con,

If I'm not wrong this will allow to user asyncom, with a raw guillotina connection,
something like this...

class DBOM(OMAsyncPG):
    @property
     def connection(self):
         txn = get_transaction()
         await txn.get_connection()

There are still rude cases, I need to evolve it a bit more, but the raw idea,
is to be able to query other postgresql objects from a guillotina context.

Do you think this will be transaction aware? (Should I need to do something else to join
the guillotina transaction, and be able to mix, updated objects from guillotina with,
other objects updated on the db?

Why,

  • Because sometimes is better to just store subresources as a postgresql table.
  • Because this way we can leverage guillotina as the web framework, and just use AsyncOM
    as a complementary storage.

cc: @vangheem @masipcat

@jordic

This comment has been minimized.

Copy link
Contributor Author

jordic commented Nov 30, 2019

Ok, seems it's working... (at least for read, with something like):

from guillotina import configure
from mcrawler.interfaces import IAsyncOm
from guillotina.transactions import get_transaction
from asyncom import OMDatabase


@configure.utility(provides=IAsyncOm)
class AsyncOMUtility(OMDatabase):
    async def get(self):
        txn = get_transaction()
        conn = await txn.get_connection()
        return OMDatabase(conn=conn)

Later on a service, I can just do:

@configure.service(
    method="GET",
    name="@sources",
    context=IContainer
)
class GetSources(Service):
    async def __call__(self):
        db = await get_utility(IAsyncOm).get()
        data = await db.query(Source).all()
        return [item.diff_dict() for item in data]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.