SQLAlchemy
SQLAlchemy | |
---|---|
Basic data
|
|
Current version | 1.3.18 (June 25, 2020) |
operating system | platform independent |
programming language | python |
category | ORM |
License | MIT license |
www.sqlalchemy.org |
SQLAlchemy is an open-source - SQL - Toolkit and ORM - Framework for the programming language Python with the aim of Object-relational impedance mismatch in the way of Java's Hibernate to circumnavigate. SQLAlchemy was released in February 2006.
SQLAlchemy offers a number of design patterns for efficient persistence of data in a relational database . The motivation behind SQLAlchemy is based on the fact that SQL databases are less similar to object collections, the more extensive the data stock and the more power is required, while object collections behave less like relations and tuples, the more is abstracted between data representation and mini-world. Therefore, SQLAlchemy primarily follows a data mapper pattern instead of what is known as an active record pattern. Optional plugins allow further patterns, e.g. E.g. with Elixir a declarative syntax.
example
Creation of an M: N relationship (authorship) between book and author (without imports
):
Base = declarative_base()
engine = sqlalchemy.create_engine('postgres://user:pwd@host/dbname', echo=True)
autorschaft = Table('buch_autor', Base.metadata,
Column('isbn', Integer, ForeignKey('buch.isbn')),
Column('kennung', Integer, ForeignKey('autor.kennung'))
)
class Buch(Base):
__tablename__ = 'buch'
isbn = Column(Integer, primary_key=True)
titel = Column(String(255), nullable=False)
klappentext = Column(Text)
autoren = relationship(Autor, secondary=autorschaft, backref='buecher')
class Autor(Base):
__tablename__ = 'autor'
kennung = Column(String(32), primary_key=True)
name = Column(String(50), nullable=False, unique=True)
Base.metadata.create_all(engine)
Supported databases
SQLAlchemy supports a variety of database management systems :
- Informix IDS
- DB2
- Drizzle
- Firebird
- SAP MaxDB
- Microsoft Access
- Microsoft SQL Server
- MySQL
- Oracle Database
- PostgreSQL
- SQLite
- Sybase ASE
See also
literature
- Mark Ramm, Michael Bayer: SQLAlchemy: Database Access Using Python , Addison-Wesley , 2010, ISBN 9780132364676
- Rick Copeland: Essential SQLAlchemy , O'Reilly , 2008, ISBN 0-596-51614-2
- Jeremy Jones, Noah Gift: Python for Unix and Linux System Administration , O'Reilly , 2008, ISBN 978-0-596-51582-9