Created
May 31, 2019 20:17
-
-
Save jdevera/348f012a1cb51be0b2f384aa41aaeef3 to your computer and use it in GitHub Desktop.
SqlAchemy spurious select
This file contains hidden or 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 uuid | |
from sqlalchemy import Column, String, create_engine, CHAR | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import sessionmaker | |
engine = create_engine('sqlite:///:memory:', echo=True) | |
Base = declarative_base() | |
class User(Base): | |
__tablename__ = 'users' | |
id = Column(CHAR(16), primary_key=True, default=lambda: uuid.uuid4().bytes) | |
name = Column(String) | |
Base.metadata.create_all(engine) | |
Session = sessionmaker(bind=engine) | |
session = Session() | |
user = User(name='john') | |
session.add(user) | |
session.commit() | |
print(user.id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment