纯python mysql驱动程序

trio_mysql的Python项目详细描述


Documentation Statushttps://travis-ci.org/python-trio/trio-mysql.svg?branch=masterhttps://coveralls.io/repos/python-trio/trio-mysql/badge.svg?branch=master&service=githubhttps://img.shields.io/badge/license-MIT-blue.svg

Trio MySQL

这个包包含一个纯python和trio增强的mysql客户端库。 它是pymysql的一个简单的克隆,添加了异步方法 与三个框架兼容。

注意:trio mysql尝试遵守(异步版本的)高级 在PEP 249中定义的数据库api。然而,有些差异是 不可避免。

Requirements

  • python–以下之一:
  • MySQL服务器–以下之一:

Installation

上一个稳定版本在pypi上可用,可以使用pip

安装
$ pip install trio_mysql

Documentation

在线提供文档:http://trio_mysql.readthedocs.io/

有关支持,请参阅StackOverflow

Example

下面的示例使用一个简单的表

CREATETABLE`users`(`id`int(11)NOTNULLAUTO_INCREMENT,`email`varchar(255)COLLATEutf8_binNOTNULL,`password`varchar(255)COLLATEutf8_binNOTNULL,PRIMARYKEY(`id`))ENGINE=InnoDBDEFAULTCHARSET=utf8COLLATE=utf8_binAUTO_INCREMENT=1;
importtrio_mysql.cursors# Connect to the databaseconnection=trio_mysql.connect(host='localhost',user='user',password='passwd',db='db',charset='utf8mb4',cursorclass=trio_mysql.cursors.DictCursor)asyncwithconnectionasconn:asyncwithconn.cursor()ascursor:# Create a new recordsql="INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"awaitcursor.execute(sql,('webmaster@python.org','very-secret'))# connection is not autocommit by default. So you must commit to save# your changes.conn.commit()# Alternately, you can set up a transaction:asyncwithconn.transaction():asyncwithconn.cursor()ascursor:# Create a new recordsql="INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"awaitcursor.execute(sql,('webmistress@python.org','totally-secret'))asyncwithconn.cursor()ascursor:# Read a single recordsql="SELECT `id`, `password` FROM `users` WHERE `email`=%s"awaitcursor.execute(sql,('webmaster@python.org',))result=awaitcursor.fetchone()print(result)

此示例将打印:

{'password':'very-secret','id':1}

License

trio mysql是在mit许可下发布的。有关详细信息,请参见许可证。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java什么会导致程序在它似乎拥有的监视器上被阻止?   java Android studio设置视图的背景色   java我可以保存一个文本文件而不给用户修改它的能力吗?   pdfbox PDFBOX2。0:java堆堆栈错误   java是维护和操作AllowList的有效方法   JAVAsql。SQLException:找不到适合jdbc的驱动程序:mysql://localhost:3306/asd性爱   如何使用java。lang.NullPointerException:void 安卓。支持v7。应用程序。ActionBar。setElevation(float)“”在空对象引用上'   java调试空指针异常   java正则表达式,以按令牌的特定匹配项拆分,同时忽略其他匹配项   java为JPanel设置边框上的笔划   并发@Schedule方法的java行为   如何在Java中使用泛型与语言运算符和泛型类扩展数   java Rhino Javascript如何为异常堆栈跟踪标记字符串源   运行可执行jar时发生java错误,无法找到或加载主类