Before introducing SQLAlchemy, let's look at the ORM first.
ORM full name Object Relational Mapping , translate come to call 对象关系映射 . That is, ORM establishes a correspondence between the tables in the database and the classes in the object-oriented language.
SQLAlchemy is one of the most well-known ORM tools in the Python community, designed for efficient and high-performance database access, enabling a complete enterprise-class persistence model.
Installing a different system on Ubuntu is just a command header. Install SQLAlchemy:
$ sudo pip install sqlalchemy
1 Connecting the database
We code a new Python file name .py(name只是一个名字,随便你自己取 不过要符合命名规则) :
# coding: utf-8 #使用utf-8from sqlalchemy import create_engine #导入sqlalchemy中的create_engine包 用来连接数据库 也可以导入PSYCOPG2 Bag
engine = create_engine(‘mysql+mysqldb://<username>:<password>@<dsnname>‘)
username是数据库的用户名 password是数据库管理员密码 dsnname是ip+端口+路径
2 columns of the database
Everyone knows that a database is really a column of data. The columns in the database have so many parameters how do we determine that in Python?
It's probably a question that the average person will have. I thought about it in the first place.
And the answer is the use of Colume in Python's sqlalchemy.
id = column (Integer, Primary_key=true) Username = column (String (64), Nullable=false, Index=True) Password = column (String (64), Nullable=false) email = column ( String (64), Nullable=false, index= true)
Type = Colume (bool,nullable=true)
Here is a brief introduction to the basic parameters to fill out the
What's wrong with the hope that you can point to help me progress thank you
Finally, we can see Https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/ 0014320114981139589ac5f02944601ae22834e9c521415000
This site Oh, I myself have been in this Python tutorial a few times
if someone is doing openstack. I hope you can give me a chance to ask for advice.
MySQL database artifact in SQLAlchemy python