Skip to content
Advertisement

Tag: sqlalchemy

Writing a hybrid method using pathlib (accessing properties)

I’m trying to do some path-checking logic on some values in a database. I’m having trouble implementing the class level expression for the hybrid method. Here is some stripped down code: I’m getting the error: Neither ‘Function’ object nor ‘Comparator’ object has an attribute ‘parents’ So I have to create a SQL expression for this function, but I’m not sure

How do I construct a self-referential/recursive SQLModel

I want to define a model that has a self-referential (or recursive) foreign key using SQLModel. (This relationship pattern is also sometimes referred to as an adjacency list.) The pure SQLAlchemy implementation is described here in their documentation. Let’s say I want to implement the basic tree structure as described in the SQLAlchemy example linked above, where I have a

How to union two counts queries in SQLAlchemy?

I have two queries and the only difference between then is that one is counting the success status and the other failure status. Is there a way to get this result in just one query? I’m using SQLALchemy to do the queries. Answer You can use conditions on Count, your query will look like:

Advertisement