-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jowilf/update_docs
Update docs
- Loading branch information
Showing
7 changed files
with
70 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Publish on Pypi | ||
name: Publish | ||
on: | ||
release: | ||
types: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters