Skip to content

Commit 50799b7

Browse files
committed
Expose functions execute_query_and_handle_result and execute_plain_query
1 parent 21f4622 commit 50799b7

File tree

11 files changed

+186
-33
lines changed

11 files changed

+186
-33
lines changed

Manifest.toml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,6 @@ git-tree-sha1 = "9d4f64f79012636741cf01133158a54b24924c32"
8888
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
8989
version = "0.8.4"
9090

91-
[[Documenter]]
92-
deps = ["Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
93-
git-tree-sha1 = "3ebb967819b284dc1e3c0422229b58a40a255649"
94-
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
95-
version = "0.26.3"
96-
9791
[[Downloads]]
9892
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
9993
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
@@ -122,12 +116,6 @@ version = "0.4.2"
122116
deps = ["Random"]
123117
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"
124118

125-
[[IOCapture]]
126-
deps = ["Logging"]
127-
git-tree-sha1 = "377252859f740c217b936cebcd918a44f9b53b59"
128-
uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
129-
version = "0.1.1"
130-
131119
[[Infinity]]
132120
deps = ["Dates", "Random", "Requires"]
133121
git-tree-sha1 = "633bac4f993e1237ad9745ae8df9c8378c6ef27a"
@@ -220,9 +208,9 @@ uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
220208

221209
[[Libiconv_jll]]
222210
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
223-
git-tree-sha1 = "8d22e127ea9a0917bc98ebd3755c8bd31989381e"
211+
git-tree-sha1 = "42b62845d70a619f063a7da093d995ec8e15e778"
224212
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
225-
version = "1.16.1+0"
213+
version = "1.16.1+1"
226214

227215
[[LinearAlgebra]]
228216
deps = ["Libdl"]

Project.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
name = "PostgresORM"
22
uuid = "748b5efa-ed57-4836-b183-a38105a77fdd"
33
authors = ["Vincent Laugier <vincent.laugier@gmail.com>"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[deps]
77
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
88
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
9-
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
109
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
1110
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1211
LibPQ = "194296ae-ab2e-5f79-8cd4-7183a0a5a0d1"
@@ -18,14 +17,13 @@ TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
1817
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1918

2019
[compat]
21-
julia = "1"
22-
Documenter="0.25.0,1"
23-
IterTools = "1.1.0,2"
2420
DataFrames = "0.19.0,1"
21+
IterTools = "1.1.0,2"
2522
JSON = "0.21,1"
2623
LibPQ = "1.1.0,2"
2724
Query = "1.0.0,2"
2825
StringCases = "0.1.0,1"
2926
Tables = "1.0.0,2"
3027
TickTock = "1.0.0,2"
3128
TimeZones = "1.3.0,2"
29+
julia = "1"

docs/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
4+
[compat]
5+
Documenter = "0.27"

docs/make.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Pkg;
2-
Pkg.add("Documenter")
2+
#Pkg.add("Documenter")
33
using Documenter, PostgresORM
44

55
makedocs(
@@ -9,7 +9,8 @@ makedocs(
99
"Getting started" => "getting-started.md",
1010
"Modules" => [
1111
"modules/PostgresORM.md",
12-
"modules/PostgresORM.Controller.md"]
12+
# "modules/PostgresORM.Controller.md"
13+
]
1314
],
1415
)
1516
deploydocs(; repo = "github.com/JuliaPostgresORM/PostgresORM.jl.git",

docs/src/getting-started.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
## Pre-requisites
44
### Install LibPQ.jl
5-
`MyProject> add LibPQ`
5+
`(MyProject) pkg> add LibPQ`
66

77
### Install PostgresORM.jl
8-
`MyProject> add https://github.com/JuliaPostgresORM/PostgresORM.jl`
8+
`(MyProject) pkg> add PostgresORM`
99

1010
## Example projects
1111
You can look at the following projects to see how PostgresORM is used :
1212
* [IMDBTestApp.jl](https://github.com/JuliaPostgresORM/IMDBTestApp.jl)
1313

14+
1415
## Concepts
1516

1617
### Classes
@@ -143,6 +144,60 @@ Julia enums are the counterpart of PostgreSQL custom enumeration types.
143144
Many PostgresORM functions expects a `LibPQ.Connection` as one of the arguments.
144145
The developer is in charge of managing the connections and the transactions.
145146

147+
## Design choices
148+
149+
### Retrieval of _complex properties_
150+
Methods `retrieve_entity` and `retrieve_one_entity` expects the argument
151+
`retrieve_complex_props` to tell them if they need to make additional queries
152+
to retrieve the properties of the _complex properties_.
153+
If `retrieve_complex_props == false` then the properties of a _complex_property_
154+
will be set to missing except the properties used as IDs.
155+
156+
### Retrieval of _properties of IEntities_
157+
Reminder, methods `retrieve_entity` and `retrieve_one_entity` expects the argument
158+
`retrieve_complex_props` to tell them if they need to make additional queries
159+
to retrieve the properties of the _complex properties_. There is no such thing
160+
for _properties of IEntities_, PostgresORM never loads them (the properties of
161+
will be equal to missing). It is up to the package user to enrich the instance
162+
if he wants to.
163+
164+
### Update of a _properties of IEntities_
165+
`update_entity` does not update properties of type vector of IEntities.
166+
If the user wants to update a property of type vector of IEntities, he needs to
167+
use `update_vector_property!`.
168+
169+
### Beware! missing has two meanings
170+
A property with value missing can mean that:
171+
* the value is missing for this entity
172+
* the value has not been loaded yet
173+
174+
We could have make use of `Nothing` for the second case but we decided not to
175+
because the benefit was too small compare to the complexity it was adding.
176+
Nevertheless, the developer must be well aware of this when updating an instance.
177+
Here are two code snippets to show what is the risk:
178+
179+
```
180+
# Load the film with retrieve_complex_props set to true
181+
film = retrieve_one_entity(Film(codeName = "cube"),
182+
true, # retrieve the complex props
183+
dbconn)
184+
@test ismissing(film.director.id) # false
185+
@test ismissing(film.director.birthDate) # false
186+
update_entity(film.director, dbconn) # This is OK
187+
188+
189+
# Load the film with retrieve_complex_props set to false
190+
film = retrieve_one_entity(Film(codeName = "cube"),
191+
false, # do not retrieve the complex props
192+
dbconn)
193+
@test ismissing(film.director.id) # false
194+
@test ismissing(film.director.birthDate) # true
195+
update_entity(film.director, dbconn) # This is NOT OK! the director will loose
196+
# its birthDate
197+
198+
199+
```
200+
146201
## Reverse engineer the database
147202
The easiest way to get started is to ask PostgresORM to generate the _classes_,
148203
the ORM modules and the enums. Once done, you can copy the files in the _src_

docs/src/index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ This resource aims to teach you everything you need to know to get up and runnin
99
```@contents
1010
Depth = 2
1111
Pages = ["getting-started.md",
12-
"modules/PostgresORM.md",
13-
"modules/PostgresORM.Controller.md",
14-
"modules/PostgresORM.PostgresORMUtil.md",
12+
"modules/PostgresORM.md",
1513
]
1614
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Module PostgresORM.Controller
2+
3+
TODO
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Module PostgresORMUtil
2+
3+
TODO

docs/src/modules/PostgresORM.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Module PostgresORM
22

33
```@docs
4-
PostgresORM.retrieve_one_entity
4+
PostgresORM.create_entity!
5+
PostgresORM.create_in_bulk_using_copy
56
PostgresORM.retrieve_entity
7+
PostgresORM.retrieve_one_entity
8+
PostgresORM.update_entity!
9+
PostgresORM.update_vector_property!
10+
PostgresORM.delete_entity
11+
PostgresORM.delete_entity_alike
612
```

src/PostgresORM.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module PostgresORM
22

33
export greet, get_orm, create_entity!, create_in_bulk_using_copy,
4-
delete_entity, delete_entity_alike,
5-
retrieve_entity,
6-
update_entity!, update_vector_property!
4+
delete_entity, delete_entity_alike, retrieve_entity, update_entity!,
5+
update_vector_property!, execute_plain_query
76

87
export IEntity, IAppUser, Modification
98

0 commit comments

Comments
 (0)