Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. from sqlalchemy.ext.declarative import declarative_base
  2. from sqlalchemy import create_engine
  3. from sqlalchemy import Column, String, LargeBinary, Integer
  4. from sqlalchemy.orm import sessionmaker
  5.  
  6. Base = declarative_base()
  7. engine = create_engine('sqlite:///:memory:')
  8.  
  9. class File(Base):
  10. __tablename__ = 'files'
  11. id = Column(Integer, primary_key=True)
  12. name = Column(String)
  13. data = Column(LargeBinary)
  14.  
  15. Base.metadata.create_all(engine)
  16. Session = sessionmaker(bind=engine)
  17.  
  18. filename = r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
  19. print("Reading file {}.".format(filename))
  20. with open(filename, "rb") as file:
  21. data = file.read()
  22. print("About to commit {} KB of data.".format(len(data)/1000))
  23.  
  24. session = Session()
  25. x = File(id=0, name=filename, data=data)
  26. session.add(x)
  27. session.commit()
  28. print("Data committed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement