-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support tuples #611
Support tuples #611
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
e615446
to
14fdc8d
Compare
Wouldn't |
Yeah, but on the other hand, most functions take references by default. I don't know which is the better "default". @igalklebanov Thoughts? |
14fdc8d
to
b782a0d
Compare
@thelinuxlich Did you mean we'd have |
refTuple and tuple |
because val at least there is no precedent in the API, right? |
@koskimas @thelinuxlich |
Actually, when used in where, there's still going to be ref usage in the lhs. This is a tough one, but seems like consistency should rule here. |
I think it should be |
Yeah, for now pretty much the only use case for this is eb(refTuple('first_name', 'last_name'), '=', tuple('Jennifer', 'Aniston')) so I'd say |
b782a0d
to
bfc04b6
Compare
@igalklebanov @thelinuxlich I renamed the functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing stuff! 👨🎨
Left some comments..
* further type speedup and simplification * Add tuple support * rename tuple to refTuple and valTuple to tuple * improve typings
This PR adds tuple support. After trying out a bunch of options, I ended up with a function overload approach up to tuples of length five. There's also a partially unsafe
$asTuple
function inSelectQueryBuilder
that I don't love.The reason for my choices basically boils down to the fact that typescript doesn't allow the index of a type in an union to be observed. They've stated in some issues that it will never be observable.
Because of this, there's no (sane) conversion from an object to a tuple, which is why the
$asTuple
method is necessary. If you google this, there is a solution, but it takes around 3 gigabytes of memory to convert a single object to a tuple, so that's a hard no-no.Using function overloads instead of a recursive type (like the one in coalesce) is also due to performance AND autocompletion issues. The recursive type immediately caused ~one second delays and I wasn't able to get autocompletion to work. Just like we don't currently have autocompletion in
coalesce
after the first argument.Having a maximum length of five for tuples shouldn't be an issue. My guess is that the most common use case for this is composite primary keys and the length for those is usually 2 or 3. We can also add more overloads if someone requests them.
Closes #367