Python generates model from a database table
Looking for a long time to find this, I am a novice ...
Now has a built database, need to do data analysis based on the original data Web application, I choose Python+tornado, because do not want to write SQL statements, I want to steal a lazy
1. Installation Tools
1 [email protected]:~/code/py/django/logcloud$ sudo pip install sqlacodegen2 downloading/unpacking sqlacodegen3 Downloading Sqlacodegen-1.1.6-py2.py3-none-any.whl4 downloading/unpacking inflect>=0.2.0 (from Sqlacodegen) 5 downloading INFLECT-0.2.5-PY2.PY3-NONE-ANY.WHL (58kB): 58kB downloaded6 requirement already satisfied (use-- Upgrade to upgrade): sqlalchemy>=0.6.0 in/usr/local/lib/python2.7/dist-packages (from Sqlacodegen) 7 installing Collected Packages:sqlacodegen, Inflect8 successfully installed Sqlacodegen inflect9 cleaning up ...
2. Conversion
[Email protected]:~/code/py/django/logcloud$ sqlacodegen mssql+pymssql://name:[email Protected]/LogColudDB-- OutFile Logcloude_model.py[email protected]:~/code/py/django/logcloud$
3. View, haha
[email protected]:~/code/py/django/logcloud$ cat logcloude_model.py# coding:utf-8from sqlalchemy Import BigInteger, Column, DateTime, Float, ForeignKey, Integer, Largebinary, T able, Unicode, Textfrom Sqlalch Emy.dialects.mssql.base Import bitfrom sqlalchemy.orm import relationshipfrom sqlalchemy.ext.declarative Import Declarative_basebase = declarative_base () metadata = Base.metadataclass Authorityinfo (base): __tablename__ = ' Authority Info ' ID = Column (BigInteger, primary_key=true) Description = column (Unicode (' Max '), nullable=false) Isdelete = C Olumn (BIT, nullable=false) authorityindex = Column (Integer, nullable=false) authorityname = column (Unicode (' Max '), n Ullable=false) class Cpkinfohistory (Base): __tablename__ = ' cpkinfohistory ' PO = Column (Unicode), primary_key=true ) ProcessName = column (Unicode (nullable=false), Result = column (Unicode (' Max '), nullable=false) Lastlogid = C Olumn (BigInteger, Nullable=false) class computerState (Base): __tablename__ = ' computerstate ' Name = column (Unicode (), primary_key=true) Ip = column (Unicode (50) , nullable=false) isdelete = Column (BIT, nullable=false) lastdate = Column (DateTime, nullable=false) isproceted = Column (BIT, Nullable=false) class DeviceInfo (Base): __tablename__ = ' deviceinfo ' ID = Column (BigInteger, Primary_key =true) ClientName = column (Unicode (), nullable=false) Description = column (Unicode (1024x768)) isdelete = column (BIT , nullable=false) linesinfo_id = Column (ForeignKey (U ' linesinfo.id '), Nullable=false, index=true) Linesinfo = Relatio Nship (U ' linesinfo ') class Disposeerrorcodeinfo (Base): __tablename__ = ' disposeerrorcodeinfo ' ID = Column (BigInteger, primary_key=true) newoperation = column (Unicode (' Max '), nullable=false) Status = column (Unicode (' Max '), Nullable=fal SE) disposeinfo_id = column (ForeignKey (U ' disposeinfo.id '), Nullable=false, index=true) errorcode_info_id = column (Fo Reignkey (U ' errorcode_infO.id '), Nullable=false, index=true) errorcode_operationid = Column (BigInteger, nullable=false) weightvalue = column ( Integer, nullable=false) disposeinfo = relationship (U ' disposeinfo ') errorcode_info = relationship (U ' errorcodeinfo ') c Lass Disposeerrorcodeinfohistory (Base): __tablename__ = ' disposeerrorcodeinfohistory ' ID = Column (BigInteger, Primar y_key=true) operatetime = Column (DateTime, nullable=false) oldstatus = column (Unicode (' Max '), Nullable=false) New Status = Column (Unicode (' Max '), nullable=false) isdelete = Column (BIT, nullable=false) weightvalue = column (Integer, Nullable=false) userinfo_id = Column (ForeignKey (U ' userinfo.id '), Nullable=false, index=true) disposeerrorcodeinfo_i D = Column (ForeignKey (U ' disposeerrorcodeinfo.id '), Nullable=false, in Dex=true) disposeerrorcodeinfo = Relationship (U ' disposeerrorcodeinfo ') UserInfo = relationship (U ' UserInfo ') class Disposeinfo (Base): __tablename__ = ' Disposeinfo ' ID = COlumn (BigInteger, primary_key=true) operation = column (Unicode (' Max '), nullable=false) IsOK = Column (BIT, nullable=f alse) Description = column (Unicode (1024x768)) touchtime = Column (DateTime, nullable=false) noticeinfo_id = column (for Eignkey (U ' noticeinfo.id '), Nullable=false, index=true) usertask_id = Column (ForeignKey (U ' usertask.id '), nullable= False, index=true) noticeinfo = relationship (U ' noticeinfo ') Usertask = relationship (U ' usertask ') class Errorcodeinfo ( Base): __tablename__ = ' errorcode_info ' ID = Column (BigInteger, primary_key=true) ErrorCode = Column (Unicode (10), Nullable=false) Description = column (Unicode (1024x768)) isdelete = Column (BIT, Nullable=false) class Errorcodeoperation ( Base): __tablename__ = ' errorcode_operation ' ID = Column (BigInteger, primary_key=true) operation = Column (Unicode (' Max '), nullable=false) weightvalue = Column (Integer, nullable=false) isenable = Column (BIT, Nullable=false) ERR orcode_info_id = Column (ForeigNkey (U ' errorcode_info.id '), Nullable=false, index=true) errorcode_info = relationship (U ' errorcodeinfo ') class Filesmanage (Base): __tablename__ = ' filesmanage ' ID = Column (BigInteger, primary_key=true) ClassName = column (Uni Code (a), Nullable=false, index=true) Md5 = Column (Unicode (+), nullable=false) Data = Column (Largebinary, nullable= False) Ver = Column (Integer, nullable=false) DateCreated = column (Unicode (), nullable=false) Uploadusername = C Olumn (Unicode (), nullable=false) Remarks = column (Unicode (' Max ')) catagory = column (Unicode (), Nullable=false) localfilename = Column (Unicode) class Loginfo (Base): __tablename__ = ' log_info ' ID = Column (BigInteger, primary _key=true) Po = column (Unicode (ten), Nullable=false, index=true) ProcessName = column (Unicode), Nullable=false, in dex=true) User = column (Unicode (ten), nullable=false) ErrorCode = column (Unicode ()) Log = column (Unicode (' Max '), Nullable=false) Barcode = ColuMN (Unicode ()) Isn = column (Unicode ()) Shift = column (Unicode (ten), nullable=false) testresult = column (Unicode (ten), Nullable=false, index=true) lastdate = Column (DateTime, nullable=false) ClientName = column (Unicode), nulla Ble=false, Index=true) class Linesinfo (Base): __tablename__ = ' linesinfo ' ID = Column (BigInteger, Primary_key=true) Name = column (Unicode (), nullable=false) Description = column (Unicode (1024x768)) isdelete = Column (BIT, Nullable=fal SE) class Noticeinfo (Base): __tablename__ = ' noticeinfo ' ID = Column (BigInteger, primary_key=true) Top1_errorcodei D = Column (BigInteger, nullable=false) top2_errorcodeid = column (BigInteger) top3_errorcodeid = column (BigInteger) touchtime = Column (DateTime, nullable=false) isdispose = Column (BIT, nullable=false) tasklavel = column (Integer, n Ullable=false) responsibility_id = Column (ForeignKey (U ' responsibility.id '), Nullable=false, index=true) UserTask_ID = Column (ForeignKey (U ' UsErtask.id '), Nullable=false, index=true) deviceinfo_id = Column (ForeignKey (U ' deviceinfo.id '), Nullable=false, index= True) statisticsinfo_id = Column (BigInteger, nullable=false) deviceinfo = relationship (U ' deviceinfo ') Responsibil ity = Relationship (U ' Responsibility ') Usertask = relationship (U ' usertask ') class Poinfo (Base): __tablename__ = ' Poinf O ' ID = column (BigInteger, primary_key=true) Po = column (Unicode (ten), nullable=false) Plm = column (Unicode (20)) ProductName = column (Unicode ()) Description = column (Unicode (1024x768)) isdelete = Column (BIT, Nullable=false) Cu stomer = Column (Unicode) class Responsibility (Base): __tablename__ = ' Responsibility ' ID = Column (BigInteger, PRI mary_key=true) ProcessName = Column (Unicode (ten), nullable=false) basenumber = Column (Integer, Nullable=false) ERR orrate = Column (Float), nullable=false) Description = column (Unicode) overtime = column (Integer, nullable=f alse) poinfo_id = Column(ForeignKey (U ' poinfo.id '), Nullable=false, Index=true) userinfo_id = Column (ForeignKey (U ' userinfo.id '), Nullable=false, index=true) poinfo = relationship (U ' poinfo ') UserIn fo = relationship (U ' UserInfo ') class Roleauthority (Base): __tablename__ = ' roleauthority ' ID = Column (BigInteger, PRI mary_key=true) isdelete = Column (BIT, nullable=false) roleinfo_id = column (ForeignKey (U ' roleinfo.id '), nullable=fals E, index=true) authorityinfo_id = Column (ForeignKey (U ' authorityinfo.id '), Nullable=false, index=true) AuthorityInfo = Relationship (U ' authorityinfo ') roleinfo = relationship (U ' roleinfo ') class Roleinfo (Base): __tablename__ = ' Roleinfo ' ID = column (BigInteger, primary_key=true) RoleName = column (Unicode), nullable=false) Description = column ( Unicode (1024x768)) isdelete = Column (BIT, nullable=false) rolelevel = Column (Integer, Nullable=false) class Settinginfo (B ASE): __tablename__ = ' settinginfo ' ID = Column (BigInteger, primary_key=true, NULLAble=false) Key = column (Unicode (), Primary_key=true, nullable=false) Value = column (Unicode (' Max '), nullable=fals e) Description = column (Unicode (1024x768)) class Statisticsinfo (Base): __tablename__ = ' statisticsinfo ' ID = column (Bi Ginteger, primary_key=true) ProcessName = Column (Unicode (ten), nullable=false) BeginTime = Column (DateTime, nullable= False) nowerrorrate = column (Float), nullable=false) times = column (Integer, nullable=false) isoutmoded = Colu Mn (BIT, nullable=false) poinfo_id = Column (ForeignKey (U ' poinfo.id '), Nullable=false, index=true) deviceinfo_id = Col Umn (ForeignKey (U ' deviceinfo.id '), Nullable=false, index=true) deviceinfo = relationship (U ' deviceinfo ') POInfo = RelA Tionship (U ' poinfo ') class UserInfo (Base): __tablename__ = ' UserInfo ' ID = Column (BigInteger, primary_key=true) Nam e = column (Unicode (ten), nullable=false) jobnumber = column (Unicode), nullable=false) Phone = column (Unicode (20)) Emil = Column (Unicode(+), nullable=false) Department = column (unicode) duties = column (Unicode)) Description = column (Unicode ( ) Group = column (Unicode (), nullable=false) isdelete = Column (BIT, nullable=false) Password = column (Unico De (+)) Createdatetime = Column (DateTime, Nullable=false) class UserProfile (Base): __tablename__ = ' userprofile ' U Serid = Column (Integer, primary_key=true) UserName = column (Unicode (), Nullable=false, Unique=true) class Userroleinfo (Base): __tablename__ = ' userroleinfo ' ID = Column (BigInteger, primary_key=true) isdelete = Column (BIT, nullable= False) userinfo_id = column (ForeignKey (U ' userinfo.id '), Nullable=false, index=true) roleinfo_id = column (ForeignKey ( U ' roleinfo.id '), Nullable=false, index=true) roleinfo = relationship (U ' roleinfo ') UserInfo = relationship (U ' UserInfo ') class Usertask (Base): __tablename__ = ' usertask ' ID = Column (BigInteger, primary_key=true) tasklavel = column (I Nteger, Nullable=false) Shift = Column (Unicode (ten), nullable=false) Description = column (unicode) isdelete = column (BIT, nullable=f alse) userinfo_id = column (ForeignKey (U ' userinfo.id '), Nullable=false, index=true) linesinfo_id = column (ForeignKey ( U ' linesinfo.id '), Nullable=false, index=true) linesinfo = relationship (U ' linesinfo ') UserInfo = relationship (U ' UserI NFO ') t_view_linesstate = Table (' view_linesstate ', metadata, column (' ID ', BigInteger, Nullable=false), column (' Cl Ientname ', Unicode (+), Nullable=false), column (' linesinfo_id ', BigInteger, Nullable=false), column (' Count ', Integer ) T_view_logstate = Table (' view_logstate ', metadata, column (' Po ', Unicode (Ten), Nullable=false), column (' Processn Ame ', Unicode (Ten), Nullable=false), column (' ErrorCode ', Unicode ()), column (' ClientName ', Unicode (), Nullable=fal SE), column (' ID ', BigInteger), column (' Count ', Integer)) T_view_noticeinfo = Table (' view_noticeinfo ', metadata, Column (' ID ', BigintegeR, Nullable=false), column (' Touchtime ', DateTime, Nullable=false), column (' Top1_errorcodeid ', BigInteger, nullable=f alse), column (' Top2_errorcodeid ', BigInteger), column (' Top3_errorcodeid ', BigInteger), column (' Isdispose ', BIT, n ULLABLE=FALSE), column (' Tasklavel ', Integer, Nullable=false), column (' ClientName ', Unicode ()), column (' Processn Ame ', Unicode (Ten)), column (' BeginTime ', DateTime), column (' Nowerrorrate ', Float ()), column (' Times ', Integer), Column (' isoutmoded ', BIT), column (' Po ', Unicode (Ten))) T_view_top1_error = Table (' view_top1_error ', metadata, Co Lumn (' Top1_errorcodeid ', BigInteger, Nullable=false), column (' Count ', Integer), column (' ID ', BigInteger, NULLABLE=FA LSE), column (' ErrorCode ', Unicode (Ten), Nullable=false), column (' Description ', Unicode (1024x768))) class Webpagesmembershi P (Base): __tablename__ = ' webpages_membership ' UserId = Column (Integer, primary_key=true) createdate = column (Dat ETime) ConfirmationtoKen = column (Unicode) isconfirmed = Column (BIT, Server_default=text ("(0))") lastpasswordfailuredate = column ( DateTime) passwordfailuressincelastsuccess = Column (Integer, Nullable=false, Server_default=text ("(0 )) Password = Column (Unicode (+), nullable=false) passwordchangeddate = column (DateTime) PasswordSalt = Colu MN (Unicode (+), nullable=false) Passwordverificationtoken = Column (Unicode) Passwordverificationtokenexpirati Ondate = Column (DateTime) class Webpagesoauthmembership (Base): __tablename__ = ' webpages_oauthmembership ' Provider = Column (Unicode (+), Primary_key=true, nullable=false) Provideruserid = Column (Unicode), Primary_key=true, Nullable=false) UserId = Column (Integer, Nullable=false) class Webpagesrole (Base): __tablename__ = ' webpages_roles ' Roleid = Column (Integer, primary_key=true) RoleName = Column (Unicode, Nullable=false, unique=true) UserProfil E = Relationship (U ' userprofile ', secondary= ' webpages_usersinroles ') t_webpages_usersinroles = Table (' webpages_usersinroles ', metadata, Column (' UserId ', ForeignKey (U ' userprofile.userid '), Primary_key=true, Nullable=false), Column (' Roleid ', ForeignKey (U ' webpages_ Roles.roleid '), Primary_key=true, Nullable=false)) [email protected]:~/code/py/django/logcloud$
MySQL data table automatically leads to Python sqlalchemy actionable objects