Questions tagged [sqlmodel]

Since SQL Model is a library that combines both SQL Alchemy and Pydantic, this tag is intended for only related questions to this library (SQLModel). Please be sure to tag SQL Alchemy and Pydantic related questions with the corresponding tags

SQLModel is a library for interacting with SQL databases from Python code, with Python objects.

It is designed to be intuitive, easy to use, highly compatible, and robust. SQLModel is based on Python type annotations and powered by Pydantic and SQLAlchemy.

171 questions
3
votes
1 answer

Invalid argument(s) 'render_as_batch'

I'm trying to have Alembic auto-migrate table field type changes in SQLite. According to documentation to do this add render_as_batch=True to the context. Ordinarily, we would need to add compare_type=True but SQLite doesn't support direct type…
phil0s0pher
  • 525
  • 10
  • 21
3
votes
2 answers

How to filter by path with PostgreSQL

I have some resources in my database that are inherited to their sub-resources. I need to be able to get also the inherited resources when I query a resource. I have a field called path which I'm planning to use. The path always contains the full…
lr_optim
  • 299
  • 1
  • 10
  • 30
3
votes
1 answer

How to query a nested attribute in SQLModel?

I have these two tables named User and UserRole. import enum from typing import List from sqlmodel import Column, Enum, Field, Relationship, SQLModel class UserRoleType(str, enum.Enum): admin = 'admin' client = 'client' class…
Ramon Dias
  • 835
  • 2
  • 12
  • 23
3
votes
0 answers

sqlalchemy select joined table on AsyncSession

So, I'm implementing async functionality on fastAPI using sqlalchemy.ext.asyncio & asyncpg, my problem is that the result of my joined query statement is not eagerly loaded even though I specify to my SQLModel that, that table has __mapper_args__ =…
Devs
  • 65
  • 8
3
votes
1 answer

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) with PostgreSQL

I searched for this error a lot, but I only find some with more information behind that like "FATAL: ...". Mine has none. It only says sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) I have a postgres database inside a docker…
Verilyzed
  • 51
  • 1
  • 2
  • 6
3
votes
0 answers

How to use DateTimeTZRange in FastAPI with SQLModel (sqlalchemy + pydantic)?

I'm working on a FastAPI project that uses SQLModel as ORM. As far as I understand it SQLModel is some sort of wrapper on top of sqlalchemy and pydantic that makes the two work together. I have a model that looks like this: from psycopg2.extras…
Ariel
  • 3,383
  • 4
  • 43
  • 58
3
votes
2 answers

SqlModel datetime field is throwing error upon execution

I am using SQLModel in python 3.8 When I add my datetime field created_at: datetime = Field(default_factory=utcnow(), nullable=False) I get this Error File "./app/main.py", line 16, in class Post(SQLModel, table=True): File…
Mark Wardell
  • 493
  • 7
  • 25
3
votes
1 answer

how to create PostgreSQL 'text' column using SQLModel for FastAPI

I'm using SQLModel for FastAPI. But I don't know how to create 'text' column type using it. How can I create 'text' column? Thank you for reading it. from sqlmodel import SQLModel, Field class BaseModel(SQLModel): col_1: str =…
ynjo
  • 97
  • 6
3
votes
1 answer

Python SQLModel - Truncate table or delete all and get number of rows

Using Python SQLModel, I want to truncate a table, or remove all rows, and get the number of deleted rows, in the most SQLModel standar way. How can I do this? I am using this: with Session(engine) as session: count =…
okelet
  • 716
  • 1
  • 8
  • 23
3
votes
2 answers

Unable tu map FastAPI List[], Set() through SQLModel into Postgres

I'm doing my personal portfolio API with FastAPI and decided to try SQLModel. It feels so intuitive and i love it so far, but i encountered a problem that I have struggling with for days, trying to understand how to make it right. I have a Project…
3
votes
1 answer

Is it possible to inherit Python type annotations?

I'm learning a new tool called SQLModel, by Sebastian Ramirez (The FastAPI creator). For basic CRUD operations in SQLModel, the docs teach you it's necessary to set up a model entity like this: from typing import Optional, List from sqlmodel import…
John Kealy
  • 1,503
  • 1
  • 13
  • 32
2
votes
1 answer

FastAPI - switching off a switch some time later

Let's say I have this sqlmodel.SQLModel which has a table name Project. My intention is to feature a record of a Project for a definite period of time, e.g. 3 days, i.e. setting it's field featured to be True, and automatically set its field…
Jim
  • 450
  • 2
  • 10
2
votes
1 answer

SQLModel: Forbid mutation

from sqlmodel import SQLModel class Foo(SQLModel): bar: str class Config: """ Forbid mutation in order to freeze the inheriting classes """ allow_mutation = False foo =…
solknar
  • 31
  • 5
2
votes
0 answers

Deep nesting response model in fastapi using sqlmodel

I would like here to iterate on this previous question. But now I have a relationship among 3 tables. I believe it's useful here to look at an entity relationship diagram to better understand the structure of the underlying database. The schemas.py…
moth
  • 1,833
  • 12
  • 29
2
votes
2 answers

How to join multiple tables in sql join using sqlmodel and fastapi

tables.py class Tool(SQLModel, table=True): __tablename__ = 'tools' tool_id: Optional[int] = Field(default=None, primary_key=True) tool_name : str = Field(sa_column=Column("tool_name", VARCHAR(54),nullable=False)) tool_description :…
code_10
  • 155
  • 1
  • 2
  • 10
1
2
3
11 12