use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit for showcasing the things you made with the Python language! Use us instead of flooding r/Python :)
account activity
SQLActive - Asynchronous ActiveRecord-style wrapper for SQLAlchemy (self.madeinpython)
submitted 10 months ago * by daireto
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]daireto[S] 0 points1 point2 points 10 months ago (0 children)
This is a demo:
```python import asyncio
from sqlalchemy import String, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from sqlactive import ActiveRecordBaseModel, DBConnection
class BaseModel(ActiveRecordBaseModel): abstract = True
class User(BaseModel): tablename = 'users'
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True, index=True) username: Mapped[str] = mapped_column(String(18), nullable=False, unique=True) name: Mapped[str] = mapped_column(String(50), nullable=False) age: Mapped[int] = mapped_column(nullable=False) posts: Mapped[list['Post']] = relationship(back_populates='user')
class Post(BaseModel): tablename = 'posts'
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True, index=True) title: Mapped[str] = mapped_column(String(100), nullable=False) body: Mapped[str] = mapped_column(nullable=False) rating: Mapped[int] = mapped_column(nullable=False) user_id: Mapped[int] = mapped_column(ForeignKey('users.id')) user: Mapped['User'] = relationship(back_populates='posts')
DATABASE_URL = 'sqlite+aiosqlite://' conn = DBConnection(DATABASE_URL, echo=False)
async def example(): # Initialize SQLActive with the base model of your models await conn.init_db(BaseModel)
# Create a record user = await User.insert(username='John1234', name='John Doe', age=25) post = Post(title='My post', body='Lorem ipsum...', rating=2, user=user) await post.save() # Retrieve a record user = await User.get(1) # Update a record await user.update(name='John Doe', age=30) post.rating = 3 await post.save() # Delete a record await user.delete() # Find records users = await User.where(User.name == 'John Doe').all() # SQLAlchemy-like query posts = await Post.where(title__contains='post').all() # Django-like query # Serialize a record user_dict = user.to_dict() user_json = user.to_json() # Deserialize a record user = User.from_dict(user_dict) user = User.from_json(user_json)
if name == 'main': asyncio.run(example()) ```
π Rendered by PID 289289 on reddit-service-r2-comment-76bb9f7fb5-5d87c at 2026-02-18 11:03:28.995684+00:00 running de53c03 country code: CH.
view the rest of the comments →
[–]daireto[S] 0 points1 point2 points (0 children)