3 ms·
In the readme you say: >This contrasts against traditional ("stateful") ORMs which use query builders (rather than raw SQL) to return database-aware (rather th
by cabalamat 5y ago
In the readme you say:
>This contrasts against traditional ("stateful") ORMs which use query builders (rather than raw SQL) to return database-aware (rather than pure) objects.
>The name pureORM reflects both that it is pure ORM (there is no query builder dimension) as well as the purity of the mapped Objects.
I don't know what you mean by "pure" or "purity" here, and i think an explantion would help.
Also, in the code:
db.one(query)
"one" does not strike me as a particularly expressive method name.
- athenot 5y agoI'm not familiar with it, but at first glance, "one()" stands in contrast to "multiple()". Either running a single query or running multiple queries in a request.
- zachrip 5y agoIt is used for the amount of objects returned (not the amount of raw rows returned, to be clear). Many orms have `findOne` or `findAll` methods that return an object or an array respectively. Just helps to make things more ergonomic and usually appends a LIMIT clause.
- athenot 5y agoThanks for the correction. I guess that validates the OP's point after all.
- cabalamat 5y agoAh, that makes more sense now.
- ptx 5y ago"single" might be a better name. The Kotlin standard library uses that name for a variant of the "filter" method (on collections) that returns a single matching element or throws an exception if there are more or fewer.
- manyxcxi 5y agoI thought it was first or firstOrNull. Or is there a new Kotlin collection method I need to learn about? Aside, Kotlin collection extensions might be my favorite thing I learned in the last two years.
- ptx 5y agoThey are similar but slightly different. "single" checks that there is exactly one matching element: >>> listOf(1, 2, 3).single { it > 2 } res0: kotlin.Int = 3 >>> listOf(1, 2, 3).single { it > 1 } java.lang.IllegalArgumentException: Collection contains more than one matching element. >>> listOf(1, 2, 3).single { it > 100 } java.util.NoSuchElementException: Collection contains no element matching the predicate. Whereas "firstOrNull" returns the first result even if there are more, or null if there are none: >>> listOf(1, 2, 3).firstOrNull { it > 2 } res0: kotlin.Int? = 3 >>> listOf(1, 2, 3).firstOrNull { it > 1 } res1: kotlin.Int? = 2 >>> listOf(1, 2, 3).firstOrNull { it > 100 } res2: kotlin.Int? = null Python's "next" function kind of acts like "single", except that it doesn't check that there aren't more than one matching element. I wish the itertools module had a function that did this.