diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e8de77f..580961d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Publish on Pypi +name: Publish on: release: types: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 493e4d9..a35b232 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Python package +name: Test suite on: push: @@ -93,5 +93,3 @@ jobs: run: poetry run bash scripts/coverage.sh - name: Upload coverage uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} diff --git a/README.md b/README.md index eda507f..ae9a40a 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The key features are: --- -**Documentation**: [https://github.com/jowilf/sqlalchemy-file](https://github.com/jowilf/sqlalchemy-file) +**Documentation**: [https://jowilf.github.io/sqlalchemy-file](https://jowilf.github.io/sqlalchemy-file/) **Source Code**: [https://github.com/jowilf/sqlalchemy-file](https://github.com/jowilf/sqlalchemy-file) diff --git a/docs/index.md b/docs/index.md index e862cfe..c3dded3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,9 +5,18 @@ uploading them to various storage such as Amazon S3, Rackspace CloudFiles, Googl using [Apache Libcloud](https://github.com/apache/libcloud).
@@ -32,7 +41,7 @@ The key features are: --- -**Documentation**: [https://github.com/jowilf/sqlalchemy-file](https://github.com/jowilf/sqlalchemy-file) +**Documentation**: [https://jowilf.github.io/sqlalchemy-file](https://jowilf.github.io/sqlalchemy-file/) **Source Code**: [https://github.com/jowilf/sqlalchemy-file](https://github.com/jowilf/sqlalchemy-file) @@ -72,8 +81,7 @@ from libcloud.storage.drivers.local import LocalStorageDriver from sqlalchemy import Column, Integer, String, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session - -from sqlalchemy_file import FileField, File +from sqlalchemy_file import File, FileField from sqlalchemy_file.storage import StorageManager Base = declarative_base() diff --git a/docs_src/example.py b/docs_src/example.py new file mode 100644 index 0000000..7138275 --- /dev/null +++ b/docs_src/example.py @@ -0,0 +1,39 @@ +import os + +from libcloud.storage.drivers.local import LocalStorageDriver +from sqlalchemy import Column, Integer, String, create_engine +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import Session +from sqlalchemy_file import File, FileField +from sqlalchemy_file.storage import StorageManager + +Base = declarative_base() + + +# Define your model +class Attachment(Base): + __tablename__ = "attachment" + + id = Column(Integer, autoincrement=True, primary_key=True) + name = Column(String(50), unique=True) + content = Column(FileField) + + +# Configure Storage +os.makedirs("/tmp/storage/attachment", 0o777, exist_ok=True) +container = LocalStorageDriver("/tmp/storage").get_container("attachment") +StorageManager.add_storage("default", container) + +# Save your model +engine = create_engine( + "sqlite:///example.db", connect_args={"check_same_thread": False} +) +Base.metadata.create_all(engine) + +with Session(engine) as session: + session.add(Attachment(name="attachment1", content=open("./example.txt", "rb"))) + session.add(Attachment(name="attachment2", content=b"Hello world")) + session.add(Attachment(name="attachment3", content="Hello world")) + file = File(content="Hello World", filename="hello.txt", content_type="text/plain") + session.add(Attachment(name="attachment4", content=file)) + session.commit() diff --git a/mkdocs.yml b/mkdocs.yml index 0cfda1b..31f16e5 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,8 +1,12 @@ site_name: SQLAlchemy File +site_description: SQLAlchemy-file is a SQLAlchemy extension for attaching files to SQLAlchemy model and uploading them to various storage such as Amazon S3, Rackspace CloudFiles, Google Storage and others using Apache Libcloud. +site_url: https://jowilf.github.io/sqlalchemy-file +repo_name: jowilf/sqlalchemy-file +repo_url: https://github.com/jowilf/sqlalchemy-file theme: name: material icon: - repo: fontawesome/solid/file-export + logo: material/file-cloud palette: - media: "(prefers-color-scheme: light)" scheme: default @@ -60,4 +64,14 @@ plugins: show_root_heading: true show_source: false watch: - - sqlalchemy_file \ No newline at end of file + - sqlalchemy_file + + +extra: + social: + - icon: fontawesome/brands/github + link: https://github.com/jowilf + - icon: fontawesome/brands/twitter + link: https://twitter.com/jowilf + - icon: fontawesome/brands/linkedin + link: https://www.linkedin.com/in/jocelin-hounon-2008aa139 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 266ebdc..2caca6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ description = """SQLAlchemy-file is a SQLAlchemy extension for attaching files authors = ["Jocelin Hounon