feat: 新增技能扩展N9一章相关示例源码

This commit is contained in:
100gle
2022-12-15 09:02:32 +08:00
parent a93c74e29c
commit 7686cabcd2
9 changed files with 382 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import pathlib
import peewee as pw
db_url = pathlib.Path(__file__).parents[1].joinpath("./mydb.sqlite3")
db = pw.SqliteDatabase(db_url)
class BaseModel(pw.Model):
class Meta:
database = db
class User(BaseModel):
uid = pw.AutoField()
username = pw.CharField(max_length=10)
def __repr__(self) -> str:
return f"User<uid={self.uid}, username={self.username}>"
__str__ = __repr__
def main():
user = User.select().where(User.username.startswith("Jay")).get()
ok = user.delete_instance()
print(f"delete rows: {ok}")
stmt = User.delete().where(User.username.in_(["bill gates", "larry page"]))
ok = stmt.execute()
print(f"delete rows: {ok}")
if __name__ == '__main__':
main()