# coding=UTF8
"""
create time:2022-11-18 15:36:12
@Author :wyk
"""
from peewee import * # 流行的 ORM 框架,實(shí)現(xiàn)了對(duì)象與數(shù)據(jù)庫(kù)表的映射,兼容多種數(shù)據(jù)庫(kù),簡(jiǎn)單、快速的操作相應(yīng)數(shù)據(jù)庫(kù), 面向?qū)ο螅?
# 連接數(shù)據(jù)庫(kù)
db = MySQLDatabase('wyk',
host='localhost',
port=3306,
user='root',
passwd='******',
charset='utf8')
# 定義映射類
class Teacher(Model):
id = AutoField(primary_key=True)
name = CharField()
age = IntegerField()
class Meta:
database = db
# 創(chuàng)建表
# db.create_tables([Teacher])
# 新增數(shù)據(jù)
# t1 = Teacher(name='張三', age=22)
# t2 = Teacher(name='李四', age=23)
# t3 = Teacher(name='王五', age=24)
# t1.save()
# t2.save()
# t3.save()
# 查詢數(shù)據(jù)
t = Teacher.get(Teacher.age == 22) # 單條數(shù)據(jù)
print('name: {0}'.format(t.name))
ts = Teacher.select() # 多條數(shù)據(jù)
for t in ts:
print('name: {0}, age: {1}'.format(t.name, t.age))
# 修改數(shù)據(jù)
t2 = Teacher.update({Teacher.name:'張三'}).where(Teacher.id == 1)
t2.execute()
# 刪除數(shù)據(jù)
t3 = Teacher.delete().where(Teacher.id == 3)
t3.execute()
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
我們提供的服務(wù)有:網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、天門ssl等。為超過(guò)千家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的天門網(wǎng)站制作公司