| Sep | OCT | Nov |
| 29 | ||
| 2020 | 2021 | 2022 |
COLLECTED BY
Collection: Save Page Now Outlinks
Full Stack Python
All topics |
Blog |
Supporter's Edition |
@fullstackpython |
Facebook |
What's new?
A benefit many developers enjoy with SQLAlchemy is that it allows them
to write Python code in their project to map from the database schema
to the applications' Python objects. No SQL is required to create,
maintain and query the database. The mapping allows SQLAlchemy to handle
the underlying database so developers can work with their Python objects
instead of writing bridge code to get data in and out of relational tables.
SQLAlchemy is an implementation of the object-relational mapping (ORM) concept. Learn more in the data chapter or view all topics.
class Contact(db.Model): __tablename__ = 'contacts' id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(100)) last_name = db.Column(db.String(100)) phone_number = db.Column(db.String(32)) def __repr__(self): return '<Contact {0} {1}: {2}>'.format(self.first_name, self.last_name, self.phone_number)SQLAlchemy handles the table creation that otherwise we would have had to write a create table statement like this one to do the work:
CREATE TABLE CONTACTS(
ID INT PRIMARY KEY NOT NULL,
FIRST_NAME CHAR(100) NOT NULL,
LAST_NAME CHAR(100) NOT NULL,
PHONE_NUMBER CHAR(32) NOT NULL,
);
By using SQLAlchemy in our Python code, all records can be obtained with a
line like contacts = Contact.query.all() instead of a plain SQL such as
SELECT * FROM contacts. That may not look like much of a difference in
syntax but writing the queries in Python is often faster and easier for
many Python developers once multiple tables and specific filtering on fields
for queries have to be written. In addition, SQLAlchemy abstracts away
idiosyncratic differences between database implementations in
SQLite, MySQL and
PostgreSQL.
The most accurate speech-to-text API. Built for Python developers.