I wrote a PyPI module that extends the parameter style in Python's sqlite3 module

sqlite3 accepts qmark and named as parameter binding formats, but does not accept the formats and pyformat formats defined in PEP249 [^ 1] [^ 2] [^ 3]. This is a module that accepts them.

Python versions have been tested with 2.7.8 and 3.4.1.

: cake: How to use

pip install sqlite3paramstyle

It binds to the part of % s.

conn = sqlite3paramstyle.connect(":memory:")
cur = conn.cursor()
cur.execute("select %s, %s", ("foo", "bar"))
cur.fetchall()  # [("foo", "bar")]

It also supports the Python extended format.

cur.execute("select %(who)s, %(age)s", {"who": "John", "age": 20})
cur.fetchall()  # [("John", 20)]$

I hope it helps someone somewhere: beers:

: frog: Created background

I was supposed to maintain Python code with almost no test code and added tests quietly, but I found Python code that uses psycopg2 live. I definitely wanted to use SQLAlchemy, but since it was a difficult phase to change the dependent modules, I decided to proceed in the direction of not changing as much as possible. I didn't want to keep the Postgresql process running on the CI server all the time, and the DB connection was in a form that could be passed from the outside, so when testing, I tried to pass the connection of sqlite3 and execute it. However, the parameter styles that psycopg2 accepts are the format and pyformat formats described above, which are completely incompatible with sqlite3. I found qmarkpg that extends psycopg2 to accept qmark styles, so why not write a module that works the other way around? As soon as I thought.

Happy to be a PyPI author: smiley_cat: Wow Wow

Referenced site

How to register with PyPI

How to use tox

Recommended Posts

I wrote a PyPI module that extends the parameter style in Python's sqlite3 module
I wrote a script that splits the image in two
A memo that I wrote a quicksort in Python
I wrote the queue in Python
I wrote the stack in Python
I made a program that solves the spot the difference in seconds
A story that didn't work when I tried to log in with the Python requests module
I wrote a corpus reader that reads the results of MeCab analysis
I wrote the selection sort in C
I wrote the sliding wing in creation.
I registered PyQCheck, a library that can perform QuickCheck with Python, in PyPI.
Note that I understand the least squares algorithm. And I wrote it in Python.
I want to see a list of WebDAV files in the Requests module
I wrote a script to revive the gulp watch that will die soon
I wrote a class in Python3 and Java
I wrote a design pattern in kotlin Prototype
I wrote the hexagonal architecture in go language
I tried adding a Python3 module in C
I wrote a Japanese parser in Japanese using pyparsing.
A story that was convenient when I tried using the python ip address module
I wrote a design pattern in kotlin Factory edition
I wrote a design pattern in kotlin Builder edition
I wrote a design pattern in kotlin Adapter edition
I wrote a design pattern in kotlin, Iterator edition
A memo that I touched the Datastore with python
[Note] I can't call the installed module in jupyter
I wrote a design pattern in kotlin Template edition
I wrote a Python script that exports all my posts using the Qiita API v2
I wrote a code that exceeds 100% recovery rate in horse racing prediction using LightGBM (Part 2)
I wrote a miscellaneous Ansible module that enables Virtualenv to be used by installing Pythonz.
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
A memorandum to register the library written in Hy in PyPI
I tried the super-resolution algorithm "PULSE" in a Windows environment
Mezzanine introduction memo that I got stuck in the flow
I wrote the basic operation of Seaborn in Jupyter Lab
A word that I was interested in as a programming beginner
I tried "a program that removes duplicate statements in Python"
I wrote it in Go to understand the SOLID principle
I wrote a script to get a popular site in Japan
Is there a bias in the numbers that appear in the Fibonacci numbers?
I wrote a script to combine the divided ts files
I wrote the basic operation of Numpy in Jupyter Lab.
A memorandum that you will often use in Python's Selenium
Note that I was addicted to accessing the DB with Python's mysql.connector using a web application.
I tried to make a serial communication single function module that controls the servo motor on the Petit Robo board in C language