-
-
Save laranea/4858638ca584fe5712a7ea41f9db1ea8 to your computer and use it in GitHub Desktop.
sqlalchemy snippet.
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
#!/usr/bin/env python | |
from sqlalchemy import create_engine | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column, Integer, String | |
from sqlalchemy.orm import sessionmaker | |
engine = create_engine('sqlite:///:memory:', echo=True) | |
Session = sessionmaker(bind=engine) | |
Base = declarative_base() | |
class User(Base): | |
__tablename__ = 'users' | |
id = Column(Integer, primary_key=True) | |
name = Column(String) | |
fullname = Column(String) | |
password = Column(String) | |
def __repr__(self): | |
return "<User(name='%s', fullname='%s', password='%s')>" % (self.name, self.fullname, self.password) | |
Base.metadata.create_all(engine) | |
ed_user = User(name='ed', fullname='Ed Jones', password='edspassword') | |
session = Session() | |
session.add(ed_user) | |
session.commit() | |
ed_user.name = 'hoge' | |
session.add(ed_user) | |
session.commit() | |
session.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Skip to content
Reset your password
Check your email for a link to reset your password. If it doesn’t appear within a few minutes, check your spam folder.
Return to sign in
TermsPrivacySecurityContact GitHub