ORM框架,

天问 26e18c1a7b Update 'README.md' 3 weeks ago
README.md 26e18c1a7b Update 'README.md' 3 weeks ago

README.md

peewee

ORM框架,

Usage

pip install peewee

from peewee import SqliteDatabase
db = SqliteDatabase('my_database.db')


from peewee import Model, CharField, IntegerField

class Person(Model):
    name = CharField()
    age = IntegerField()

    class Meta:
        database = db  # 将模型与特定数据库连接关联


# 创建并插入新记录
person = Person.create(name='Alice', age=30)
# 或者
person = Person()
person.name = 'Bob'
person.age = 25
person.save()

# 查询所有记录
people = Person.select()
# 条件查询
young_people = Person.select().where(Person.age < 30)

# 更新记录
person = Person.get(Person.name == 'Alice')
person.age = 31
person.save()

# 删除记录
person = Person.get(Person.name == 'Bob')
person.delete_instance()


# 数据迁移
peewee migrations