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.8-cp313-cp313-win_amd64.whl (408.6 kB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13

easyorm_py-1.0.8-cp312-cp312-win_amd64.whl (415.3 kB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12

easyorm_py-1.0.8-cp311-cp311-win_amd64.whl (423.9 kB view details)

Uploaded CPython 3.11Windows x86-64

easyorm_py-1.0.8-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.8-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: easyorm_py-1.0.8-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 408.6 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.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e32792e732f0a3369cc5d1f1b233f4cc0eec7ddec22b44688ff4c60a81b7caab
MD5 17374b332a07edee3910079d7be14664
BLAKE2b-256 51f0dbebb9de987f485fa3d44f94711f48c5680f7e7a7f594cb43cdeb019645c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.8-cp313-cp313-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f8a91fca86ce8d1da2e930ed990832a9884e7b3424faee78a493e5bf1d55d32
MD5 a186da9a6f82e5e80ffd4ecb5dd9b41f
BLAKE2b-256 d574ef8d4ea9e0d89fa3ecb719b310d6b4e145b0b4f49a35fd807e31456d7d27

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easyorm_py-1.0.8-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 415.3 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.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0b4ac52df5253a241ee7017075eb867ac0d8ce7537854fc1ad4af754564c9894
MD5 d0f1cc19c36bee201a591b8495d0168c
BLAKE2b-256 0f0f7bd556a8c40713f8235dba90ec0251ad0e8eb8e54110a56067b55553289a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.8-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 23b009081ef1a97cc94dc3d7c110f48d7e97297408cded3fe3964a1e781733c7
MD5 7c27c3ee7a011eca498197d73863c847
BLAKE2b-256 131c7523f1c547f4b8c987bc7fe583835e171cae5c67912b243e7b547859e73c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easyorm_py-1.0.8-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 423.9 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.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f85d4cb4e33ebb9525c820bbcef71c5b53f29c87d72d99f5fb05ef67c01dbc05
MD5 97af5663a5b701611dff37389b954317
BLAKE2b-256 878ad608891caa226d4191a402545b1d420346ccc5e9b5a241761e204ec1dd1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.8-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 05a6536b46374a5561723f6ff8c581142b8a9d075c24da7a563b35290b6e11dd
MD5 16642715074589025be3260dc0a187db
BLAKE2b-256 ac761c7c51d0c670446267a894da346fcf5832d2363ac89d21bfd551a39e8ee1

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