[sqlalchemy] Re: SQL Alchemy TypeDecorator

2022-08-09 Thread 'Jonathan Vanasco' via sqlalchemy
This is usually done in the ORM with functions, and possibly hybrids.  

See https://docs.sqlalchemy.org/en/14/orm/mapped_attributes.html

On Tuesday, August 9, 2022 at 1:55:45 PM UTC-4 Justvuur wrote:

> Hi there,
>
> Is there a way to pass/access model data for a row within the " 
> process_result_value" method of a TypeDecorator?
>
> For example, I want to decrypt the value but only if another value in the 
> same model row is true/false.
>
> Regards,
> Justin
>
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/daa3-b548-4d33-a638-a7fae644f322n%40googlegroups.com.


[sqlalchemy] Re: SQLAlchemy exists() used with first() ?

2022-08-09 Thread 'Jonathan Vanasco' via sqlalchemy
I think you misunderstand `exists()` in SQLAlchemy and SQL.  `exists()` is 
a convenience function to create a SQL `EXISTS` clause, which is an 
operator used for filtering subqueries.

The 'from_exists' is just a subquery.  It is supposed to be used within a 
query which would then limit the query, not executed itself.

See
  
 
https://docs.sqlalchemy.org/en/14/core/selectable.html?#sqlalchemy.sql.expression.Exists
 
  
 
https://docs.sqlalchemy.org/en/14/core/selectable.html?#sqlalchemy.sql.expression.exists
  
 https://docs.sqlalchemy.org/en/14/orm/query.html#sqlalchemy.orm.Query.exists
   https://www.w3schools.com/sql/sql_exists.asp



On Tuesday, August 9, 2022 at 2:05:56 PM UTC-4 Justvuur wrote:

> Hi there,
>
> When creating another column property in a model that makes use of the 
> exists(), I noticed that the exists does a "select *".
>
> *For example, the form exists below:*
> class Contact(ResourceMixin, db.Model):  
>  __tablename__ = 'contacts'
>
> form_contacts = db.relationship(FormContact, backref='contact', 
> passive_deletes=True)
>
> form_exists = column_property(
> exists().where(and_( FormContact .form_contact_id == id,
> FormContact.partnership_id == partnership_id
> )).label('form_contact_exist'), deferred=True
> )
> *prints out to be something like:*
> exists(select * from form_contacts where form_contacts.form_contact_id == 
> id and  form_contacts. partnership_id == partnership_id)
>
> Does the exists "stop" the query once one row is returned or does it 
> execute the entire select all query?
> If the latter, is there a way to limit the select all to one row?
>
> Regards,
> Justin
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/0cb5d3e1-8e8d-4367-861d-f5e8328c4ffen%40googlegroups.com.


[sqlalchemy] SQLAlchemy exists() used with first() ?

2022-08-09 Thread Justvuur
Hi there,

When creating another column property in a model that makes use of the 
exists(), I noticed that the exists does a "select *".

*For example, the form exists below:*
class Contact(ResourceMixin, db.Model):  
 __tablename__ = 'contacts'

form_contacts = db.relationship(FormContact, backref='contact', 
passive_deletes=True)

form_exists = column_property(
exists().where(and_( FormContact .form_contact_id == id,
FormContact.partnership_id == partnership_id
)).label('form_contact_exist'), deferred=True
)
*prints out to be something like:*
exists(select * from form_contacts where form_contacts.form_contact_id == 
id and  form_contacts. partnership_id == partnership_id)

Does the exists "stop" the query once one row is returned or does it 
execute the entire select all query?
If the latter, is there a way to limit the select all to one row?

Regards,
Justin

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/17fa3686-6e58-4198-869d-88b40dc02448n%40googlegroups.com.


[sqlalchemy] SQL Alchemy TypeDecorator

2022-08-09 Thread Justvuur
Hi there,

Is there a way to pass/access model data for a row within the " 
process_result_value" method of a TypeDecorator?

For example, I want to decrypt the value but only if another value in the 
same model row is true/false.

Regards,
Justin


-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/ea4cc84a-207d-4415-b995-2852ed6f2a47n%40googlegroups.com.