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

Support async ORM - piccolo #281

Open
virajkanwade opened this issue Feb 10, 2024 · 1 comment
Open

Support async ORM - piccolo #281

virajkanwade opened this issue Feb 10, 2024 · 1 comment

Comments

@virajkanwade
Copy link
Contributor

No description provided.

@virajkanwade
Copy link
Contributor Author

virajkanwade commented Feb 16, 2024

@apotterri

Piccolo currently supports
SQLiteEngine
PostgresEngine
CockroachEngine

CockroachEngine inherits from PostgresEngine.

https://piccolo-orm.readthedocs.io/en/latest/piccolo/engines/index.html#engine-types

from _appmap import wrapt
from _appmap.env import Env

from piccolo.engine.postgres import PostgresEngine
from piccolo.engine.sqlite import SQLiteEngine


async def install_extension_run_querystring(wrapped, self_obj, args, kwargs):
    print('> inside Postgres run_querystring')
    print('  query_id: ', self_obj.query_id + 1)  # this will be incremented inside the function
    print('  args:', args)
    print('  kwargs:', kwargs)

    query, query_args = args[0].compile_string(
            engine_type=self_obj.engine_type
    )

    print('    querystring:', args[0].__str__())
    print('      query: ', query)
    print('      query_args: ', query_args)

    response = await wrapped(*args, **kwargs)

    print('  query_id: ', self_obj.query_id)  # this will be incremented inside the function
    print('  response:', response)

    return response


async def install_extension_run_ddl(wrapped, self_obj, args, kwargs):
    print('> inside Postgres run_ddl')
    print('  query_id: ', self_obj.query_id + 1)  # this will be incremented inside the function
    print('  args:', args)
    print('  kwargs:', kwargs)

    print('    querystring:', args[0])

    response = await wrapped(*args, **kwargs)

    print('  query_id: ', self_obj.query_id)  # this will be incremented inside the function
    print('  response:', response)

    return response


if Env.current.enabled:
    PostgresEngine.run_querystring = wrapt.wrap_function_wrapper("piccolo.engine.postgres", "PostgresEngine.run_querystring", install_extension_run_querystring)
    PostgresEngine.run_ddl = wrapt.wrap_function_wrapper("piccolo.engine.postgres", "PostgresEngine.run_ddl", install_extension_run_ddl)

    SQLiteEngine.run_querystring = wrapt.wrap_function_wrapper("piccolo.engine.postgres", "SQLiteEngine.run_querystring", install_extension_run_querystring)
    SQLiteEngine.run_ddl = wrapt.wrap_function_wrapper("piccolo.engine.postgres", "SQLiteEngine.run_ddl", install_extension_run_ddl)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant