AnyhowStep / tsql

A SQL query-builder/ORM
37 stars 3 forks source link

Reconsider double.mul() and double.sub() implementations #256

Open AnyhowStep opened 4 years ago

AnyhowStep commented 4 years ago

Right now, double.mul() and double.sub() have number|null for the return type.

This only happens because of SQLite.

You can't even use Infinity in other databases; so, we don't get these problems.

It would be nice if we made mul()/sub() just return number.

In SQLite, this would be emulated with COALESCE(x * y, (SELECT SUM(9223372036854775807) FROM (SELECT NULL UNION ALL SELECT NULL)))

Or, throwIfNull(x * y)

AnyhowStep commented 4 years ago

Then, if we want multiplication-but-allow-null-return-type-for-nan, we can have a separate function double.mulWithNan() or some other such nonsense

AnyhowStep commented 4 years ago

Or maybe just not have mulWithNan for the unified library at all

AnyhowStep commented 4 years ago

It all boils down to what this library is really intended to do.

The number 1 concern is to have consistent behavior across all supported databases, as long as the unified library is used to build the queries and expressions.

Given databases A and B, we have the following scenarios,