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",
    },
    "default": {
        "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.5-cp313-cp313-win_amd64.whl (389.0 kB view details)

Uploaded CPython 3.13Windows x86-64

easyorm_py-1.0.5-cp313-cp313-manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.13

easyorm_py-1.0.5-cp312-cp312-win_amd64.whl (395.8 kB view details)

Uploaded CPython 3.12Windows x86-64

easyorm_py-1.0.5-cp312-cp312-manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12

easyorm_py-1.0.5-cp311-cp311-win_amd64.whl (403.5 kB view details)

Uploaded CPython 3.11Windows x86-64

easyorm_py-1.0.5-cp311-cp311-manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.11

File details

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

File metadata

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

File hashes

Hashes for easyorm_py-1.0.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0fb06e90ebc70331e2365ddfbbe49baecfa9f68fd4ebd19d1f51d5470aac133b
MD5 7ac805087ee9c2177990cfbfa227280b
BLAKE2b-256 54205dbfafaf9c4ffcd05c6e38bb08e1937f7446eca31d3d709f589ef79c7359

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.5-cp313-cp313-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a914e81c2494aa0da4439d993a2d15be3de7ae3cb3e7e9ef99a064125d38853f
MD5 efde06859ed5369074fb5874da4be65c
BLAKE2b-256 d563f956e136c510ba240eeea1b9f279bb02a4e58ebf1ea50a0e4ebb0d174cc0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for easyorm_py-1.0.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 62efaafe0561bcd7400a28e3dbdf6b818347557f33b8ce25cca9c0ff780eef54
MD5 d42cd1bbd298e0b166edd04172e7f016
BLAKE2b-256 490b4fc12e974805a28ba26b6d90a3623d13d94da40d81b3f98e615160114d7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.5-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 37e21cad1f09ba8a9c53dda921e3f263d88111044dd2e46686e1454f13adb0be
MD5 e8f62f2a1146e789135ce7532a16ba38
BLAKE2b-256 429e937541062922b8a053b9f109b4e1eac52aa585f03e20e93948be12792fe5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for easyorm_py-1.0.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 944446447ba9ebd822ca8a4e475a54de5b27e6045cb11e2f8127cfc4ff0f6400
MD5 0d1abce73a0a67a49a327f43f3da42b8
BLAKE2b-256 97c3ee7e12eeeb19499794950d4286227e36e7c9696ffa351862c4fefce2fac5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.5-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c176cee71e22a0dcf29289dfe9d6f871bcdd0ec1b8d17048966fb4221d8c58b
MD5 1873bbcc3cb6e83feedb6298d5d1bcd2
BLAKE2b-256 15087c082c7caff82151a3cce82be3ec8579b2cdbe9d27600c0650690c55676a

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