|
2 | 2 |
|
3 | 3 | ## Pre-requisites |
4 | 4 | ### Install LibPQ.jl |
5 | | -`MyProject> add LibPQ` |
| 5 | +`(MyProject) pkg> add LibPQ` |
6 | 6 |
|
7 | 7 | ### Install PostgresORM.jl |
8 | | -`MyProject> add https://github.com/JuliaPostgresORM/PostgresORM.jl` |
| 8 | +`(MyProject) pkg> add PostgresORM` |
9 | 9 |
|
10 | 10 | ## Example projects |
11 | 11 | You can look at the following projects to see how PostgresORM is used : |
12 | 12 | * [IMDBTestApp.jl](https://github.com/JuliaPostgresORM/IMDBTestApp.jl) |
13 | 13 |
|
| 14 | + |
14 | 15 | ## Concepts |
15 | 16 |
|
16 | 17 | ### Classes |
@@ -143,6 +144,60 @@ Julia enums are the counterpart of PostgreSQL custom enumeration types. |
143 | 144 | Many PostgresORM functions expects a `LibPQ.Connection` as one of the arguments. |
144 | 145 | The developer is in charge of managing the connections and the transactions. |
145 | 146 |
|
| 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 | + |
146 | 201 | ## Reverse engineer the database |
147 | 202 | The easiest way to get started is to ask PostgresORM to generate the _classes_, |
148 | 203 | the ORM modules and the enums. Once done, you can copy the files in the _src_ |
|
0 commit comments