I start to understand what ORM is and what it is eaten with. If I understood correctly, his main idea is to save the developer from working directly with SQL. To do this, the entities of the database are declared in the language, say, in the form of classes. And we are working with these entities. And the framework itself is already jerking the corresponding SQL queries.
Those. in Java terms, there is some interface controller
interface DBController { public List<T> select(...); public void insert(AEntity); public void update(AEntity); public void delete(AEntity); } into which our entity is transferred for processing. select - selects some records to put them in the list insert , update , delete perform manipulations with entities according to certain rules.
If so far everything is correct, then the question is how should such a task be solved.
There is a file table of this structure
CREATE TABLE files ( id INTEGER PRIMARY KEY, name VARCHAR, data BLOB, last_download TIMESTAMP )you need to display a list of files when you click on the file to download it, and then update the date of the last download
Describing the essence
class file { public int id, public String name, public byte[] data, public Date last_download } And I immediately see problems
- When filling out the list for output to the page, I have blobs from the database that take up a lot of space and are not needed to display the list
After downloading, I need to update one field and not touch the rest. Those. instead of default request
UPDATE files SET name = :name, data = :data, last_download = :last_download WHERE id = :idI need to do this
UPDATE files SET last_download = :last_download WHERE id = :id
Is this all elementary solved? Or I need to describe three entities.
class fileInfo { public int id, public String name, public Date last_download } class fileDownload { public int id, public byte[] data } class fileUpdate { public int id, public Date last_download } If fundamentally, then let realm be as ORM
table->select(['id' ,' name']). and when updating ORM, it should keep track of which fields have been updated, and only write them to the update request. so the entity should be, of course, one - teranis_modifiedshould be attached to each field? - Anton Shchyrov