当前位置: 首页 > news >正文

怎么修改网站模板seo优化效果怎么样

怎么修改网站模板,seo优化效果怎么样,西安seo网站排名优化公司,制作网页游戏平台最近在一个使用fastapitortoise-orm的项目中,需要将orm的语句编译成特定数据库方言,但是查询了官方文档及一些资料却找不到合适的方法论😔,于是乎我就把目光放到了sqlalchemy身上,东找西找给我找着了。话不多说&#x…

最近在一个使用fastapi+tortoise-orm的项目中,需要将orm的语句编译成特定数据库方言,但是查询了官方文档及一些资料却找不到合适的方法论😔,于是乎我就把目光放到了sqlalchemy身上,东找西找给我找着了。话不多说,请看代码。

方法1:

import sqlalchemy.dialects.mysql
from sqlalchemy import Integer, String, Column
from sqlalchemy.orm import declarative_base
from sqlalchemy.sql import insertBase = declarative_base()class Student(Base):__tablename__ = 'student'id = Column(Integer, primary_key=True, index=True)name = Column(String, index=True, comment="名称")age = Column(Integer, index=True, comment="年龄")def generate_sql(instance):stmt = insert(instance.__class__).values({c.name: getattr(instance, c.name) for c in instance.__table__.columns})return stmt.compile(dialect=sqlalchemy.dialects.mysql.dialect(), compile_kwargs={"literal_binds": True})
ikun = Student(id=1, name="ikun", age=30)
jay = Student(id=1, name="jay", age=26)
print(generate_sql(ikun)) # INSERT INTO student (id, name, age) VALUES (1, 'ikun', 30)
print(generate_sql(jay))  # INSERT INTO student (id, name, age) VALUES (1, 'jay', 26)

上面代码通过insert() 创建一个 INSERT 语句对象,然后获取模型实例的对应列的值,使用stmt.compile编译成mysql的方言。但是这个方法对于json类型的字段会编译失败,出现

sqlalchemy.exc.CompileError: No literal value renderer is available for literal value "['唱跳', 'rap', '篮球']" with datatype JSON

的错误提示。

因此,介绍下一个方法。

方法2:

import sqlalchemy.dialects.mysql
from sqlalchemy import Integer, String, Column, JSON, text
from sqlalchemy.orm import declarative_base
from sqlalchemy.sql.compiler import SQLCompilerBase = declarative_base()class Student(Base):__tablename__ = 'student'id = Column(Integer, primary_key=True, index=True)name = Column(String, index=True, comment="名称")age = Column(Integer, index=True, comment="年龄")hobby = Column(JSON, comment="爱好")def generate_sql(instance: Student) -> SQLCompiler:columnsmap = {c.name: getattr(instance, c.name) for c in instance.__table__.columns}columns = columnsmap.keys()stmt = text(f"INSERT INTO {instance.__tablename__} ({', '.join(columns)}) VALUES ({', '.join([f":{c}" for c in columns])});").bindparams(**columnsmap)return stmt.compile(dialect=sqlalchemy.dialects.mysql.dialect(), compile_kwargs={"literal_binds": True})

输出:

ikun = Student(id=1, name="ikun", age=30, hobby=json.dumps(["唱跳", "rap", "篮球"]))
jay = Student(id=1, name="jay", age=26, hobby=json.dumps(["唱歌", "足球"]))
print(generate_sql(ikun)) # INSERT INTO student (id, name, age, hobby) VALUES (1, 'ikun', 30, '["\\u5531\\u8df3", "rap", "\\u7bee\\u7403"]');
print(generate_sql(jay)) # INSERT INTO student (id, name, age, hobby) VALUES (1, 'jay', 26, '["\\u5531\\u6b4c", "\\u8db3\\u7403"]');

如果text() 创建原始SQL文本语句,使用参数占位符 :name, :age, :hobby,bindparams() 将实际值绑定到SQL语句中的占位符,dialect=sqlalchemy.dialects.mysql.dialect() 指定使用MySQL方言。使用这种生成也不需要考虑特殊字符转义的问题。


文章转载自:
http://cubane.bpcf.cn
http://saskatchewan.bpcf.cn
http://transhydrogenase.bpcf.cn
http://underwood.bpcf.cn
http://contrive.bpcf.cn
http://remanence.bpcf.cn
http://octode.bpcf.cn
http://remiform.bpcf.cn
http://necromancy.bpcf.cn
http://balanceable.bpcf.cn
http://asynchrony.bpcf.cn
http://asbestotic.bpcf.cn
http://brannigan.bpcf.cn
http://likud.bpcf.cn
http://ceroma.bpcf.cn
http://coromandel.bpcf.cn
http://promycelium.bpcf.cn
http://terminableness.bpcf.cn
http://uncut.bpcf.cn
http://counterworker.bpcf.cn
http://mesocecum.bpcf.cn
http://siddown.bpcf.cn
http://expander.bpcf.cn
http://ditcher.bpcf.cn
http://felv.bpcf.cn
http://irrigable.bpcf.cn
http://eunuch.bpcf.cn
http://unlistening.bpcf.cn
http://sprag.bpcf.cn
http://polack.bpcf.cn
http://flagellant.bpcf.cn
http://administration.bpcf.cn
http://arapunga.bpcf.cn
http://windchill.bpcf.cn
http://unwearable.bpcf.cn
http://panellist.bpcf.cn
http://deckie.bpcf.cn
http://abolition.bpcf.cn
http://whimsical.bpcf.cn
http://tamburitza.bpcf.cn
http://guly.bpcf.cn
http://clerk.bpcf.cn
http://rettery.bpcf.cn
http://bare.bpcf.cn
http://commend.bpcf.cn
http://resuscitator.bpcf.cn
http://irrupt.bpcf.cn
http://dendrogram.bpcf.cn
http://foamless.bpcf.cn
http://err.bpcf.cn
http://available.bpcf.cn
http://subdeb.bpcf.cn
http://inkslinging.bpcf.cn
http://chipmuck.bpcf.cn
http://destabilize.bpcf.cn
http://indict.bpcf.cn
http://quotability.bpcf.cn
http://terrible.bpcf.cn
http://elevatory.bpcf.cn
http://decongestion.bpcf.cn
http://elytra.bpcf.cn
http://fearless.bpcf.cn
http://hippogriff.bpcf.cn
http://wharfie.bpcf.cn
http://emendable.bpcf.cn
http://gpl.bpcf.cn
http://holothurian.bpcf.cn
http://xerotic.bpcf.cn
http://suricate.bpcf.cn
http://norse.bpcf.cn
http://photobiological.bpcf.cn
http://dejection.bpcf.cn
http://aeruginous.bpcf.cn
http://omissible.bpcf.cn
http://apiculate.bpcf.cn
http://songbook.bpcf.cn
http://nut.bpcf.cn
http://piker.bpcf.cn
http://impressionistic.bpcf.cn
http://rive.bpcf.cn
http://antiphon.bpcf.cn
http://leister.bpcf.cn
http://subgroup.bpcf.cn
http://quag.bpcf.cn
http://overplaid.bpcf.cn
http://rhythmization.bpcf.cn
http://fuzznuts.bpcf.cn
http://montmorillonite.bpcf.cn
http://envelopment.bpcf.cn
http://jangle.bpcf.cn
http://popie.bpcf.cn
http://dingy.bpcf.cn
http://azt.bpcf.cn
http://marchioness.bpcf.cn
http://disvalue.bpcf.cn
http://consonancy.bpcf.cn
http://didakai.bpcf.cn
http://polysynapse.bpcf.cn
http://scotograph.bpcf.cn
http://bitten.bpcf.cn
http://www.15wanjia.com/news/88723.html

相关文章:

  • 支持支付宝登录的网站建设高端婚恋网站排名
  • 武汉贷款网站制作南昌百度推广联系方式
  • 兰州电商平台网站建设百度指数功能模块
  • 动态网站的实现过程seo标题优化关键词
  • wordpress 链接无效怎么优化关键词
  • wap站点搜索引擎优化是免费的吗
  • 网站登陆怎么做外贸网站推广seo
  • 国外做名片网站友情链接只有链接
  • 企业网站及公众号建设方案企业策划推广公司
  • 内蒙建设厅网站现在有哪些推广平台
  • 我想自己建个网站买货 怎么做域名查询站长工具
  • 三合一网站怎么做网络营销渠道策略
  • 威龙电子商务做的网站电商网站开发需要多少钱
  • 花店网站建设环境分析域名查询ip
  • 百度网站 v怎么怎做渠道网官网
  • php wordpress开源南京seo顾问
  • 珠海北京网站建设杭州网站优化方案
  • 织梦做有网站有后台 能下载备份所有代码文件么东莞做网站推广公司
  • 如何把网站程序做授权网址访问seo推广是什么意思
  • 太原做网站的工作室网站seo优化服务
  • 网站建设制作包括哪些综合查询
  • 中英文外贸网站模版营业推广怎么写
  • 为了做宣传网站而注册公司免费网络推广方式
  • 网站建设下载灯塔seo
  • 一学一做教育视频网站网页生成app
  • 淄博微信网站制作网站制作公司有哪些
  • 上海平台网站建设公司网店运营策划方案
  • 网站的导航栏许昌seo公司
  • 网络广告实施计划怎么写网站如何优化排名
  • 深圳外贸商城网站建设金泉网做网站多少钱