An alternative would be
session.query(User).filter(User.id_ == id).count()
On Saturday, June 4, 2022 at 4:45:49 AM UTC+10 jason@stormfish-sci.com
wrote:
> I believe I finally found a solution:
>
> select(func.count(User.id_)).where(User.id_ == id)
>
> Thank you for taking the time to
Use .any():
session.query(Gizmo).filter(Gizmo.users.any('user1'))
On Wednesday, October 13, 2021 at 11:50:16 PM UTC+10 chat...@gmail.com
wrote:
> Imagine a Postgres JSON column with values like below:
> "["user1", "user2"]"
>
> Is there any way to query a postgres JSON (not JSONB) column
This thing is called referential integrity
(https://en.wikipedia.org/wiki/Referential_integrity) and is enforced on
the database level - you can't have a value in Child.parent_id which is not
in Parent.id. The ForeignKey creates a constraint in the database which
ensures the referential
We have a similar setup (a PostgreSQL schema per tenant), we deal with
different database versions by running different *code versions* - i.e. if
you need a new column you release a new code version which knows how to
deal with the new column. Switching a tenant to that code version runs an
Robert, my understanding is that SQLAlchemy knows nothing about the
Postgres's `similarity` function - sqlalchemy.func just magically generates
the SQL output depending on which member you invoke. Try
`func.magic_unicorns()`. So, there's not much to optimize here - it outputs
what you give it.
Hi all,
I've asked this question on stackoverflow:
http://stackoverflow.com/questions/12031861/sqlalchemy-how-do-i-get-an-object-from-a-relationship-by-objects-pk/12032405
Basically, I'm looking for a dict-like access to a relationship to be able
to quickly retrieve items by some key (item's
From your code it's not clear how you're going to differentiate
between matches and merges - basically, you need something in your
database which makes matches different from merges and then
configure the retationships to use those fields.
See the Boston addresses example in the documentation:
each time the attribute is
accessed. Also, the _email attribute IS loaded and then sent back to
the server, which sort of undermines the idea of database-side
processing...
On Jul 28, 2:06 pm, Michael Bayer mike...@zzzcomputing.com wrote:
On Jul 27, 2011, at 8:56 PM, Sergey V. wrote:
Good day
Good day,
I'm trying to figure out how to do something similar to the Symmetric
Encryption recipe (http://www.sqlalchemy.org/trac/wiki/UsageRecipes/
SymmetricEncryption), only on the database side, not in Python.
I have a suspicion that @compiles decorator may provide a solution,
but having
Say I create an instance of a mapped class and then attach some values
to it.
And want to do session.add.
If you're worried about something like this:
user = User()
user.name = ;DROP TABLE users;
session.add(user)
then don't be, there is no possibility of SQL injection here,
Can you give an example of sql injection working with ORM? Some sample
code etc.
On Jul 5, 5:41 am, Krishnakant Mane krm...@gmail.com wrote:
Hello all.
I use Pylons 0.9.7 and sqlalchemy.
I use the Object Relational Mapper with declarative syntax in a few of
my modules.
I was reading chapter
Hi,
One easy/obvious improvement would be to delete all user's
identifiers and groups at once without iterating over them for
every user. Actually, iterating over the list of user_ids is not
necessary too I think.
code
session.query(Identifier).filter(Identifier.user_id.in_(user_ids)).delete()
Do you need to store expiry_code? seeing as it is a function of
last_con and the current date.
Second that. I would also point out that phone number probably
shouldn't be an integer - how would you store phone numbers which
start with 0, for example?
I'd rather make it a String.
--
You
relationship() expects a class or a mapper instance, not a string. I
got this error:
ArgumentError: relationship 'available_deals' expects a class or a
mapper argument (received: type 'str')
Hmm... I'm not sure what I'm doing wrong but passing strings to
relation() definitely works for me:
The twist is that I've spread out my tables and ORM classes across
several files. I've tried to keep it so that I don't have circular
dependencies. That means I've defined Merchant first, and then Deal
later, in separate files
To avoid problems with imports and dependencies you can pass
Hi all,
I've got two tables: Users (id, password) and UserProperties (user_id,
name, value). Is there a way to map the properties stored in
UserProperties as attributes of User object?
I mean,
john = User('john', 'password')
john.name = John Smith # creates UserProperty('john', 'name', 'John
Hi all,
I must be missing something obvious here...
Let's suppose I have the following class:
class User(Base):
#
addresses = relation(Address, backref=user)
and I have a number which may be an ID of an Address object. How do I
check if the number is an ID of one of Addresses of
Some assumptions:
1. SA-mapped object means the user object in the example
2. property name means addresses in the example
3. The function shouldn't assume that you want an Address object
4. The ID attribute is known ahead of time (e.g. its always id). If
not, your function will need
Ahh... I missed the relation.any() part of your example - with it the
code should behave exactly as I need. I think. I need to give it a
try.
Thanks!
On Oct 30, 9:53 am, Sergey V. sergey.volob...@gmail.com wrote:
Some assumptions:
1. SA-mapped object means the user object in the example
2
19 matches
Mail list logo