This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# taken from https://code.activestate.com/recipes/577504/ **plus** | |
# the comment at https://code.activestate.com/recipes/577504/#c5 | |
from sys import getsizeof, stderr | |
from itertools import chain | |
from collections import deque | |
from reprlib import repr | |
def total_size(o, handlers={}, verbose=False): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import contextlib | |
import cProfile | |
import io | |
import pstats | |
import random | |
from sqlalchemy import cast | |
from sqlalchemy import Column | |
from sqlalchemy import Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import Column, Integer, create_engine | |
from sqlalchemy.ext.declarative import declarative_base | |
Base = declarative_base() | |
# a model | |
class Thing(Base): | |
__tablename__ = 'thing' | |
id = Column(Integer, primary_key=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import * | |
from sqlalchemy.orm import * | |
from sqlalchemy.ext.declarative import declarative_base | |
e = create_engine("sqlite://", echo=True) | |
# first, we're in the old version of the app | |
OldBase = declarative_base() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import Column | |
from sqlalchemy import create_engine | |
from sqlalchemy import inspect | |
from sqlalchemy import Integer | |
from sqlalchemy import MetaData | |
from sqlalchemy import select | |
from sqlalchemy import String | |
from sqlalchemy import Table | |
from sqlalchemy.orm import aliased | |
from sqlalchemy.orm import declarative_base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A plain asyncio program that uses asyncpg to run some rows into a table and | |
select them. | |
This is a "control" program which we will compare to the one which uses calls | |
from an implicit IO greenlet at | |
https://gist.github.com/zzzeek/4e89ce6226826e7a8df13e1b573ad354. | |
Performance against a PG database over a wired network | |
Ran 40000 records in 40 concurrent requests, Total time 5.560306 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import Column | |
from sqlalchemy import create_engine | |
from sqlalchemy import Integer | |
from sqlalchemy import MetaData | |
from sqlalchemy import select | |
from sqlalchemy import String | |
from sqlalchemy import Table | |
from sqlalchemy.orm import aliased | |
from sqlalchemy.orm import declarative_base | |
from sqlalchemy.orm import Session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import greenlet | |
import sqlite3 | |
class _ErrorContainer(object): | |
error = None | |
def _expect_raises_fn(fn): | |
ec = _ErrorContainer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""this is getting close but SQLAlchemy is still not instrumenting __init__ such | |
that it can intercept Pydantic's operations, in particular that list coming | |
in which it wants to convert to instrumented list. | |
this probably could be made to work with some more effort but it will | |
be quite hacky in the end, not really worth it unless there was | |
some explicit support in pydantic. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import contextlib | |
import random | |
import yappi | |
# install sqlalchemy from github master: | |
# pip install git+https://github.com/sqlalchemy/sqlalchemy/ | |
from sqlalchemy import cast | |
from sqlalchemy import Column |