Skip to content

Instantly share code, notes, and snippets.

View eshirazi's full-sized avatar

Eran Shirazi eshirazi

View GitHub Profile
@eshirazi
eshirazi / pytds_sock5_with_sql_alchemy.py
Created September 26, 2021 08:38
Using SQLAlchemy to connect to Microsoft Sql Server database using SOCKS 5 proxy with Python-TDS
import socks
import pytds
from sqlalchemy import create_engine
from sqlalchemy.pool import StaticPool
host = ...
port = 1433
user = ...
password = ...
socks_proxy_host = ...
@eshirazi
eshirazi / sqlalchemy_azure_mssql_pyodbc.py
Created April 25, 2019 09:49
SQLAlchemy connect to Azure SQL, using PyODBC
# On mac, run these first:
# - brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
# - brew update
# - brew install msodbcsql17 mssql-tools
#
# Install requirements:
# - pip install pyodbc sqlalchemny
import urllib
from sqlalchemy import create_engine
@eshirazi
eshirazi / sqlalchemy_trace.py
Created August 30, 2016 16:17
Flask SQLAlchemy - print stack trace for every query
import sqlalchemy.event
def show_query_stack_traces():
base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
def catch_queries_callback(connection, cursor, query, *_):
print query
stacktrace = [
(file_path, val1, val2, line_contents)
for (file_path, val1, val2, line_contents) in traceback.extract_stack()