您的当前位置:首页正文

python+peewee的表格创建与设备常见操作

2024-11-28 来源:个人技术集锦

数据库表格创建

from peewee import MySQLDatabase, Model, IntegerField, CharField, DateTimeField

db = MySQLDatabase("test_api", host="10.35.148.22", user="test", password="123456", port=3306)


class BaseModel(Model):
    class Meta:
        database = db


class User(BaseModel):
    nid = CharField(primary_key=True)
    name = CharField()
    pgid = CharField()
    password = CharField(default="123456")
    level = IntegerField(default=1)
    phone = CharField(null=True)
    email = CharField(null=True)
    status = IntegerField(default=1)    # 1表示存在,0表示已删除

设备创建

id: 18
method: "device.create"
params: {
gid: "1CqPB0nXzRLaRcdrwmcaLeL0XicM"
mac: "20:21:11:18:00:01"
name: "XT500"
type: 65536
ucode: "202111180001ABC"
}

设备查找

id: 19
method: "device.search"
params: {
gid: "1CqPB0nXzRLaRcdrwmcaLeL0XicM"
ignoreChild: false
location: {begin: 0, end: 9}
begin: 0
end: 9
types: [65536]
0: 65536
}

设备绑定

id: 46
method: "device.binding"
params: {
nid: "5248057356"
ucode: "202111180001ABC"
}

设备修改

id: 47
method: "device.modify"
params: {name: "XT500", ucode: "202111180001ABC"}
name: "XT500"
ucode: "202111180001ABC"

设备解绑

id: 20
method: "device.delBinding"
params: {ucode: "202111180001ABC", nid: "5248057356"}
nid: "5248057356"
ucode: "202111180001ABC"

设备删除

id: 12
method: "device.delete"
params: {ucode: "202111180001ABC"}
ucode: "202111180001ABC"

unittest使用记录

testunit = unittest.TestSuite()
testunit.addTest(ContactDeleteGroup("test_delete_group"))
runner = unittest.TextTestRunner()
runner.run(testunit)
显示全文