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


class BaseMapper(Generic[T]):


    @classmethod
    def session(cls):
        """
        get db session
        """

    def add(self, data: Any):
        """
        add
        :param data:
        :return:
        """
        

    def add_all(self, data: list):
        """
        add_all
        :param data:
        :return:
        """

    def select_all(self, statement=None):
        """
        select all
        :param statement:
        :return:
        """

    def select_one(self, statement=None):
        """
        select one
        :param statement:
        :return:
        """
        

    def select_by_id(self, id: int):
        """
        select by id
        :param id:
        :return:
        """

    def update_by_id(self, data: dict, selective: bool=False):
        """
        upate by id
        :param data:
        :param selective:
        :return:
        """

    def delete_by_id(self, id: int):
        """
        delete by id
        :param id: 
        :return: 
        """
        ...

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

class TestMapper(BaseMapper[User]):

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13

easyorm_py-1.0.9-cp312-cp312-win_amd64.whl (415.6 kB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12

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

Uploaded CPython 3.11Windows x86-64

easyorm_py-1.0.9-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.9-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: easyorm_py-1.0.9-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 409.0 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.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b123bd08c47af4fd524272296ef5d8de97ffe63cdbe093e7f1adb7065563cdab
MD5 c8fd2f10e4c2175f72ea1c88a709c6ae
BLAKE2b-256 d7857e69889b18d23129830f3ddfa7daa9355800b3541e9cd4a98e1ab99b35b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.9-cp313-cp313-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e33f68fd5b967a28e11c20182484afaeeeb1642a4696d10c59fbfdcea3c6f2f1
MD5 8ef8a69390eca9ffdeb31083fd7252e9
BLAKE2b-256 6d6bcf07c2047aca2bbb579c42283f2572b2c9fde9fada0f402ef67e2df0ace0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easyorm_py-1.0.9-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 415.6 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.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 47b6ad7f7e75d5d15ec6c8524ad66afdbc64af928a04e1b4fde3dd7a48fb61cb
MD5 7ee287432126369fea242c71dbd209c5
BLAKE2b-256 40b1e7fce9a85c8b4cb2de75a25088a0ba478a1a48d7d0ced4aaedd5710e658d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.9-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3d100848266230ed2a6adf11eb31f8804d700ed16abc68d1b865839c9be777e5
MD5 a368c2e47d4f46357b614bb39e64ae64
BLAKE2b-256 bba785dab43193b2c66f39770a66b083e1483878f4b0cdb48fc7e116dfc15065

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easyorm_py-1.0.9-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.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 aa0173544d2f656e03129d22f60b14133e4e7b08e2712cfbdfac409be1c2ee3c
MD5 75b3197409122b2869803044be7a9797
BLAKE2b-256 56bd4a3d9373d5c38e813965048eebd9bde95fddc219d1035992af22888ed8d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.9-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5580a0bbe256ccbbd81858e085350649ec102045752b6801ef57945828b809b7
MD5 18ffa428622ae4544d6732a05c58a991
BLAKE2b-256 9c643841a9bcab66684e1de2bc875ac8a8b9e0c7bd1a819158c1e29b70a13b7e

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