
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
mysql-statement-builder
Advanced tools
...
pip install mysql-statement-builder
import mysql.connector
from mysql.connector import pooling
from contextlib import contextmanager
from mysqlsb import MySQLStatementBuilder, FetchType
# Setup a connection pool using the MySQL python connector
connection_pool = mysql.connector.pooling.MySQLConnectionPool(
user='user',
password='password',
host='host',
database='database',
port='port',
autocommit=False,
)
# Setup a method for recieving a connection from the connection pool
@contextmanager
def get_connection() -> pooling.PooledMySQLConnection:
"""
Returns a MySQL connection that can be used for read/write.
"""
connection = connection_pool.get_connection()
try:
yield connection
finally:
connection.close()
# Apply mysql-statement-builder to select data from the database
def get_user_from_database(user_id: int):
with get_connection() as connection:
mysql_statement = MySQLStatementBuilder(connection)
user_data = mysql_statement \
.select('users', ['id', 'username', 'email']) \
.where('id = %s', [user_id]) \
.execute(fetch_type=FetchType.FETCH_ONE, dictionary=True)
if user_data is None:
raise UserNotFoundException('User could not be found in database')
user = User(**user_data) # Unpack results dictionary into e.g. a Pydantic basemodel class
return user
FAQs
Simplifies writing MySQL statements in non-ORM environments.
We found that mysql-statement-builder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.