mastodon.xyz is one of the many independent Mastodon servers you can use to participate in the fediverse.
A Mastodon instance, open to everyone, but mainly English and French speaking.

Administered by:

Server stats:

811
active users

#sqlalchemy

0 posts0 participants0 posts today
James Bennett<p>I have a <a href="https://infosec.exchange/tags/Python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Python</span></a> codebase using <a href="https://infosec.exchange/tags/sqlalchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>sqlalchemy</span></a> Core -- *NOT* ORM -- for its data layer, and I'm currently not happy with the way it's doing data for testing. Who has a pattern for this that they actually like?</p><p>I already have ephemeral per-test-function isolation of the database, so that's taken care of.</p><p>If this were ORM I'd just use something like factory-boy, but the fact that it's Core and doesn't really map neatly to objects the way ORM stuff does rules that out. I think ideally what I'd like is some sort of declarative JSON file format or whatever that lets me provide a mapping of table names to lists of rows to insert into them, and then a pytest fixture that lets me say "load that JSON file for this test". Has anyone written something like that? Do I get to go write my own?</p>
洪 民憙 (Hong Minhee)<p><strong>애플리케이션 개발 측면에서 본 Drizzle ORM 대 Kysely 비교</strong></p> <p><a href="https://hackers.pub/@hongminhee/2025/drizzle-orm-vs-kysely" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">hackers.pub/@hongminhee/2025/d</span><span class="invisible">rizzle-orm-vs-kysely</span></a></p>
Future Sprog<p>Dear <a href="https://mastodon.nzoss.nz/tags/LazyWeb" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>LazyWeb</span></a> and friends,</p><p>I have a lovely normalised database and one column, when fetched back from the database, can have multiple values. I have the standard 3 table many-to-many setup: Table A, table B, and a third Table that has the matching IDs from A and B to do the multi-to-multi.</p><p>How do I fetch this back from the database and present it as a JSON array? Everything seems to suggest using the database to make a delimited string and let clients turn it into an array. Silly.</p><p><a href="https://mastodon.nzoss.nz/tags/SQLAlchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLAlchemy</span></a></p>
hobbsc<p>i keep finding all sorts of weird tooling in <a href="https://social.sdf.org/tags/sqlalchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>sqlalchemy</span></a> by way of my coworkers' commits. i didn't realize how many features it has, even after messing with event listeners for a week.</p>
Hacker Charity<p>Just added SQLAlchemy from <span class="h-card" translate="no"><a href="https://hachyderm.io/@zzzeek" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>zzzeek</span></a></span> to our list! From raw SQL nightmares to elegant Python ORM - you've transformed how an entire generation of developers works with databases.</p><p>Thank you for this masterpiece of engineering!</p><p><a href="https://floss.social/tags/Python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Python</span></a> <a href="https://floss.social/tags/SQLAlchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLAlchemy</span></a> <a href="https://floss.social/tags/OpenSource" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>OpenSource</span></a></p>
Marcos Dione<p>I love this magick:</p><p>```<br>In [1]: import model</p><p>In [2]: model.Tooter<br>Out[2]: model.Tooter</p><p>In [3]: model.Tooter.account<br>Out[3]: &lt;sqlalchemy.orm.attributes.InstrumentedAttribute at 0x7fbf7bd31bc0&gt;</p><p>In [4]: model.Tooter.account == 'foo'<br>Out[4]: &lt;sqlalchemy.sql.elements.BinaryExpression object at 0x7fbf8183a960&gt;<br>```</p><p>:) <a href="https://en.osm.town/tags/python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>python</span></a> <a href="https://en.osm.town/tags/SQLAlchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLAlchemy</span></a> <a href="https://en.osm.town/tags/metaprogramming" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>metaprogramming</span></a></p>
Albin<p>Holy s*it, I just tried <a href="https://mastodon.social/tags/tortoise" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>tortoise</span></a>-orm for <a href="https://mastodon.social/tags/Python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Python</span></a> and my mind is blown away. After using <a href="https://mastodon.social/tags/SQLAlchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLAlchemy</span></a> for a long time this is like night and day!</p>
Endurain<p>Well this is messing with me:</p><p>SQLAlchemy column definition:<br>start_time = Column(DateTime, nullable=False, comment="Activity start date (DateTime)")</p><p>SQLAlchemy query:<br>activity_db = (db.query(activities_models.Activity).filter(activities_models.Activity.id == activity_id).first())</p><p>print(type(activity_db.start_time))<br>print(activity_db.start_time)</p><p>First print returns: &lt;class 'str'&gt;<br>Second print returns: 2024-11-25T16:49:52+0100</p><p>Boost welcomed 🙃 </p><p>Why?! <a href="https://fosstodon.org/tags/Python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Python</span></a> <a href="https://fosstodon.org/tags/help" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>help</span></a> <a href="https://fosstodon.org/tags/MySQL" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>MySQL</span></a> <a href="https://fosstodon.org/tags/SQLAlchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLAlchemy</span></a> <a href="https://fosstodon.org/tags/boost" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>boost</span></a></p>
Julien Riou<p>As a DBA, I always want developers to use database transactions and appropriate levels of locking. Because I'm tired of seeing explicit locking of tables or autocommit enabled.</p><p>BUT, after two days of trying to patch a simple CRUD app to apply my own rules, failing miserably, I just want to remove all this ORM crap and use raw SQL.</p><p>That's it.</p><p>Tomorrow, I will rewrite this monstrosity.</p><p><a href="https://hachyderm.io/tags/python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>python</span></a> <a href="https://hachyderm.io/tags/postgresql" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>postgresql</span></a> <a href="https://hachyderm.io/tags/gino" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>gino</span></a> <a href="https://hachyderm.io/tags/sqlalchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>sqlalchemy</span></a> <a href="https://hachyderm.io/tags/json" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>json</span></a></p>
Wolf<p><span class="h-card" translate="no"><a href="https://mastodon.online/@veronica" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>veronica</span></a></span> <a href="https://hachyderm.io/tags/sqlalchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>sqlalchemy</span></a> has been nothing but trouble in our team. Lazy loading makes you have more transactions that last longer and also leads to the n+1 query problem. And I hate the query constructor to me it’s harder to understand than plain old SQL. We’re stripping it off to get back down to the <a href="https://hachyderm.io/tags/psycopg2" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>psycopg2</span></a> layer.</p>
frague59 ⏚<p><span class="h-card" translate="no"><a href="https://mastodon.online/@veronica" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>veronica</span></a></span> Give a try to <a href="https://pouet.chapril.org/tags/peewee" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>peewee</span></a> - much more simple than <a href="https://pouet.chapril.org/tags/SQLAlchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLAlchemy</span></a> !</p>
Wolf<p><span class="h-card" translate="no"><a href="https://chaos.social/@scy" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>scy</span></a></span> no it doesn’t help with migrations, so it probably doesn’t solve your problem. I knew that when I responded. I should have said more, especially that. The reason I answered, and the reason I answered with this is that we were on <a href="https://hachyderm.io/tags/sqlalchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>sqlalchemy</span></a> and it’s done nothing but get in the way. <a href="https://hachyderm.io/tags/psycopg2" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>psycopg2</span></a> was underneath and now we’re using that and life is much better. So that’s what I *prefer* though I’m sorry it’s not what you need.</p>
scy<p>What's your preferred alternative to <a href="https://chaos.social/tags/SQLAlchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLAlchemy</span></a>? Looking for something more lightweight and less complex.</p><p>I don't necessarily need an <a href="https://chaos.social/tags/ORM" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>ORM</span></a>, I certainly don't need cross-DBMS abstraction.</p><p>In fact, all I basically need is a nice interface to <a href="https://chaos.social/tags/SQLite" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLite</span></a>. If it comes with some kind of ORM, that's nice. Way more important would be if it helps me deal with migrations. The less I have to think about capturing&nbsp;/ applying schema changes, the better.</p><p>Suggestions? What did you enjoy working with?</p><p><a href="https://chaos.social/tags/Python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Python</span></a></p>
洪 民憙 (Hong Minhee)<p><a href="https://fosstodon.org/tags/Alembic" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Alembic</span></a>, the migration tool for <a href="https://fosstodon.org/tags/SQLAlchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLAlchemy</span></a>, supports not only schema upgrades but also downgrades and branch merges, so I didn't have much trouble moving between different branches with slightly different schemas in my local development environment, which is something I don't think many database migration tools offer.</p><p><a href="https://alembic.sqlalchemy.org/en/latest/branches.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">alembic.sqlalchemy.org/en/late</span><span class="invisible">st/branches.html</span></a></p>
Thomas Arildsen<p>Can I define custom insert behaviour in a <a href="https://fosstodon.org/tags/SQLAlchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLAlchemy</span></a> ORM-mapped class which is used when I call `sqlalchemy.orm.Session.add` and perhaps `sqlalchemy.orm.Session.bulk_save_objects`?</p><p>This is so I would not have to make sure to use a custom MyData.insert method, but could just rely on the usual mechanisms of SQLAlchemy: `session.add(my_data)`.</p><p>I have looked for, for example an __insert__ method in ORM-mapped classes to override, but I have not found anything like that.</p><p><a href="https://fosstodon.org/tags/Python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Python</span></a></p>
John-Mark Gurney<p>I'm pretty impressed, I manage to get a cte construct working without much difficulty. The SQLAlchemy documentation wasn't too helpful, BUT, SQLite's was good to get the concept down, and I just assumed it'd behave a certain way, that is:</p><p>```<br>cteq = &lt;initial select&gt;.cte(recursive=True)<br>cteq = cteq.union_all(&lt;recursive lookup query using cteq.c.field&gt;)<br>```</p><p>as I used this in an in expression, I had to wrap it:<br>```<br>cteq = select(cteq.c.field)<br>```</p><p><a href="https://flyovercountry.social/tags/Python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Python</span></a> <a href="https://flyovercountry.social/tags/SQLAlchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>SQLAlchemy</span></a> </p><p><a href="https://flyovercountry.social/@encthenet/113270889004069225" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">flyovercountry.social/@encthen</span><span class="invisible">et/113270889004069225</span></a></p>
Aaron Longchamps<p>My learning style is to figure out what I need to get to the next step, then take that next step, then repeat. This has helped me get as far as I have in this project, but also means I'm learning just enough to keep making progress.</p><p>I'm not really going through tutorials or digging into fundamentals much, only enough to accomplish something.</p><p>I know just enough about how databases work but it's been a long while since I've really been into them and I've never designed one before, let alone with foreign keys and relationships. I know the basic idea of what I want, but finding examples is harder.</p><p>If anyone has any great examples of foreign key relationships in SQL Alchemy, especially with a Vue based front end, I'm all ears.</p><p>If not, I might need to dust off my old blog and get something up there.</p><p><a href="https://infosec.exchange/tags/webdev" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>webdev</span></a> <a href="https://infosec.exchange/tags/programming" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>programming</span></a> <a href="https://infosec.exchange/tags/python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>python</span></a> <a href="https://infosec.exchange/tags/sqlalchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>sqlalchemy</span></a> <a href="https://infosec.exchange/tags/databases" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>databases</span></a></p>
Aaron Longchamps<p>Well I've hit a bit of a wall on the foreign key situation in SQL Alchemy on the backend side of this project.</p><p>I want to have an inventory item with a deviceTypeId field that's an ID number pointing over to the Device Types table. Each Device Type row has an ID and a name. I want the Device Type name to get back over to the inventory item record as another field.</p><p>If that doesn't make sense, maybe this will in JSON: </p><p>Device Type row / example:<br>{ "id": 1, "name": "Synology DS414 NAS" }</p><p>Inventory Item row / example:<br>{ "id": 1, "name": "ds414", "deviceTypeId": 1, ...(other fields) }</p><p>The database relationship I want to have my SQL Alchemy ORM do is this:</p><p>{ "id": 1, "name": "ds414", "deviceTypeId": 1, **"deviceType": "Synology DS414 NAS",**<br>...(other fields) }</p><p>I've seen lots of docs with relationships(...), Mapped(...) calls, Lists, back reference, back populate, and other things.</p><p>For now I really just want to pull over the name field from another table, based on the foreign key ID.</p><p><a href="https://infosec.exchange/tags/webdev" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>webdev</span></a> <a href="https://infosec.exchange/tags/programming" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>programming</span></a> <a href="https://infosec.exchange/tags/python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>python</span></a> <a href="https://infosec.exchange/tags/sqlalchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>sqlalchemy</span></a> <a href="https://infosec.exchange/tags/orm" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>orm</span></a> <a href="https://infosec.exchange/tags/vscode" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>vscode</span></a> <a href="https://infosec.exchange/tags/sqlite" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>sqlite</span></a> <a href="https://infosec.exchange/tags/databases" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>databases</span></a> <a href="https://infosec.exchange/tags/vue" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>vue</span></a></p>
Poes<p>a little bit confusing with <a href="https://mastodon.bsd.cafe/tags/sqlalchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>sqlalchemy</span></a>, the database is there and contain tables with fine column but I can't insert data to the table because the table is not found. </p><p>weird.</p>
Poes<p>trying <a href="https://mastodon.bsd.cafe/tags/alembic" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>alembic</span></a> (with <a href="https://mastodon.bsd.cafe/tags/sqlalchemy" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>sqlalchemy</span></a>) to migrate some sql schema, everything running with smooth except when I change constraint (unique=True).</p><p>alembic can't process this migrate because SQLite have limitation on modifying constraint schema using ALTER TABLE.</p><p>I have trying to use BATCH MODE but did not meet my expectations. 🥲</p>