sql的简单方法

simqle的Python项目详细描述


simqle

The simple way to SQL

build statuscodecov

非常适合在python项目中使用不繁琐的sql。执行sql并返回simple 带有命名参数的记录集。管理多个连接,并切换 在生产、开发和测试模式之间。

安装

储存库

https://github.com/Harlekuin/SimQLe

或者选择你的毒药:

  • $ pip install simqle
  • $ poetry add simqle
  • $ pipenv install simqle

simqle以yaml格式读取连接文件。见 .connections.yaml文件部分了解更多详细信息。

用法

生产中

从连接的名称、sql语句和dict中获取结果 参数:

fromsimqleimportConnectionManager# Intialise your connectionscm=ConnectionManager(".connections.yaml")# Write some simple SQLsql="SELECT name, age FROM people WHERE category = :category"params={"category":5}result=cm.recordset(con_name="my-database",sql=sql,params=params)

recordset()方法返回(数据、标题)的元组。数据”是行元组的列表。 标题是查询中字段名的列表。

发展中

将simqle_mode环境变量设置为“development”。这将使用 开发连接代替生产连接,而不改变 你的密码。

集成测试中

将simqle_mode环境变量设置为“testing”。

测试此包

测试需要行为包:

> pip install behave

要运行,只需:

> behave

.connections.yaml文件

定义生产、开发和测试服务器的连接字符串。这个 test-connectionsdev-connections的名称应反映 connections名字。每个连接都由其名称引用。

示例文件:

connections:# The name of the connection - this is what will be used in your project# to reference this connection.-name:my-sql-server-databasedriver:mssql+pyodbc:///?odbc_connect=connection:DRIVER={SQL Server};UID=<username>;PWD=<password>;SERVER=<my-server># some odbc connections require urls to be escaped, this is managed by# setting url_escaped = true:url_escape:true# File based databases like sqlite are slightly different - the driver# is very simple.-name:my-sqlite-databasedriver:sqlite:///# put a leading '/' before the connection for an absolute path, or omit# if it's relative to the project pathconnection:databases/my-database.db#  This connection will be used if no name is given if the default # parameter is used:default:truedev-connections:# the names of the dev-connections should mirror the connections above.-name:my-sql-server-databasedriver:mssql+pyodbc:///?odbc_connect=# connecting to a different server hereconnection:DRIVER={SQL Server};UID=<username>;PWD=<password>;SERVER=<my-dev-server>url_escape:true-name:my-sqlite-databasedriver:sqlite:///connection:/tmp/my-dev-database.dbdefault:truetest-connections:-name:my-sql-server-databasedriver:mssql+pyodbc:///?odbc_connect=connection:DRIVER={SQL Server};UID=<username>;PWD=<password>;SERVER=<my-test-server>url_escape:true-name:my-sqlite-databasedriver:sqlite:///connection:/tmp/my-test-database.dbdefault:true

作者

Tom Malkin

贡献者

Zack Botkin

发布历史记录

  • 0.1.0条
    • 添加项目的基本框架
  • 0.1.1条
    • 单元测试
    • 增加了sqlite的集成测试。
    • 100%覆盖
  • 0.2.0条
    • 在connections.yaml文件中添加了url_escape选项
    • 为mysql和postgresql添加集成测试
  • 0.3.0分
    • 项目重构为类
    • 添加了默认参数
  • 0.4.0条
    • 作为连接模式添加的开发

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

推荐PyPI第三方库


热门话题
java RFID不完整输出?   java如何构造一个for循环来查找每个数组的第一个索引的总和   java Eclipse AST解析器正在删除我的规则   安卓如何在java中创建“可重写”配置?   java每次我向应用程序添加图像时,它都会崩溃   Java 8流到文件   EntityNotFoundException的java可能原因   java多线程为什么下面的程序表现得如此怪异?   java footprint soap api+mavenjaxb2plugin   java MongoDB锁定,直到找到结果   java重写Jtable选项卡行为转到下一个可编辑单元格   java关于方法和创建另一个方法   java将人脸与图像分离   java复制Spring批处理作业实例   java TextView不会更改为新设置的文本