python sanic orm_sanic中使用tortoise-orm

#models.py

from tortoise.models import Model

from tortoise import fields

class User(Model):

id = fields.IntField(pk=True, , source_field="userID")

name = fields.CharField(max_length = 100)

date_field = fields.DateTimeField()

# fields.ForeignKeyField("models.Books", on_delete = field.SET_NULL, null = True)

# def __str__(self):

# return self.name

class Meta:

table = "user" #数据表名字

unique_together=("field_a", "field_b")#唯一字段

indexes=("field_a", "field_b") #索引

ordering = ["name", "-date_field"] #默认排序

class Books(Model):

id = fields.IntField(pk=True, , source_field="bookID")

#config.py

db_config = {

'connections': {

你可能感兴趣的:(python,sanic,orm)