Skip to main content

Aestate framework for Python,You can see:https://gitee.com/aecode/aestate

Project description

Aestate —— 多样化数据库查询

star star star

介绍

当前测试通过数据库有:

  • MySql8.0
  • Sqlserver2019
  • PostgreSQL 13.3

Aestate Framework 是一款基于Python语言开发的ORM框架, 你可以使用多种方式去实现基于对象方式的查询.

也就是相对于Java语言的Mybatis-Plus

比如使用类似Django的模式去使用:modelClass.orm.filter(*args, **kwargs)

或者SQLAlchemy的方式:find().where(**kwargs).group_by(*args)

或者像JavaHibernate一样:

@SelectAbst()
def find_all_F_where_id_in_and_name_like_order_by_id(self, **kwargs) -> list: ...


@Select("SELECT * FROM demo WHERE id=#{id} AND name=#{name}")
def find_all_where_id(self, id, name): ...

或者像JavaMybatis使用xml

<?xml version="1.0"?>
<aestate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="aestate  https://gitee.com/aecode/aestate-xml/blob/main/v1/tags.xsd"
         xmlns="aestate">
    <template id="templateField">
        id,name,password,create_time,update_time
        <description>测试模板</description>
    </template>
    <resultMap id="resultMapLeftJoin" type="example.table.demoModels.Demo">
        <result field="d1_id" properties="id"/>
        <result field="d1_name" properties="name"/>
        <result field="d1_password" properties="password"/>
        <foreign type="example.table.demoModels.Demo" name="demoJoin">
            <result field="d2_id" properties="id"/>
            <result field="d2_name" properties="name"/>
            <result field="d2_password" properties="password"/>
        </foreign>
    </resultMap>
    <item id="findAllById">
        <select resultType="resultMapLeftJoin">
            SELECT
            <!-- 导入查询的字段 -->
            <!--            <include from="templateField"/>-->
            <include from="tempSymbol"/>
            FROM demo as d1 LEFT JOIN demo as d2 ON d2.id = d1.id WHERE d1.id >
            <switch field="id">
                <case value="10">10</case>
                <case value="5">5</case>
                <default>#{id}</default>
            </switch>
            <if test="#{id}&gt;=20">AND d2.id > 20</if>
            <else>AND d2.id > 10</else>
            LIMIT 2

            <description>
                SELECT d1.`name` as d1_name,d1.`password` as d1_password,d1.`id` as d1_id, d2.`name` as
                d2_name,d2.`password` as d2_password,d2.`id` as d2_id FROM demo as d1 LEFT JOIN demo as d2 ON d2.id =
                d1.id WHERE d1.id > %s AND d2.id > 10 LIMIT 2
            </description>
        </select>
    </item>
</aestate>

相对于其他库有什么区别?

  • 首先Aestate是基于Django、SQLAlchemy、Mybatis、Mybatis-Plus、SpringJPA整合起来的一个数据库支持库, 融合了这么多第三方库首先一点就是他的操作方式是多种多样的。目前已有六种操作方法, 也就是Django模式、SQLAlchemy模式、xml模式、Mybatis-Plus模式,注解模式,原生模式。

  • 其次就是在兼容性方面,由于这个世界上的数据库种类太多了没办法做到统一, Aestate保留了对其他小众数据库的实现接口,尽可能多兼容数据库。

  • 数据库表方面,Django是会生成数据django自己系统内部的表,在迁移的时候呢如果做错一步可能对于新手 来讲后面的修复操作是极其难的,也未必能够在短时间内定位问题并修复。Aestate为了解决这个问题,将make 和手动建表尽可能的兼容,不会生成额外的表和数据,也不会捆绑某个特定系统,将pojo/model复制出来可以直接为下一个项目使用。

  • 缓存方面参考了Mybatis的实现方法并略微修改,Aestate有两个内存管理模块,用于保证数据的完整性, 当一些特别大的数据占满缓存时,Aestate 会尽量多的去分配内存保证数据完整性,除外才会去管理内存(不建议操作大于系统内存2/10的数据)。Aestate有弹性内存管理方式,会根据系统的执行自动调整缓存大小,尽可能的加快运行速度,减少对数据库的连接次数。

  • 自带日志和美化,不需要下载其他插件就可以把日志变色,自动保存日志,这个功能对于爱美的大兄弟简直就 是神仙般的存在(当然也可能只有我喜欢装逼)

  • 还有很多......

寻找志同道合的朋友一起开发Aestate
作者QQ:2075383131(云)
qq群:909044439(Aestate Framework)

先决条件

Python >=3.6 (其他版本没试过)
教程文档地址:http://doc.cacode.ren

更全面的教程和文档

安装

目前源代码仅开放在gitee,处于组织CACode下,仓库地址为:aestate 使用pip或anaconda安装Aestate

pip install aestate

conda install aestate 

注意请不要用国内镜像下载,只发布在 pypi.org 也就是pip的官方源下

qq群:909044439

我是新手,怎么快速入门呢?

你可以前往https://doc.cacode.ren跟着官方文档入门
也可以在B站 你在写臭虫 看视频学

操作方式太多了一下子学不会怎么办?

Aestate有五种方式,不是非要全部都会,我当时写的时候只是为了把很多语言的操作方式用Python实现,然后让其他语言转Python的开发者能够找到熟悉的感觉,例如

  1. Java专业户:用xml、方法名和注解
  2. Python专业户:用Django模式和SQLAlchemy模式
  3. 纯萌新:老老实实写SQL,先把基础练好

谁在使用 Aestate Framework 开发网站

CACode: https://cacode.ren
CocoZao 爬虫:https://ccz.cacode.ren

开源示例项目:gitee/aestate-example

更多示例项目请前往

👉 Go to canotf`s homepage on Gitee 👈

鸣谢

Cpython
DBPool
Simplejson
Gitee

感谢捐献

Spacexzm Canotf

CACode Development Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Aestate-1.0.5a1.tar.gz (78.0 kB view hashes)

Uploaded Source

Built Distribution

Aestate-1.0.5a1-py3-none-any.whl (110.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page