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
0
votes
1 answer

Postgres docker "server closed the connection unexpectedly"

I want to run and connect to the postgresql Docker image in Python using SQLModel. Here's my attempt from contextlib import contextmanager import docker from sqlmodel import create_engine, SQLModel, Field DEFAULT_POSTGRES_PORT = 5432 class…
joel
  • 6,359
  • 2
  • 30
  • 55
0
votes
1 answer

How to create a table with schema in SQLModel?

I want to create a table with schema "fooschema" and name "footable". Based on this GitHub issue and to some extent the docs, I tried fooMetadata = MetaData(schema="fooschema") class Foo(SQLModel, table=True): __tablename__ = "footable" …
joel
  • 6,359
  • 2
  • 30
  • 55
0
votes
0 answers

pydantic recursive model and selectinload sqlalchemy

my question is about way to get a select to parent model, with properly selectinload option, using pydantic response model. For example: from pydantic import BaseModel class Parent(SQLModel, table=True): id: UUID = sm.Field(UUID,…
0
votes
0 answers

Getting error: Class 'models.forumModels.Phpbb_forums' is not mapped

i create a scripts to add data into my database with sqlmoel, i've 2 table one posts and the other forums, for the posts script worked normally without any problem but the forum script it return an error that the table forums is not mapped. here is…
MihRajaa
  • 1
  • 2
0
votes
1 answer

Working with Generator Context Manager in fastapi db session

I am using context manager with fastapi session, my setup is below: from sqlmodel import create_engine, Session from app.core.config import settings engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True) SessionLocal =…
Olaw2jr
  • 5
  • 3
0
votes
1 answer

What is this table=True inside a subclass of SQLModel?

Consider this code: from sqlmodel import SQLModel, Field class Task(SQLModel, table=True): id = Column(Integer, primary_key=True, index=True) I only stepped away from python for a few weeks and now there are arguments in the class-inheritance…
Cygnuson
  • 160
  • 1
  • 11
0
votes
0 answers

Using ARRAY of POINT-s (Point[]) in SQLModel, SQLAlchemy and PostgreSQL

I have just started working with SQLModel which is built on top of the SQLAlchemy. I want to create a Class Model for table to do selects and inserts. I have one column that is an Array of Points. The DDL for that table looks like that: CREATE TABLE…
demetere._
  • 268
  • 2
  • 10
0
votes
0 answers

SQLModel in Fastapi using __table_args__ is unable to create tables for unit testing

My Model is as follows, this model is defined in a file called tool_model.py, Hence the creation using tool_model.SQLModel.metadata.create_all(engine) class Tool(SQLModel, table=True): __tablename__='tools' __table_args__ = {'schema':…
code_10
  • 155
  • 1
  • 2
  • 10
0
votes
0 answers

How to create and use many to many relationships with FastAPI and SQLModel and avoid circular references?

I've got a Python 3.10.8 FastAPI application using SQLModel and having trouble with many-to-many relationships. I can define them okay using strings to refer to the class on the other side of the many. Here is a simplified sample of one side of the…
writes_on
  • 1,735
  • 2
  • 22
  • 35
0
votes
1 answer

Is there a way to paginate related data in sqlmodel on the frontend

The sqlmodel docs gives an example of two classes class Team(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str = Field(index=True) headquarters: str heroes: List["Hero"] =…
mtkguy
  • 277
  • 2
  • 14
0
votes
0 answers

FastAPI + SQLModel Distinguishing Unset from Null (None) query parameters

I am playing around with using pydantic/SQLModels to specify query parameters for FastAPI endpoints. The model would have all optional types, and then get passed the endpoint using query_params:QuerySchema=Depends(QuerySchema). This works fine but I…
Andrew L.
  • 23
  • 8
0
votes
1 answer

SQLModel with Pydantic validator

I want to use SQLModel which combines pydantic and SQLAlchemy. I have a UserCreate class, which should use a custom validator. This is my Code: class UserBase(SQLModel): firstname: str lastname: str username: str email: str …
Data Mastery
  • 1,555
  • 4
  • 18
  • 60
0
votes
1 answer

SQLModel error when autogenerating Alembic revisions

I have a repository.models.models file: from datetime import date from typing import Type, Optional, List from sqlmodel import SQLModel, Field, Relationship class Compra(SQLModel, table=True): com_id: Optional[int] = Field(default=None,…
André Carvalho
  • 111
  • 1
  • 11
0
votes
0 answers

Fallback for Postgresql DB in AsyncSession in Python

I am currently having two Postgresql Clusters attached to my Python FastAPI server from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.orm import sessionmaker primary_engine =…
tobias
  • 501
  • 1
  • 6
  • 15
0
votes
0 answers

Programmatic access to SQLModel class attributes

I am trying to plug a SQLModel table onto a dash data table, handling pagination, filtering and page count in the backend, as explained here https://dash.plotly.com/datatable/callbacks Working code from sqlmodel import SQLModel from sqlmodel import…
solknar
  • 31
  • 5