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

天猫网站做链接怎么做青岛网站建设优化

天猫网站做链接怎么做,青岛网站建设优化,六盘水市住房和城乡建设局网站,动态个人网站模板下载Python 如何操作数据库,让你使用 DeepSeek 开发数据库应用更加快 操作数据库最好用 ORM 工具,可以提高开发效率. ORM 就是实体与数据库表的映射,让我们可以用面向对象的方式来操作数据库. 简单易用,直接上代码. 使用Orm Bee操作…

Python 如何操作数据库,让你使用 DeepSeek 开发数据库应用更加快

操作数据库最好用 ORM 工具,可以提高开发效率.

ORM 就是实体与数据库表的映射,让我们可以用面向对象的方式来操作数据库.

简单易用,直接上代码.

使用Orm Bee操作数据库


class Orders:id = None  name = None remark = None# can ignoredef __repr__(self): return  str(self.__dict__)# also can use field type as :int        
class Orders8:__tablename__ = "orders"id:int = None  name:str = None remark:str = Nonedef __repr__(self): return  str(self.__dict__)class Student2:id = Nonename = None age = None  remark = Noneaddr = Nonedef __repr__(self): return  str(self.__dict__)from bee.api import Suid, SuidRich
from bee.config import PreConfig
from bee.honeyfactory import BF
from bee.osql.bee_enum import Opif __name__ == "__main__":# set bee.properties/bee.json config folderPreConfig.config_path="E:\\Bee-Project\\resources"# select recordsuid = Suid()orderList = suid.select(Orders())  # select all# insert    orders = Orders()orders.id = 1orders.name = "bee"orders.remark = "test"suid = Suid()suid.insert(orders)# update/deleteorders = Orders()orders.name = "bee130"# For safety reasons# Fields that are not present in the entity will be ignored.orders.ext = "aaa"  orders.id = 1suid = Suid()n1 = suid.update(orders)n2 = suid.delete(orders)print(n1)print(n2)# batch insertstudent0 = Student2()student0.name = "bee"student1 = Student2()student1.name = "bee1"student1.addr = ""student1.age = 40entity_list = []entity_list.append(student0)entity_list.append(student1)suidRich = SuidRich()insertNum = suidRich.insert_batch(entity_list)print(insertNum)#how to use Condition for advanced query and updatecondition = BF.condition()condition.op("age", Op.ge, 22)condition.op("remark", Op.eq, None)stuList = suidRich.select(Student2(), condition)# select ... from student2 where age >= ? and remark is nullfor stu in stuList:print(stu)# all stu'age add 1 if id>5condition = BF.condition()condition.setAdd("age", 1)condition.op("id", Op.ge, 5)updateNum = suidRich.updateBy(Student2(), condition)# update student2 set age = age + ? where id >= ?print("updateNum:", updateNum)#SuidRich: insert_batch,select_first,updateBy#复杂的where过滤条件、group,having,order by,Update Set等可使用Condition;

代码讲解:

实体: Orders, Orders8, Student2

PreConfig.config_path="E:\\Bee-Project\\resources"   是用来声明配置文件所在的文件夹.

  主要代码: 

    suid = Suid()
    #查询所有记录
    orderList = suid.select(Orders())  # select all
    #插入一条记录
    suid.insert(orders)
    #更新,删除记录
    n1 = suid.update(orders)
    n2 = suid.delete(orders)

还有可以通过 Condition 构造出更加复杂的 where 条件和 Update 记录.

 # select ... from student2 where age >= ? and remark is null

# update student2 set age = age + ? where id >= ?

其它功能

主要API在bee.api.py
Suid: simple API for Select/Update/Insert/Delete
SuidRich : select_paging, insert_batch, updateBy, select_first,select_by_id,
delete_by_id,select_fun,count,exist,create_table,index_normal,unique
PreparedSql: select, select_dict, modify, modify_dict

要连接数据库,要配置基本的用户名等连接信息:

配置db连接信息
1.1.can custom your db Module
in bee.json or bee.properties set dbModuleName{"dbname": "SQLite",  "database": "bee.db", //default support: pymysql,sqlite3,cx_Oracle,psycopg2 (no need set)"dbModuleName":"sqlite3"}
#value is: MySql,SQLite,Oracle,
#MySQL config
#bee.db.dbname=MySQL
#bee.db.host =localhost
#bee.db.user =root
#bee.db.password =
#bee.db.database =bee
#bee.db.port=3306# SQLite
bee.db.dbname=SQLite
bee.db.database =bee.db
1.2.if do not want to use the default config file(bee.json or bee.properties),
can set the db_config info yourself.# #mysqldict_config = {  'dbname':'MySQL','host': 'localhost',  # 数据库主机  'user': 'root',  # 替换为您的 MySQL 用户名  'password': '',  # 替换为您的 MySQL 密码  'database': 'bee',  # 替换为您的数据库名称  'port':3306}honeyConfig= HoneyConfig()honeyConfig.set_db_config_dict(dict_config)1.3.set connection directly:config = {  # 'dbname':'MySQL','host': 'localhost',  # 数据库主机  'user': 'root',  # 替换为您的 MySQL 用户名  'password': '',  # 替换为您的 MySQL 密码  'database': 'bee',  # 替换为您的数据库名称  'port':3306}honeyConfig= HoneyConfig()honeyConfig.set_dbname("MySQL")conn = pymysql.connect(**config)factory=BeeFactory()factory.set_connection(conn)

--------------------------------------------

快速开始:

安装依赖包

在命令行输入以下命令:

pip install ormbee

ORM Bee pypi url:
https://pypi.org/project/ormbee/

ORM Bee in Python!
Bee(BeePy)是Python版的ORM工具(还有Java版的).

Bee in Python url:
https://github.com/automvc/BeePy

Bee in Java url:
https://github.com/automvc/bee

http://www.dtcms.com/wzjs/85868.html

相关文章:

  • 制作网站开发公司网络销售好不好做
  • 小程序外包商丘seo博客
  • 网站内容收录常用的seo网站优化排名
  • 企业网站优化公司有哪些淘宝seo培训
  • 学做网站需要多长时间京东关键词优化技巧
  • 河南建设资格执业网站以营销推广为主题的方案
  • 页面设计毕业论文8000字seo优化易下拉霸屏
  • 怎么做虚拟的网站晚上国网app
  • 注册网站需要什么条件深圳seo外包公司
  • 太原网站如何制作百度主页
  • 都江堰建设局官方网站品牌推广工作内容
  • 高级软件工程师seo关键词排名优化矩阵系统
  • wordpress网址导航模板seo搜索引擎优化题库
  • 建立个公司网站关键词优化系统
  • 软件项目实施流程日照seo优化
  • 做的好的大学生旅行有哪些网站好全国疫情高峰感染高峰进度
  • 生物学特色网站建设百度手机版网页
  • 道滘网站建设哈尔滨网络优化推广公司
  • 做美女图片网站合法吗东莞网络科技公司排名
  • 中国最新军事新闻最新消息视频百度搜索引擎优化指南最新版
  • 网站建设经费预算包括哪些坚决把快准严细实要求落实到位
  • 西安外贸网站建设91永久海外地域网名
  • 星月教你做网站回顾文档优化游戏性能的软件
  • 网站怎么屏蔽ip访问seo合作
  • 网站 别名培训中心
  • 做网站发现是传销昆明seo建站
  • 上海市建设工程安全质量监督总站网站百度快照怎么没有了
  • 棕色网站模板烟台seo关键词排名
  • 网站发展建设思路seo排名优化课程
  • 禅城南庄网站制作公司地址怎么弄在百度上显示