File tree Expand file tree Collapse file tree 5 files changed +46
-1
lines changed Expand file tree Collapse file tree 5 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -112,13 +112,25 @@ engine = create_engine(
112112Base.metadata.create_all(engine)
113113
114114with Session(engine) as session, open (" ./example.txt" , " rb" ) as local_file:
115+ # from an opened local file
115116 session.add(Attachment(name = " attachment1" , content = local_file))
117+
118+ # from bytes
116119 session.add(Attachment(name = " attachment2" , content = b " Hello world" ))
120+
121+ # from string
117122 session.add(Attachment(name = " attachment3" , content = " Hello world" ))
123+
124+ # from a File object with custom filename and content_type
118125 file = File(content = " Hello World" , filename = " hello.txt" , content_type = " text/plain" )
119126 session.add(Attachment(name = " attachment4" , content = file ))
127+
128+ # from a File object specifying a content path
129+ session.add(Attachment(name = " attachment5" , content = File(content_path = " ./example.txt" )))
130+
120131 session.commit()
121132
133+
122134```
123135
124136## Related projects and inspirations
Original file line number Diff line number Diff line change @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
55and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
66
7+ ## [ 0.6.0] - 2023-10-07
8+
9+ ---
10+
11+ ### Added
12+
13+ * Add option to upload files by path in [ #87 ] ( https://github.com/jowilf/sqlalchemy-file/pull/87 )
14+ by [ @adscib ] ( https://github.com/adscib )
15+
716## [ 0.5.0] - 2023-07-21
817
918---
Original file line number Diff line number Diff line change @@ -111,11 +111,22 @@ engine = create_engine(
111111Base.metadata.create_all(engine)
112112
113113with Session(engine) as session, open (" ./example.txt" , " rb" ) as local_file:
114+ # from an opened local file
114115 session.add(Attachment(name = " attachment1" , content = local_file))
116+
117+ # from bytes
115118 session.add(Attachment(name = " attachment2" , content = b " Hello world" ))
119+
120+ # from string
116121 session.add(Attachment(name = " attachment3" , content = " Hello world" ))
122+
123+ # from a File object with custom filename and content_type
117124 file = File(content = " Hello World" , filename = " hello.txt" , content_type = " text/plain" )
118125 session.add(Attachment(name = " attachment4" , content = file ))
126+
127+ # from a File object specifying a content path
128+ session.add(Attachment(name = " attachment5" , content = File(content_path = " ./example.txt" )))
129+
119130 session.commit()
120131
121132```
Original file line number Diff line number Diff line change @@ -31,9 +31,22 @@ class Attachment(Base):
3131Base .metadata .create_all (engine )
3232
3333with Session (engine ) as session , open ("./example.txt" , "rb" ) as local_file :
34+ # from an opened local file
3435 session .add (Attachment (name = "attachment1" , content = local_file ))
36+
37+ # from bytes
3538 session .add (Attachment (name = "attachment2" , content = b"Hello world" ))
39+
40+ # from string
3641 session .add (Attachment (name = "attachment3" , content = "Hello world" ))
42+
43+ # from a File object with custom filename and content_type
3744 file = File (content = "Hello World" , filename = "hello.txt" , content_type = "text/plain" )
3845 session .add (Attachment (name = "attachment4" , content = file ))
46+
47+ # from a File object specifying a content path
48+ session .add (
49+ Attachment (name = "attachment5" , content = File (content_path = "./example.txt" ))
50+ )
51+
3952 session .commit ()
Original file line number Diff line number Diff line change 1- __version__ = "0.5 .0"
1+ __version__ = "0.6 .0"
22
33from .file import File as File # noqa
44from .types import FileField as FileField # noqa
You can’t perform that action at this time.
0 commit comments