Git Product home page Git Product logo

spmpool's Introduction

Python3的MySQL数据连接池spmpool

Python优点很多,适合快速开发,常用数据结构都有,且提供了很方便的api。我比较倾向于用新版的Python3,而它在操作MySQL数据库时,会用到PyMySQL驱动,我就针对这个驱动,为Python3编写了一个小巧的数据库连接池spmpool,使用非常方便。

python3依赖包:pymysql

使用之前记得把 spmpool.py 放到lib目录中

使用方法

import spmpool 

# 添加连接池配置
spmpool.add_config('local', 'root', '123456', 'testdb', init_pool_size=20)
spmpool.add_config('remote', 'ujued', '123456', 'db', init_pool_size=120)

# 获取连接池  
local_pool = spmpool.spmpool('local')
remote_pool = spmpool.spmpool('remote')

# 获取连接并使用
conn = local_pool.get()
result = conn.execute('select id, name, password from user')
rows = result.fetchall()
for row in rows:
    print(row.id, row.password, row.name)
conn.close()

spmpool's People

Contributors

ujued avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.