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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13

easyorm_py-1.0.6-cp312-cp312-win_amd64.whl (395.3 kB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12

easyorm_py-1.0.6-cp311-cp311-win_amd64.whl (403.1 kB view details)

Uploaded CPython 3.11Windows x86-64

easyorm_py-1.0.6-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.6-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: easyorm_py-1.0.6-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 388.6 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.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e31589e2d05a1fb6d36dba47b8e658dfb95e73f3371bb56911ec53c01fb8ceb5
MD5 71f13c913e928de68b4d95b7bf75e0a5
BLAKE2b-256 4ae86af6a04f96cb4065a0bee425dddaf982312de2f908c5b694ffe9deea6c4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.6-cp313-cp313-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2fc0b037568d4ac35759df157b0dbe894b5af9b6081c9daf9dc9e9dd933daf34
MD5 20b8625542b775b982573113177171c9
BLAKE2b-256 c2b18d56527367fb8fc1597e9d74c25e05807b7c5736934d44bcda9cab6b70f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easyorm_py-1.0.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 395.3 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.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4fcf1c6029154972ec8127e0f0a045b322ed55e6036a14b52199409fe1aaaa7c
MD5 c14d7776dac5b236c99f736d04aa64dc
BLAKE2b-256 3a19e1ab0831c97f2e932481b27f4f4a6d9922295e75a11a1a155162b6b06e7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.6-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb2b3c5280db2deab49d41208531f654bd6f05f39a14ac14f292bc22d0e7e544
MD5 eec57d5189c6000c4c938e4cb2e04527
BLAKE2b-256 f29ca56f7fac2d4139e0a87af6da01c25d8932d104f225fc1c88f6c848b10202

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easyorm_py-1.0.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 403.1 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.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fff0ac07f04a5810b2732ccc0759b8e28f26483df6121c1341dae1c61aa93ed2
MD5 1ed8c39ae0e9965f366a4363b8051680
BLAKE2b-256 dd723e3fbaec0d085ec551774d63abb9ab80ebc1716319b1c9e6176524dded99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.6-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2bdcf897777a8b65cc3f86fd268bcfc692f21d3fa1ad3b29ed0e2c42039696c6
MD5 928bcf62626ab10061faba5c0869f518
BLAKE2b-256 829786a364020422ee4199c615aa862d3a50978aa3e1937d52bfd4dfb79eb880

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