一、增删查改
user = {"id": 2, "mobile": "2313", "name": "2313"} company = {"id": 2, "name": "2313", "creator_id": 2313} match = {'id': 6} values = {'iint': 7, 'sstr': '2443349403', 'user': user, 'company': company, 'id': 3} start_time = time.time() ts = await Test.all().values() ts = await Test.filter(**match).update(**values) ts = await Test.create(**values) crate_time = time.time() - start_time
二、连接设置
config = { 'connections': { # Dict format for connection 'default': { 'engine': 'tortoise.backends.asyncpg', 'credentials': { 'host': 'localhost', 'port': '5432', 'user': 'postgres', 'password': 'Emi,/****', 'database': 'xy', } }, # Using a DB_URL string # 'default': 'postgres://postgres:qwerty123@localhost:5432/events' }, 'apps': { 'models': { 'models': ['models'], # models.py 文件跟 main.py 在同一目录内 # If no default_connection specified, defaults to 'default' __main__ 'default_connection': 'default', } } } register_tortoise( app, config=config, config_file=None, db_url=None, modules={"models": ["models"]}, generate_schemas=False, add_exception_handlers=False )
标签:经验,Tortoise,models,default,user,time,config,id From: https://www.cnblogs.com/pearlcity/p/16746006.html