Skip to content

engine singleton Built in SQLmodel or make my own ? #123

@SteffRainville

Description

@SteffRainville

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

Architecture question, no code needed.

Description

I need the "engine" instance in my services and routers to create "session" to access the database?

define this somewhere

engine = create_engine(sqlite_url, echo=False)

use this everywhere

session = Session(engine)

All samples are single file examples so no imports of engine.

It is unclear to me if SQLModel has a solution or should I create my own singleton to hold the engine instance.

My Flask background had me put the engine from SqlAlchemy to the app instance, is this prefred in FastApi (But not sure if I can import the app instance from main.py).

Operating System

Windows

Operating System Details

No response

SQLModel Version

0.0.4

Python Version

3.9.7

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions