您现在的位置是:首页 > 文章详情

Python ORM Bee V1.5.2 上传 Python 中央仓库 PYPI

日期:2025-01-27点击:145

Pythone ORM Bee 是基于 Python 的 ORM 工具;让你使用 Python 开发数据库应用更简单!

pip install ormbee 简单命令即可安装

 

https://pypi.org/project/ormbee/

简单易用的ORM,开发数据库很快

主要功能

V1.5.2

基础功能稳定版

 

往期回顾:

V1.0 发布

V1.1 发布

V1.3发布

 

安装依赖包

在命令行输入以下命令:

pip install ormbee

 

快速开始:

1. 配置db连接信息

1.1.can custom your db Module

in bee.json or bee.properties set dbModuleName

1.2.if do not want to use the default config file(bee.json or bee.properties),

can set the db_config info yourself.

        # #mysql
        config = {  
            'dbName':'MySQL',
            'host': 'localhost',  # 数据库主机  
            'user': 'root',  # 替换为您的 MySQL 用户名  
            'password': '',  # 替换为您的 MySQL 密码  
            'database': 'bee',  # 替换为您的数据库名称  
            'port':3306
        }
        
        honeyConfig= HoneyConfig()
        honeyConfig.set_db_config_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.setConnection(conn)

 

2. 使用Bee操作数据库


class Orders:
    id = None  
    name = None 
    remark = None

    #can ignore
    def __repr__(self):  
        return  str(self.__dict__)
        
class Student2:
    id = None
    name = None 
    age = None  
    remark = None
    addr = None

    def __repr__(self): 
        return  str(self.__dict__)
        
        
from bee.api import Suid
from bee.config import PreConfig

if __name__=="__main__":
    
    #set bee.properties/bee.json config folder, can set project root for it
    PreConfig.config_folder_root_path="E:\\Bee-Project"
    
    # select record
    suid=Suid()
    orderList=suid.select(Orders()) #select all
    
    #insert    
    orders=Orders()
    orders.id=1
    orders.name="bee"
    orders.remark="test"
    
    suid=Suid()
    suid.insert(orders)
    
    #update/delete
    orders=Orders()
    orders.name="bee130"
    orders.ext="aaa"  #实体没有字段,会被忽略。出去安全考虑
    orders.id=1
    
    suid = Suid()
    n1= suid.update(orders)
    n2= suid.delete(orders)
    print(n1)
    print(n2)
    
    #batch insert
    student0=Student2()
    student0.name = "bee"
    student1=Student2()
    student1.name = "bee1"
    student1.addr=""
    student1.age=40
    entity_list=[]
    entity_list.append(student0)
    entity_list.append(student1)
    
    suidRich = SuidRich()
    insertNum = suidRich.insert_batch(entity_list)
    print(insertNum)

 

其它功能:

bee.api.py 为主要的接口

Suid : 简单易用的Select, Update, Insert, Delete的接口;

SuidRich: 功能丰富的Suid接口,有分页,批量插入等;

PreparedSql: 自定义sql, 可以让写自己书写性能高效的sql语句,接口封装更好用.

 

诚邀您的加入!

如果您还想添加什么功能,请到评论区告诉我们(技术交流群:479080944)。

项目首页:https://gitee.com/automvc/BeePy/

https://github.com/automvc/BeePy/

 

原文链接:https://www.oschina.net/news/331605/beepy-1-5-2-released
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章