Skip to main content

python for mysql operation

Project description

annosSQL

介绍

annosSQL是一个基于python实现对mysql、oracle、sqllite数据库交互库,基础是基于对pymysql等库的封装,其用法有些特别。annosSQL中实现了一种缓存算法(通过LRU算法实现),对于近期相同sql的查询, 会优先从缓存获取,当缓存空间不存在该数据时,再次访问数据库。

安装教程

pip install annosSQL

使用说明

  1. 使用案例
from annosSQL.Innos.Interface import Interface, Handler
from annosSQL.Donos.doconn import Connection
from annosSQL.Donos.dosql import execute

@Interface()
class T4:
    #配置处理器,这是入口,是必须
    @Handler()
    def hand(self) -> list: pass

    #配置连接池
    @Connection(driver="mysql", host="127.0.0.1", user="root", password="123456", port=3306, database="czh")
    def conn(self) -> any: pass

    '''
    查询所有数据,p1方法不能有任何的形参变量,必须是空函数,'->'箭头后面跟的是返回值类型,'list'或'dict'或'tuple'都行
    这里返回list数据类型
    '''
    @execute(sql="select * from user_copy1")
    def p1(self) -> list: pass

    @execute(sql="select * from user_copy1")
    def p2(self) -> dict: pass

    @execute(sql="select * from user_copy1")
    def p3(self) -> tuple: pass

    '''
    占位符使用 {}/#{}/%s,
    条件查询时,函数的形参必须带类型,如s1方法里的id必须写出:id:int
    '''
    # {}占位符是通过str().format()实现的,此时,函数形参的位置十分重要,它将影响sql的条件的正确性
    @execute(sql="select * from user_copy1 where id={}")
    def s1(self,id:int) -> list: pass
    # #{}占位符的基本形式如下:#{1},通过#{}大括号里的数值来定位绑定到函数的形参
    @execute(sql="select * from user_copy1 where id=#{1}")
    def s2(self, id: int) -> dict: pass
    # %s 多行占位符 支持数据多行数据类型:列表与元组
    @execute(sql="select * from user_copy1 where id=%s")
    def s3(self, id: int) -> tuple: pass

    '''
    快捷符的使用:A(select)
    '''
    @execute(sql="A(select) user_copy1")
    def a1(self) -> tuple: pass



if __name__=='__main__':
    t4=T4()
    t4.hand() #调用入口
    print('p1返回的数据:')
    p1=t4.p1()
    print(p1)

    print('p2返回的数据:')
    p2 = t4.p2()
    print(p2)

    print('p3返回的数据:')
    p3 = t4.p3()
    print(p3)

    print('s1返回的数据:')
    s1 = t4.s1(1)
    print(s1)

    print('s2返回的数据:')
    s2 = t4.s2(1)
    print(s2)

    print('s3返回的数据:')
    s3 = t4.s2(1)
    print(s3)

    print('a1返回的数据:')
    a1 = t4.a1()
    print(a1)    
  1. 运行结果
p1返回的数据:
[[1, 'chx', '123455', '1'], [2, 'czh', '123456', '2']]
p2返回的数据:
[{'id': 1, 'user': 'chx', 'password': '123455', 'z': '1'}, {'id': 2, 'user': 'czh', 'password': '123456', 'z': '2'}]
p3返回的数据:
((1, 'chx', '123455', '1'), (2, 'czh', '123456', '2'))
s1返回的数据:
[[1, 'chx', '123455', '1']]
s2返回的数据:
[{'id': 1, 'user': 'chx', 'password': '123455', 'z': '1'}]
s3返回的数据:
[{'id': 1, 'user': 'chx', 'password': '123455', 'z': '1'}]
a1返回的数据:
((1, 'chx', '123455', '1'), (2, 'czh', '123456', '2'))
  1. xxxx

其他说明

#{} %s {} # #{}、 {} 普通占位符 # %s 多行占位符 支持数据多行数据类型:列表与元组 # select * from -> A(select) user # insert into table values(S{,}[]) # insert into table values(C{}) # insert into table values(L{}) # insert into table values(T{%s,%s})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

annosSQL-2.0.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

annosSQL-2.0.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file annosSQL-2.0.0.tar.gz.

File metadata

  • Download URL: annosSQL-2.0.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.10 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.5

File hashes

Hashes for annosSQL-2.0.0.tar.gz
Algorithm Hash digest
SHA256 ac19a52a2e7895e5d635e37b59b847ba649a14d20f6981359acf116e3ddc71d4
MD5 350df895c736d2f438625ff549c640f0
BLAKE2b-256 e4c6ab754729cd2b7cd2f77a84a48e3e75a274214adf6ef0303a4f1f51eb2484

See more details on using hashes here.

File details

Details for the file annosSQL-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: annosSQL-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.10 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.5

File hashes

Hashes for annosSQL-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a36699adeff13e8d17bb0d35364980e83f2c6b7ca3a0dacbf95a058ec07764a
MD5 608d3826b7104c24c06655215ee3ca02
BLAKE2b-256 f6f5d9173729813d4f441e02a5bbb126a8d7bccf12882a8179a087ebd6447fe4

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