Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sqlalchemy.ext.declarative import declarative_base
- from sqlalchemy import create_engine
- from sqlalchemy import Column, String, LargeBinary, Integer
- from sqlalchemy.orm import sessionmaker
- Base = declarative_base()
- engine = create_engine('sqlite:///:memory:')
- class File(Base):
- __tablename__ = 'files'
- id = Column(Integer, primary_key=True)
- name = Column(String)
- data = Column(LargeBinary)
- Base.metadata.create_all(engine)
- Session = sessionmaker(bind=engine)
- filename = r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
- print("Reading file {}.".format(filename))
- with open(filename, "rb") as file:
- data = file.read()
- print("About to commit {} KB of data.".format(len(data)/1000))
- session = Session()
- x = File(id=0, name=filename, data=data)
- session.add(x)
- session.commit()
- print("Data committed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement