diff --git a/README.md b/README.md index 7647e72..cf7a67a 100644 --- a/README.md +++ b/README.md @@ -112,13 +112,25 @@ engine = create_engine( Base.metadata.create_all(engine) with Session(engine) as session, open("./example.txt", "rb") as local_file: + # from an opened local file session.add(Attachment(name="attachment1", content=local_file)) + + # from bytes session.add(Attachment(name="attachment2", content=b"Hello world")) + + # from string session.add(Attachment(name="attachment3", content="Hello world")) + + # from a File object with custom filename and content_type file = File(content="Hello World", filename="hello.txt", content_type="text/plain") session.add(Attachment(name="attachment4", content=file)) + + # from a File object specifying a content path + session.add(Attachment(name="attachment5", content=File(content_path="./example.txt"))) + session.commit() + ``` ## Related projects and inspirations diff --git a/docs/changelog.md b/docs/changelog.md index 08614fe..3418b79 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.6.0] - 2023-10-07 + +--- + +### Added + +* Add option to upload files by path in [#87](https://github.com/jowilf/sqlalchemy-file/pull/87) + by [@adscib](https://github.com/adscib) + ## [0.5.0] - 2023-07-21 --- diff --git a/docs/index.md b/docs/index.md index 6d4d351..20207f4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -111,11 +111,22 @@ engine = create_engine( Base.metadata.create_all(engine) with Session(engine) as session, open("./example.txt", "rb") as local_file: + # from an opened local file session.add(Attachment(name="attachment1", content=local_file)) + + # from bytes session.add(Attachment(name="attachment2", content=b"Hello world")) + + # from string session.add(Attachment(name="attachment3", content="Hello world")) + + # from a File object with custom filename and content_type file = File(content="Hello World", filename="hello.txt", content_type="text/plain") session.add(Attachment(name="attachment4", content=file)) + + # from a File object specifying a content path + session.add(Attachment(name="attachment5", content=File(content_path="./example.txt"))) + session.commit() ``` diff --git a/docs_src/example.py b/docs_src/example.py index 766f375..29a80de 100644 --- a/docs_src/example.py +++ b/docs_src/example.py @@ -31,9 +31,22 @@ class Attachment(Base): Base.metadata.create_all(engine) with Session(engine) as session, open("./example.txt", "rb") as local_file: + # from an opened local file session.add(Attachment(name="attachment1", content=local_file)) + + # from bytes session.add(Attachment(name="attachment2", content=b"Hello world")) + + # from string session.add(Attachment(name="attachment3", content="Hello world")) + + # from a File object with custom filename and content_type file = File(content="Hello World", filename="hello.txt", content_type="text/plain") session.add(Attachment(name="attachment4", content=file)) + + # from a File object specifying a content path + session.add( + Attachment(name="attachment5", content=File(content_path="./example.txt")) + ) + session.commit() diff --git a/sqlalchemy_file/__init__.py b/sqlalchemy_file/__init__.py index a9e655b..929a321 100644 --- a/sqlalchemy_file/__init__.py +++ b/sqlalchemy_file/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.5.0" +__version__ = "0.6.0" from .file import File as File # noqa from .types import FileField as FileField # noqa