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

[Question/Feature] Encryption #762

Open
taras0024 opened this issue Oct 3, 2024 · 0 comments
Open

[Question/Feature] Encryption #762

taras0024 opened this issue Oct 3, 2024 · 0 comments

Comments

@taras0024
Copy link

Hello. I have two questions regarding StringEncryptedType:

  1. Is there any possibility in future versions to replace the checking of value in the process_bind_param and process_result_value methods from

    if value is not None:

    to simply

    if value:

    This is because I have a field that cannot be null but can be an empty string, and when an empty string is passed to query, it still gets encrypted/decrypted and stored in the database as a hash. I would prefer it to remain empty in such cases.

  2. Is there a way to avoid applying the process_bind_param and/or process_result_value methods when building a query? This is needed to retrieve raw (input) data when constructing a query through SQLAlchemy.
    For example:

    stmt = select(ConsumerModel).where(or_(*[ConsumerModel.phone.regexp_match(pattern) for pattern in [r"\+999\d{9}", r"\+888\d{9}"]]))
    print(str(stmt.compile(compile_kwargs={"literal_binds": True})))

    Instead of the query:

    SELECT id, phone FROM consumers WHERE phone ~ 'Lt/AAG0KXbsqlIeNZMiQUQ==' OR phone ~ 'kL4Xys1h0s9oSAPEneS7BQ7n9nsFYWIzsUuqVPQuB9E='

    I would like to get:

    SELECT id, phone FROM consumers WHERE phone ~ '\\+380\\d{9}$' OR phone ~ '\\+999\\d{9}'

    Alternatively, is it possible to retrieve encrypted data from the database instead of decrypted values when querying?

I hope my questions are clear. Thank you in advance for your response!

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