Better way to import declarative_base from SQLAlchemy.

Import `declarative_base` in a way that is compatible with any
SQLAlchemy version between 1.3 and 2.x.
This commit is contained in:
Fabio Manganiello 2023-04-24 23:21:39 +02:00
parent 8478245cde
commit d33d760361
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
6 changed files with 19 additions and 6 deletions

View file

@ -3,9 +3,10 @@ import os
from typing import Optional, Union, List, Dict, Any
from sqlalchemy import create_engine, Column, Integer, String, DateTime
from sqlalchemy.orm import sessionmaker, scoped_session, declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from platypush.backend import Backend
from platypush.common.db import declarative_base
from platypush.config import Config
from platypush.context import get_plugin
from platypush.message.event.covid19 import Covid19UpdateEvent

View file

@ -6,9 +6,10 @@ from typing import Optional, List
import requests
from sqlalchemy import create_engine, Column, String, DateTime
from sqlalchemy.orm import sessionmaker, scoped_session, declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from platypush.backend import Backend
from platypush.common.db import declarative_base
from platypush.config import Config
from platypush.message.event.github import (
GithubPushEvent,

View file

@ -12,10 +12,11 @@ from sqlalchemy import (
ForeignKey,
)
from sqlalchemy.orm import sessionmaker, scoped_session, declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.sql.expression import func
from platypush.backend.http.request import HttpRequest
from platypush.common.db import declarative_base
from platypush.config import Config
from platypush.context import get_plugin
from platypush.message.event.http.rss import NewFeedEvent

View file

@ -9,9 +9,10 @@ from threading import Thread, RLock
from typing import List, Dict, Any, Optional, Tuple
from sqlalchemy import engine, create_engine, Column, Integer, String, DateTime
from sqlalchemy.orm import sessionmaker, scoped_session, declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from platypush.backend import Backend
from platypush.common.db import declarative_base
from platypush.config import Config
from platypush.context import get_plugin
from platypush.message.event.mail import (
@ -40,6 +41,7 @@ class MailboxStatus(Base):
# </editor-fold>
# <editor-fold desc="Mailbox model">
@dataclass
class Mailbox:

View file

@ -1,3 +1,10 @@
from sqlalchemy import __version__
sa_version = tuple(map(int, __version__.split('.')))
if sa_version >= (1, 4, 0):
from sqlalchemy.orm import declarative_base
else:
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

View file

@ -12,9 +12,10 @@ from sqlalchemy import (
PrimaryKeyConstraint,
ForeignKey,
)
from sqlalchemy.orm import sessionmaker, scoped_session, declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.sql.expression import func
from platypush.common.db import declarative_base
from platypush.config import Config
from platypush.plugins.media import MediaPlugin
from platypush.plugins.media.search import MediaSearcher