Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

---
Expand Down
11 changes: 11 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()

```
Expand Down
13 changes: 13 additions & 0 deletions docs_src/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion sqlalchemy_file/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down