Skip to main content

easy_orm

Project description

example

1. Load db config

db_test = {
    "raw_sql": True,
    "mapper_xml_path": "test_xml",
    "default": {
        "db_type": "mysql",
        "host": "127.0.0.1",
        "port": 3306,
        "user": "root",
        "password": "123456",
        "database": "template",
    },
    "test": {
        "db_type": "mysql",
        "host": "127.0.0.1",
        "port": 3306,
        "user": "root",
        "password": "123456",
        "database": "template",
    }
}

from easy_orm import EasyOrmConfig, DBConfig
db_config = DBConfig(db_test)
EasyOrmConfig(db_config)

2. edit xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "">
<mapper namespace="TestMapper">

    <select id="find_data_by_ids">
        select id, username from test where id in
        <foreach collection="id_list" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>

    <select id="test_page">
        select id, username from test
    </select>

    <select id="test_where" resultType="model.user.User">

        select id, username from test

        <where>
            <if test="params.get('id') is not None">
                id = #{id}
            </if>
        </where>

    </select>

    <insert id="add_data">
        insert into test (nickname, username) values ('xxx', 'xxx1')
    </insert>


    <update id="update_data_by_id">
        update test set nickname = #{nickname} where id = #{id}
    </update>


    <delete id="delete_data_by_id">
        delete from test where id = #{id}
    </delete>

</mapper>

3. Extend BaseMapper and Use

# TestMapper.py
from easy_orm import BaseMapper, Page, select_one, delete, datasource
from model.user import User

class TestMapper(BaseMapper):

    def find_data_by_ids(self, id_list: list): ...

    @select_one('select * from test where id = #{id}')
    def find_data_one(self, id: int): ...

    def test_page(self, page: Page): ...

    def test_where(self, id: int) -> list[User]: ...

    def add_data(self): ...

    def update_data_by_id(self, nickname: str, id: int): ...

    @delete('delete from test where id = #{id}')
    def delete_data_by_id2(self, id: int): ...

class TestService:

    @datasource("default", True)
    def test_find_user_one(self):
        TestMapper().find_data_one(1)
        self.test_find_user_one2()

    @datasource("test", True)
    def test_find_user_one2(self):
        TestMapper().find_data_one(1)

    
if __name__ == '__main__':
    
    test_service = TestService()
    test_service.test_find_user_one()
    
    test_mapper = TestMapper()
    test_mapper.find_data_by_ids([1, 2, 3])

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

easyorm_py-1.0.7-cp313-cp313-win_amd64.whl (409.3 kB view details)

Uploaded CPython 3.13Windows x86-64

easyorm_py-1.0.7-cp313-cp313-manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.13

easyorm_py-1.0.7-cp312-cp312-win_amd64.whl (415.9 kB view details)

Uploaded CPython 3.12Windows x86-64

easyorm_py-1.0.7-cp312-cp312-manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12

easyorm_py-1.0.7-cp311-cp311-win_amd64.whl (424.3 kB view details)

Uploaded CPython 3.11Windows x86-64

easyorm_py-1.0.7-cp311-cp311-manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11

File details

Details for the file easyorm_py-1.0.7-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: easyorm_py-1.0.7-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 409.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for easyorm_py-1.0.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3bafa0a5b907e7cb46953ad76b8b8bcd6c0b7dbf0eb2a349b4cdb0f79cbbc468
MD5 1cd4eb00fdfd25c14f7734b9e585b4b0
BLAKE2b-256 c0a60ee85423125f30fd3203223904ae8c498a6a836e8025bda77af81a968520

See more details on using hashes here.

File details

Details for the file easyorm_py-1.0.7-cp313-cp313-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for easyorm_py-1.0.7-cp313-cp313-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ada1a1fbe33be4b26c2f253a7e61a98abb3766521288b1fb8934732d46a2c690
MD5 86fdbb35806ecf1ce2c0747a0c1059e1
BLAKE2b-256 b077bee2b1c718348c8ce06bf6e836b945e2b817721ca1ed4b618afa4ba3e5f6

See more details on using hashes here.

File details

Details for the file easyorm_py-1.0.7-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: easyorm_py-1.0.7-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 415.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for easyorm_py-1.0.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 63a026c6d9469d57f7c44d5200d9c091cee3053d330ceb3166f0d333ca6e119c
MD5 289a0088386340c0fd6f3b90bbc23891
BLAKE2b-256 1381eceec35413e8c9eccc538468ad12f634e87e5cbb19f9a2c3a59980e96f58

See more details on using hashes here.

File details

Details for the file easyorm_py-1.0.7-cp312-cp312-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for easyorm_py-1.0.7-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 86d961159e2784a0ec35422f709134830b5717942f0a5cb152f92c82da5f5880
MD5 d4ffe6443f2c064f8e829b86caafce61
BLAKE2b-256 bedf24a34d44a005bd415cf4871e486c8abb010c9e98cfd1643a853d08d7109f

See more details on using hashes here.

File details

Details for the file easyorm_py-1.0.7-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: easyorm_py-1.0.7-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 424.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for easyorm_py-1.0.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b5afe2570bc4a9c063ece9f527093ba11089668d5167683369d7be057198c977
MD5 0fadfdaf214a70a9058889d14adf09b6
BLAKE2b-256 6f1758115c2a5856a259e621b52af10f75c6e6e664859b3fb4544e783ab3ae14

See more details on using hashes here.

File details

Details for the file easyorm_py-1.0.7-cp311-cp311-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for easyorm_py-1.0.7-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cf518714e39c5e0d8a35d34b2e91cb01574787210c6a9fba1d136e0a3886e9e0
MD5 0942184bbd7b761c72098f29d4d0322d
BLAKE2b-256 737b441186034a2fb9453eb8cefef9ce1c9395526543df245ed6fd8eaf40c431

See more details on using hashes here.

Supported by

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