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

Mechanism for de-registering registered SQL functions #589

Open
simonw opened this issue Sep 3, 2023 · 3 comments
Open

Mechanism for de-registering registered SQL functions #589

simonw opened this issue Sep 3, 2023 · 3 comments
Labels
enhancement New feature or request python-library

Comments

@simonw
Copy link
Owner

simonw commented Sep 3, 2023

I used a custom SQL function in a migration script and then realized that it should be de-registered before the end of the script to avoid leaking into the calling code.

@simonw simonw added enhancement New feature or request python-library labels Sep 3, 2023
simonw added a commit to simonw/llm that referenced this issue Sep 3, 2023
@simonw
Copy link
Owner Author

simonw commented Sep 3, 2023

For that particular case I realized I'd quite like to have a mechanism for applying functions for a block of code and then de-registering them at the end - a context manager.

I played with this idea a bit:

with db.register_functions(md5, md5_random):
    db.query(...)

@simonw
Copy link
Owner Author

simonw commented Sep 3, 2023

Normally in Python/sqlite3 you de-register a function by passing None to it.

You can't do that with db.register_function() at the moment because a fn of None does something else:

if fn is None:
return register
else:
register(fn)

@simonw
Copy link
Owner Author

simonw commented Sep 3, 2023

Here's a prototype: 62f6738

Still needs tests and documentation (and some more thought to make sure it's doing the right thing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python-library
Projects
None yet
Development

No branches or pull requests

1 participant