通过 WordPress Peewee Model 了解 WordPress 数据库结构

文 / @WordPress主题

WordPress数据库结构参考

我最近在使用Python的Tornado框架进行应用开发,并希望能够参考一下WordPress的数据库结构。因此,我使用了一个工具将WordPress的数据库转换成了PeeweeModel。通过这个Model,我们可以方便地了解WordPress的数据库结构并且可以直接在Peewee ORM中使用。

Peewee ORM WordPress模型

frompeeweeimport*

database=MySQLDatabase('www',**{'user':"'root'"})

classUnknownField(object):
pass

classBaseModel(Model):
classMeta:
database=database

classWpCommentmeta(BaseModel):
comment=BigIntegerField(db_column='comment_id')
meta=BigIntegerField(db_column='meta_id',primary_key=True)
meta_key=CharField(max_length=255,null=True)
meta_value=TextField(null=True)

classMeta:
db_table='wp_commentmeta'

classWpComments(BaseModel):
comment=BigIntegerField(db_column='comment_ID',primary_key=True)
comment_agent=CharField(max_length=255)
comment_approved=CharField(max_length=20)
comment_author=TextField()
comment_author_ip=CharField(db_column='comment_author_IP',max_length=100)
comment_author_email=CharField(max_length=100)
comment_author_url=CharField(max_length=200)
comment_content=TextField()
comment_date=DateTimeField()
comment_date_gmt=DateTimeField()
comment_karma=IntegerField()
comment_parent=BigIntegerField()
comment_post=BigIntegerField(db_column='comment_post_ID')
comment_type=CharField(max_length=20)
user=BigIntegerField(db_column='user_id')

classMeta:
db_table='wp_comments'

classWpLinks(BaseModel):
link_description=CharField(max_length=255)
link=BigIntegerField(db_column='link_id',primary_key=True)
link_image=CharField(max_length=255)
link_name=CharField(max_length=255)
link_notes=TextField()
link_owner=BigIntegerField()
link_rating=IntegerField()
link_rel=CharField(max_length=255)
link_rss=CharField(max_length=255)
link_target=CharField(max_length=25)
link_updated=DateTimeField()
link_url=CharField(max_length=255)
link_visible=CharField(max_length=20)

classMeta:
db_table='wp_links'

classWpOptions(BaseModel):
autoload=CharField(max_length=20)
option=BigIntegerField(db_column='option_id',primary_key=True)
option_name=CharField(max_length=64)
option_value=TextField()

classMeta:
db_table='wp_options'

classWpPostmeta(BaseModel):
meta=BigIntegerField(db_column='meta_id',primary_key=True)
meta_key=CharField(max_length=255,null=True)
meta_value=TextField(null=True)
post=BigIntegerField(db_column='post_id')

classMeta:
db_table='wp_postmeta'

classWpPosts(BaseModel):
id=BigIntegerField(db_column='ID',primary_key=True)
comment_count=BigIntegerField()
comment_status=CharField(max_length=20)
guid=CharField(max_length=255)
menu_order=IntegerField()
ping_status=CharField(max_length=20)
pinged=TextField()
post_author=BigIntegerField()
post_content=TextField()
post_content_filtered=TextField()
post_date=DateTimeField()
post_date_gmt=DateTimeField()
post_excerpt=TextField()
post_mime_type=CharField(max_length=100)
post_modified=DateTimeField()
post_modified_gmt=DateTimeField()
post_name=CharField(max_length=200)
post_parent=BigIntegerField()
post_password=CharField(max_length=20)
post_status=CharField(max_length=20)
post_title=TextField()
post_type=CharField(max_length=20)
to_ping=TextField()

classMeta:
db_table='wp_posts'

classWpTermRelationships(BaseModel):
object=BigIntegerField(db_column='object_id',primary_key=True)
term_order=IntegerField()
term_taxonomy=BigIntegerField(db_column='term_taxonomy_id')

classMeta:
db_table='wp_term_relationships'

classWpTermTaxonomy(BaseModel):
count=BigIntegerField()
description=TextField()
parent=BigIntegerField()
taxonomy=CharField(max_length=32)
term=BigIntegerField(db_column='term_id')
term_taxonomy=BigIntegerField(db_column='term_taxonomy_id',primary_key=True)

classMeta:
db_table='wp_term_taxonomy'

classWpTerms(BaseModel):
name=CharField(max_length=200)
slug=CharField(max_length=200)
term_group=BigIntegerField()
term=BigIntegerField(db_column='term_id',primary_key=True)

classMeta:
db_table='wp_terms'

classWpUsermeta(BaseModel):
meta_key=CharField(max_length=255,null=True)
meta_value=TextField(null=True)
umeta=BigIntegerField(db_column='umeta_id',primary_key=True)
user=BigIntegerField(db_column='user_id')

classMeta:
db_table='wp_usermeta'

classWpUsers(BaseModel):
id=BigIntegerField(db_column='ID',primary_key=True)
display_name=CharField(max_length=250)
user_activation_key=CharField(max_length=60)
user_email=CharField(max_length=100)
user_login=CharField(max_length=60)
user_nicename=CharField(max_length=50)
user_pass=CharField(max_length=64)
user_registered=DateTimeField()
user_status=IntegerField()
user_url=CharField(max_length=100)

classMeta:
db_table='wp_users'

这是我把WordPress数据库转化成的Peewee Model。你可以方便地使用这个Model并参考WordPress的数据库结构。希望能对你有所帮助!

添加UTHEME为好友
扫码添加UTHEME微信为好友
· 分享WordPress相关技术文章,主题上新与优惠动态早知道。
· 微信端最大WordPress社群,限时免费入群。