Tutorials for Python's SQLAlchemy
One of the features that the Python programming language includes is SQLAlchemy, an open-source database utility. Using SQLAlchemy, users can map relational databases into objects, which can in turn be used in object-oriented programming languages, such as C. Additionally, the utility manages the database connections used by a Python-based software application as well as dynamically changes the database if deemed necessary by the application.
Instructions
-
-
1
Launch a text editing application, such as Notepad, included with Microsoft Windows, or TextEdit, which is included with Mac OS X.
-
2
Map a database used in your Python application by using the "Mapper" command. Replace the example database fields below with the fields included in the database you're using:
mapper (Author, book_table)
-
-
3
Specify how the database should be mapped by adding another "mapper" command followed by a declarative statement, for example:
mapper(Book, book_table, properties = {
'author' : relation(
Author,
Cascade="all, delete-orphan",
backref='movies') -
4
Close the mapping script by adding the following characters to the last line of the text document:
})
-
5
Save the text file so you can access the script in the future as necessary. Copy the script and paste it into your Python application where appropriate to begin using SQLAlchemy to manage your application's database.
-
1