Skip to content

Instantly share code, notes, and snippets.

@tsauerwein
tsauerwein / sqlalchemy-raw-sql.py
Created October 15, 2016 08:51
SQLAlchemy: Using raw SQL in ORM statements
# ...
participants_and_editor = text(
'ARRAY(SELECT DISTINCT UNNEST(array_cat('
' ARRAY[guidebook.feed_document_changes.user_id], :participants)) '
'ORDER BY 1)')
DBSession.execute(
DocumentChange.__table__.update().
where(DocumentChange.document_id == outing_id).
where(DocumentChange.change_id != existing_change.change_id).
values(user_ids=participants_and_editor),
@tsauerwein
tsauerwein / none-nested-sequence.py
Created October 28, 2016 08:29
Colander and None?
import colander
class NoneSequence(colander.MappingSchema):
foo = colander.SchemaNode(colander.String())
bar = colander.SchemaNode(
colander.Sequence(), colander.SchemaNode(colander.String()),
missing=None)
@tsauerwein
tsauerwein / batch-delete.py
Created December 3, 2018 10:05
Bulk delete a larger number of rows without locking up the table
import subprocess
import re
import time
def delete():
delete_stmt = [
'mysql',
'-h', '...',
'-u', '...',
'--password=...',