Closed NiranjanShah closed 6 years ago
Thanks! The original intent was as follows: since the category
database table is a collection of rows (every row representing a category), the Category
class should follow this principle and appear as a collection of Category
instances as well. Calling Category[25]
would thus fetch the category with ID 25. In this regard, it would be identical to calling Category.getById(25)
which would just run select * from category where id=:id limit 1
.
However, there are the following disadvantages:
Category[25]
, we want the 25th Category from a list of categories, and not the Category with ID of 25.select * from category
into the memory), and then the 25th item would be returned.[]
operator runs in O(1) and returns the result very quickly. That's definitely not the case when running a select
[]
operator is quite hard since it's hard to ctrl
+click in Intellij IDEA on a single character.[]
operator is not automatically imported in Intellij. Even though it's a bug in Kotlin plugin, it still hinders the usability of vok-orm
I will therefore deprecate both the []
operator and the get
method, and I'll introduce getById()
function which clearly states its intent.
Fixed in vok-orm 0.2
In order to get a table row based on the ID normally the convention is to pass as a parameter and the square brackets are used with arrayList wherein you need to get the value at that index.
i.e Category[25] is confusing as it seems that it will give the 25 the index from the ArrayList, where as actually is the WHERE clause of sql (WHERE id = 25).