Skip to content

Instantly share code, notes, and snippets.

@laranea
Forked from mumumu/sqlalchemy_snippet.py
Created January 14, 2020 07:27
Show Gist options
  • Save laranea/4858638ca584fe5712a7ea41f9db1ea8 to your computer and use it in GitHub Desktop.
Save laranea/4858638ca584fe5712a7ea41f9db1ea8 to your computer and use it in GitHub Desktop.
sqlalchemy snippet.
#!/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()
@so784035
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment