Created
February 9, 2020 12:13
-
-
Save MagnetonBora/45e585ea2b7047543a9791ed81ad3a8a to your computer and use it in GitHub Desktop.
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.orm import sessionmaker | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column, Integer, String, Sequence, create_engine | |
engine = create_engine('sqlite:///:memory:') | |
Base = declarative_base() | |
class User(Base): | |
__tablename__ = 'users' | |
id = Column(Integer, Sequence('user_id_seq'), primary_key=True) | |
name = Column(String(50)) | |
fullname = Column(String(50)) | |
nickname = Column(String(50)) | |
def __repr__(self): | |
return f"User({self.name}, {self.fullname}, {self.nickname})" | |
Base.metadata.create_all(engine) | |
Session = sessionmaker(bind=engine) | |
session = Session() | |
edward = User(name='ed', fullname='Ed Jones', nickname='big_daddy') | |
session.add(edward) | |
# sesssion.commit() | |
session.query(User).all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment