您的位置:首页 > 游戏 > 手游 > 企业公司网站管理系统_东莞市住建局局长_在线网页服务器_怎么样推广自己的公司

企业公司网站管理系统_东莞市住建局局长_在线网页服务器_怎么样推广自己的公司

2024/12/23 4:21:52 来源:https://blog.csdn.net/qq_37703224/article/details/142351159  浏览:    关键词:企业公司网站管理系统_东莞市住建局局长_在线网页服务器_怎么样推广自己的公司
企业公司网站管理系统_东莞市住建局局长_在线网页服务器_怎么样推广自己的公司

创建模型

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass Hero(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strsecret_name: strage: Optional[int] = None

创建表

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass Hero(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strsecret_name: strage: Optional[int] = Noneengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
SQLModel.metadata.drop_all(engine)
SQLModel.metadata.create_all(engine)

初始化表

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass Hero(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strsecret_name: strage: Optional[int] = Noneengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)

添加数据

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)u = User(name="张三")
fasm.add(engine, u)

查询所有数据

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三"))
fasm.add(engine, User(name="李四"))users = fasm.get_all(engine,User)
print(users)

根据字典查询数据

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三"))
fasm.add(engine, User(name="李四"))query = {"name":"张三"}
users = fasm.get_by_dict(engine,User, query)
print(users)

根据字典实现 or 查询

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三"))
fasm.add(engine, User(name="李四"))query = {"name": {"=": "张三", "==": "李四"}}
users = fasm.get_by_dict_or(engine, User, query)
print(users)

根据字典实现 and 查询

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strage: intengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三", age=22))
fasm.add(engine, User(name="李四", age=33))query = {"age": {">": 30, "<": 40}}
users = fasm.get_by_dict_and(engine, User, query)
print(users)

根据ID 查询

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strage: intengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三", age=22))
fasm.add(engine, User(name="李四", age=33))u = fasm.get(engine,User,1)
print(u)

更新数据

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strage: intengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三", age=22))
fasm.add(engine, User(name="李四", age=33))u = fasm.get(engine, User, 1)
print("xxxxxx", u)data = {"name": "张三 333"}
fasm.update(engine, u, data)u = fasm.get(engine, User, 1)
print("=======", u)

根据 ID 更新数据

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strage: intengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三", age=22))
fasm.add(engine, User(name="李四", age=33))data = {"name": "张三 333"}
fasm.update_id(engine, User,1, data)u = fasm.get(engine, User, 1)
print("=======", u)

删除数据

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strage: intengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三", age=22))
fasm.add(engine, User(name="李四", age=33))u = fasm.get(engine,User,1)
fasm.delete(engine,u)

根据 ID 删除数据

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strage: intengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三", age=22))
fasm.add(engine, User(name="李四", age=33))fasm.delete_id(engine,User,1)

根据分页查询数据

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strage: intengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三", age=22))
fasm.add(engine, User(name="李四", age=33))
fasm.add(engine, User(name="王五", age=33))users = fasm. get_page(engine,User,page=1,size=2)
print(users)

获取第一条数据

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strage: intengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三", age=22))
fasm.add(engine, User(name="李四", age=33))
fasm.add(engine, User(name="王五", age=33))u = fasm.get_first(engine,User,{"name":"张三"})
print(u)

判断数据是否存在

from typing import Optional
from sqlmodel import Field, SQLModel
import fastzdp_sqlmodel as fasmclass User(SQLModel, table=True):id: Optional[int] = Field(default=None, primary_key=True)name: strage: intengine = fasm.get_engine(password="zhangdapeng520", database="fastzdp_sqlmodel", echo=True)
fasm.init_table(engine)fasm.add(engine, User(name="张三", age=22))
fasm.add(engine, User(name="李四", age=33))
fasm.add(engine, User(name="王五", age=33))print(fasm.is_exists(engine,User,{"name":"张三"}))
print(fasm.is_exists(engine,User,{"name":"张三 33"}))

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com