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",
    }
}

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
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): ...
    
if __name__ == '__main__':
    test = TestMapper()
    test.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.4-cp313-cp313-win_amd64.whl (388.0 kB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13

easyorm_py-1.0.4-cp312-cp312-win_amd64.whl (394.8 kB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12

easyorm_py-1.0.4-cp311-cp311-win_amd64.whl (403.3 kB view details)

Uploaded CPython 3.11Windows x86-64

easyorm_py-1.0.4-cp311-cp311-manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.11

File details

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

File metadata

  • Download URL: easyorm_py-1.0.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 388.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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 eb7f97d31f7bf02b1a10dae618db26c1fd696416c5881ae22cc1766a91683954
MD5 7cd00efba4136fb108fcf93cc824204d
BLAKE2b-256 5de48c8c3e2a2f4a12d2af9c08c1af178b308320d0a61c7f9c2eb7517be393c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.4-cp313-cp313-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9d3c4c1e74e52dd5d7596f6e6d96965b4990f053b1c712d5af7db18a5f8fe544
MD5 e6232925902d95b842ed2f683dd9b8fd
BLAKE2b-256 1a9817c787f77949ddffefc0ba02d135501cbe6b91c26ea9dd763f488afb1cd4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easyorm_py-1.0.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 394.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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ce05b65ab98e83a96bf8fefca5245ee7562a2b84db1a6ffa9405cf215d848a83
MD5 096b5a5dc8bcebdba9905c7e656412e9
BLAKE2b-256 185c99ea103e9b2ea4262839e9347924e54d6c6246f74f2a61828a1127464e0c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.4-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09451a6a9ba0cc0774cb593d1b28d38de7459197691c399a3d31afbb85a5837a
MD5 b266455f850c93bf060e1c3df5f9d9e5
BLAKE2b-256 1e2ee067d88a1eae01845457eb2ef0735c6b07a932c74ac515fa0bc0ef04c2c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easyorm_py-1.0.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 403.3 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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7823e0919baffadac2b9dcf13da2e17eb42d789d946474e8cac4d29e4cf58602
MD5 5ea9a479e5c101cd1d201021ac585920
BLAKE2b-256 38724575a203c75fd7770587400f6dfe3b4e3380b829c8259886ce857e594357

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for easyorm_py-1.0.4-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aee766035f9720d28efd863e667e0ff5fa639760822865c52cc0e15d065fe31f
MD5 6fbdeceab0d5c235864ca9c2236a8863
BLAKE2b-256 dfdd02697b0530d416771a38104c92bb206127fa25f6643d8e2cc5ee2b378d3d

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