.andWhere()
I know that
.andWhere()
isn't a function, but I'm wondering if there's a way to start a query in one function, and return it. And then have the receiver be able to continue to add to the where clause?
Something like:
12 Replies
we have
we have both
and
and or
combine operators, if that's what you needI think the key point here is to be able to modify the condition after it was created somewhere else
And add it to the partially built query
Let me think about how to best implement it with what we have
you are correct. the idea is not to add a .andWhere() function, but just to be able to extend a preexisting query
the ORM i use in a programming language called perl, has a search() that you can call over and over again on itself.
It's super handy to be able to do that.
we tend to keep our design as simple as possible and to not implement non-obvious behaviour
I, by just looking at
.search().search()
don't know whether it's going to be first one or second one or both with and
nor it is SQL like
so you literally have to learn a specific behaviour of a particular library, yet we are very keen to stay close to 0 learning curveSo what you can do here is the inversion of control. Instead of customising the query outside of the function, you can make the function accept the customisation pieces that you need.
So here you're accepting an optional callback into the
startIt
function which allows the users to customise the .where()
condition. Not very good-looking, I know, but that's what you can do with the current API. We'll probably need to think about how to make it easier to use, since we initially planned the API primarily for the cases when you specify the whole query in one place.wow whoever @alexblokh is really likes this answer 🙂
i don't like that you're making me think backwards from how i already think, but i absolutely love that you have a solution for this! thank you so much
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
@bloberenober had a reasonable solution, but I ended up finding that it was ultimately too complicated for me. So instead of passing a complete query around, I would just pass around the where clause.
and that would allow me to then
and(existingWhereClause, eq(someColumn, someValue))
as needed
Or if you don't like that solution, another solution I came up with in another situation was to pass around an object like :
admittedly it would be easier if there was an .andWhere()
option, but there are work aroundsUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
@atintel we're not going to add
.andWhere
and we've spent so much time designing our current API so you can build those helpers in the matter of minutes/hrs, we truly believe this to be the proper approachUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
im having a hard time migrating from typeorm without an andWhere
does anybody have an utils lib for this?
this works for me for now,
even if there is only a single value in and operator, it still works
in the three scenarios, the sql are gentting generated accordingly. Not sure if this would break tho
ohh im missing the fourth scenario btw