faustinoaq changed the topic of #amber to: Welcome to Amber Framework community! | https://amberframework.org | Developer happiness, productivity and bare metal performance | GH: https://github.com/amberframework | Docs: https://docs.amberframework.org | Gitter: https://gitter.im/amberframework/amber | IRC Logger: https://irclog.whitequark.org/amber | Amber::Server.start
<FromGitter> <drujensen> I assigned the PR to the core and contributor teams. I just mentioned it here for others to be aware that lots of breaking changes are coming
_whitelogger has joined #amber
<FromGitter> <OpakAlex> Hello guys, i am looking into granite, And i have one question (maybe so stupid), we have `src/granite/querying.cr` and `src/granite/query/builder.cr`. I think it maybe make sense if we will have all queries inside builder.cr, like first / last / select. Then we will have one abstraction and we can chain methods. What do you think?
<FromGitter> <Blacksmoke16> they aren't the same thing
<FromGitter> <Blacksmoke16> the former are the basic querying stuff, while the latter is for the query builder format
<FromGitter> <Blacksmoke16> i.e. `Model.find 1` versus `Model.where(:id, :eq, 10).select`
<FromGitter> <OpakAlex> but now, we can not have Model.all.where().order?
<FromGitter> <Blacksmoke16> so? how is that different than `Model.where().order`?
<FromGitter> <Blacksmoke16> obs if you dont include a conditional it'll return all the results
<FromGitter> <OpakAlex> yes of course, i just thinking of eager_loading implementation to have it on top of src/granite/querying.cr and src/granite/query/builder.cr
<FromGitter> <OpakAlex> @Blacksmoke16 i mean something like this: https://github.com/amberframework/granite/pull/407 can you check?
<FromGitter> <Blacksmoke16> i set your PR to draft, built in feature versus [DONT MERGE] in the title
<FromGitter> <OpakAlex> added. check it please, because we need to have some container to add features like paginations, includes, etc.
<FromGitter> <Blacksmoke16> sorry, i meant you dont need that in the title, because by virtue of the PR being a draft, it cannot be merged until you/admin marks it as ready
<FromGitter> <OpakAlex> oh. sorry.
<FromGitter> <Blacksmoke16> unfortunately i havent put a lot of thought into this feature before, so I dont really have any suggestions
<FromGitter> <OpakAlex> But what about to have a wrapper for queries? This is my question
<FromGitter> <OpakAlex> This is doest depends on feature
<FromGitter> <Blacksmoke16> im not sure
<FromGitter> <Blacksmoke16> assuming the API remains the same as it does now, could be worth doing. however i dont have any strong opinions either way
<FromGitter> <OpakAlex> yes, this what i am trying to have same, API ;)
<FromGitter> <Blacksmoke16> 👍 nice
<FromGitter> <Blacksmoke16> @OpakAlex not sure i follow https://github.com/amberframework/granite/pull/407#issuecomment-643330649
<FromGitter> <Blacksmoke16> whats the actual error?
<FromGitter> <OpakAlex> i found it. just my knowlage of generic types. i will fix it
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <OpakAlex> Guys, when i do like this: ⏎ ⏎ ``` end``` ⏎ ⏎ it infinity loads..... [https://gitter.im/amberframework/amber?at=5ee3d3ad7c64f31f1158f21b]
<FromGitter> <OpakAlex> ``````
<FromGitter> <OpakAlex> why? we have issues with IN ?
<FromGitter> <OpakAlex> @Blacksmoke16 ?
<FromGitter> <Blacksmoke16> what do the logs show is being executed?
<FromGitter> <OpakAlex> like this
<FromGitter> <OpakAlex> i spent 3h thinking about it's my code..
<FromGitter> <Blacksmoke16> what spec is this?
<FromGitter> <OpakAlex> i created it, but i think any spec with `id: [ids]`
<FromGitter> <OpakAlex> one sec i will go to master and will create an spec
<FromGitter> <Blacksmoke16> should have handled this
<FromGitter> <OpakAlex> it "errors queries string fields" do ⏎ ⏎ ``` found[0].id.should eq review2.id ⏎ found[1].id.should eq review1.id ⏎ end``` [https://gitter.im/amberframework/amber?at=5ee3d47ea85de303940d6125]
<FromGitter> <OpakAlex> so this one same from master
<FromGitter> <OpakAlex> add this spec into master spec/granite/querying/query_builder_spec.cr
<FromGitter> <OpakAlex> and run
<FromGitter> <OpakAlex> looks like master broken
<FromGitter> <Blacksmoke16> :thinking:
<FromGitter> <OpakAlex> wow 4h of my life, i start to be crazy ;)
<FromGitter> <OpakAlex> can you try this example local @Blacksmoke16 ?
<FromGitter> <Blacksmoke16> interesting
<FromGitter> <OpakAlex> maybe it's my setup
<FromGitter> <Blacksmoke16> naw
<FromGitter> <Blacksmoke16> i dont have any ideas on the reason tho
<FromGitter> <OpakAlex> but it's same for you?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <OpakAlex> hahah crazy
<FromGitter> <OpakAlex> create an issue please
<FromGitter> <OpakAlex> because if somebody else can have it, this will be issue.
<FromGitter> <OpakAlex> I start to believe put my mac to rubish bin and never back to programming ;)))
<FromGitter> <OpakAlex> I will check tomorrow (Berlin time) this issue. Because now it's my blocker
<FromGitter> <OpakAlex> can you create issue @Blacksmoke16 ?
<FromGitter> <Blacksmoke16> you can make it
<FromGitter> <OpakAlex> ok
<FromGitter> <Blacksmoke16> 👍 thanks
<FromGitter> <OpakAlex> i will check it at morning. looks interesting
<FromGitter> <Blacksmoke16> sounds good
<FromGitter> <Blacksmoke16> prob more of a compiler bug than a granite bug, but will be good to confirm that
<FromGitter> <OpakAlex> yes. But i think it's our bug
<FromGitter> <OpakAlex> i will check on 0.34
<FromGitter> <Blacksmoke16> oh wait i have an idea
<FromGitter> <OpakAlex> i hope, it's my first week with crystal) sometimes i don't have any ideas why)
<FromGitter> <Blacksmoke16> not sure why this wouldnt have been caught before tho
<FromGitter> <OpakAlex> because 0 specs?)
<FromGitter> <Blacksmoke16> nvm, wasnt what i thought
<FromGitter> <OpakAlex> yes, we didn't have specs for id: []
<FromGitter> <Blacksmoke16> sure we did
<FromGitter> <OpakAlex> i have it for my branch because of includes, i reused where...
<FromGitter> <Blacksmoke16> just not getting the ids from another obj
<FromGitter> <OpakAlex> hm
<FromGitter> <OpakAlex> maybe
<FromGitter> <Blacksmoke16> all these
<FromGitter> <OpakAlex> but not id man
<FromGitter> <Blacksmoke16> true true
<FromGitter> <OpakAlex> we need to add spec with id: []
<FromGitter> <OpakAlex> @Blacksmoke16 https://github.com/amberframework/granite/pull/409
<FromGitter> <OpakAlex> i really have no idea why this works, I am coming from Erlang, for me this strange, can you check @Blacksmoke16 ?
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <OpakAlex> 100% hm
<FromGitter> <OpakAlex> because we will have same error with `or`
<FromGitter> <OpakAlex> but here i realy need somebody with good Crystal
<FromGitter> <Blacksmoke16> instead of this, try doing
<FromGitter> <Blacksmoke16> ```def and(matches) ⏎ self.where matches ⏎ end``` [https://gitter.im/amberframework/amber?at=5ee3e6ad5782a31278f6f59f]
<FromGitter> <Blacksmoke16> and drop the extra `where` overload
<FromGitter> <OpakAlex> hm
<FromGitter> <OpakAlex> nope
<FromGitter> <OpakAlex> with self.where
<FromGitter> <OpakAlex> same loop
<FromGitter> <OpakAlex> wait
<FromGitter> <OpakAlex> nope
<FromGitter> <OpakAlex> doest work
<FromGitter> <OpakAlex> same issue
<FromGitter> <OpakAlex> i think self in my case handle some compile issue
<FromGitter> <OpakAlex> @Blacksmoke16
<FromGitter> <Blacksmoke16> adding a overload of `where` for `Array(String | Int32 | Int64)` is deff not ideal
<FromGitter> <Blacksmoke16> @robacarp originally wrote all this, see if he remembers anything about it 😆
<FromGitter> <OpakAlex> of course, it's just a point for thinking
<FromGitter> <OpakAlex> i don't want to merge this PR ;) @robacarp any ideas?
* FromGitter * Blacksmoke16 doesnt get why it only happens for id
<FromGitter> <Blacksmoke16> can you start reducing the example, like what happens if you just do `id: [1, 2]` and not create those other two records
<FromGitter> <OpakAlex> yes man. but tomorrow it's 22:40 for me, i want finish my beer and sleep ;)
<robacarp> whaaaaaat now
<FromGitter> <OpakAlex> pushed example with random ids @Blacksmoke16
<FromGitter> <OpakAlex> works ;)
<FromGitter> <OpakAlex> @robacarp can you check https://github.com/amberframework/granite/pull/409 and explain why this works?)
<FromGitter> <Blacksmoke16> interesting
<FromGitter> <OpakAlex> i don't known how Crystal pattern matching methods
<FromGitter> <OpakAlex> but i think answer here
<robacarp> the title says infinite loop, but I don't see what I'd expect to see in the stack trace which shows an infinite loop
<FromGitter> <Blacksmoke16> oh yea, if you look at the bottom of the trace, says something about specs
<FromGitter> <OpakAlex> @robacarp it kills via crystal
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5ee3e9f52cf2f36eae56fc7b]
<FromGitter> <Blacksmoke16> id be curious to see if that example works outside of spec context
<FromGitter> <OpakAlex> have no idea what this means, i just see a lot of logs)
<robacarp> @opakalex you mean crystal dumps some sort of stack overflow error or something?
<FromGitter> <OpakAlex> yep
<robacarp> can you add that to the issue?
<FromGitter> <OpakAlex> i added last output of console
<robacarp> ty
<robacarp> I think this is probably fine, but at first glance I think the right way to fix it is to alter Granite::Columns::Type
<robacarp> is this even supposed to handle an array?
<robacarp> no wait
<robacarp> you don't want to do this value.join business
<robacarp> the reason it iterates the array and does an and for each value is to let sql do the join (and therefore defer responsibility of guarding against sql injection attacks)
<robacarp> sorry just catching up
<robacarp> yeah, you're mixing paradigms here
<FromGitter> <OpakAlex> but interestion was wrong
<FromGitter> <OpakAlex> yep
<FromGitter> <OpakAlex> i am sure for this))
<robacarp> the and(matches) method isn't for matching one of multiple values
<robacarp> it's for matching all name=value pairs
<FromGitter> <OpakAlex> make sense, but we have has of 3 keys
<robacarp> if you want to match one of many values, you need an IN() builder
<robacarp> and this should be def where(field : (Symbol | String), operator : Symbol, value : Array(Granite::Columns::Type))
<robacarp> I don't remember if the IN() builder is there or not, it's been like 18mo since I wrote this
<FromGitter> <OpakAlex> but can you create an PR? because for me it's so magic
<robacarp> sorry, I can't... I'm swamped at work these days :(
<FromGitter> <Blacksmoke16> Should have handled arrays genetically
<robacarp> genetically?
<FromGitter> <OpakAlex> maybe generacaly?
<FromGitter> <Blacksmoke16> Autocorrect ha
<robacarp> honestly this feels like it might be a regression in the latest crystal
<robacarp> because from the tests that Blacksmoke16 just linked, it should be working
<FromGitter> <OpakAlex> it was not id: []
<robacarp> a regression or a change in the way the code needs to be written
<FromGitter> <OpakAlex> make sense
<FromGitter> <OpakAlex> yep
<FromGitter> <OpakAlex> only fails my example
<FromGitter> <OpakAlex> where just id: []
<robacarp> what does that mean from a sql perspective though
<robacarp> select * from users where id IN()
<robacarp> in what
<FromGitter> <OpakAlex> i dont think it will come to sql
<FromGitter> <OpakAlex> we have some loop inside build query
<robacarp> sure but to code for it you have to define the goal
<robacarp> what should the result be
<robacarp> it's weird that all the tests in this pull from a year ago have `.where(date_completed: nil, <actual test condition>)`
<FromGitter> <OpakAlex> but my issue i am so new into Crystal language. And i am working on another issue for N+1 prevent
<robacarp> (most, not all)
<FromGitter> <OpakAlex> but spec with id: [] fails
<FromGitter> <OpakAlex> easy spec
<FromGitter> <Blacksmoke16> I think I was writing them in regards to my use case
<robacarp> yeah
<FromGitter> <Blacksmoke16> But yea, only id might use a different overload
<FromGitter> <OpakAlex> yes. this why we see into my pr (of course wrong fix)
<robacarp> so this example code you have her
<robacarp> review1.id and review2.id are going to be the same type
<FromGitter> <OpakAlex> yes
<FromGitter> <OpakAlex> i hope
<robacarp> so it's not id: [Array of Int32 | Int64]
<FromGitter> <OpakAlex> why?
<FromGitter> <OpakAlex> what is type here for id?
<robacarp> because they're both Int32
<robacarp> it'll be Array(Int32)
<FromGitter> <OpakAlex> hm, not Array(Int32 | Int64) ?
<FromGitter> <OpakAlex> it's union type
<FromGitter> <OpakAlex> or i am wrong?
<robacarp> the type is determined programmatically -- if you do `[3, 4] ` that's just Array(Int32)
<FromGitter> <OpakAlex> so | means union not OR ?
<robacarp> it means it can have both, or does have both
<robacarp> oh I see what you mean
<FromGitter> <OpakAlex> yes
<robacarp> you're just mean any array of ints
<FromGitter> <OpakAlex> yep
<robacarp> threw me off there
<robacarp> okay, I still don't see the actual infinte loop in the code paste... maybe it didn't save?
<FromGitter> <OpakAlex> i have this: ⏎ [0x1029e4b9a] *Granite::Query::Builder(Review)@Granite::Query::Builder(Model)#where<NamedTuple(field: String, operator: Symbol, value: String | Symbol)>:Granite::Query::Builder(Review) +458 ⏎ [0x1029e49cb] *Granite::Query::Builder(Review)@Granite::Query::Builder(Model)#and<NamedTuple(field: String, operator: Symbol, value: String | Symbol)>:Granite::Query::Builder(Review) +91 ⏎ [0x1029e4967]
<FromGitter> ... *Granite::Query::Builder(Review)@Granite::Query::Builder(Model)#and:field:operator:value<String, Symbol, (String | Symbol)>:Granite::Query::Builder(Review) +167 ⏎ [0x1029e4b9a] *Granite::Query::Builder(Review)@Granite::Query::Builder(Model)#where<NamedTuple(field: String, operator: Symbol, value: String | Symbol)>:Granite::Qu ... [https://gitter.im/amberframework/amber?at=5ee3f0407c64f31f11593a64]
<FromGitter> <OpakAlex> maybe it's not infinity loop, but looks like this
<FromGitter> <OpakAlex> if you run master with my spec you will see it
<FromGitter> <robacarp> are you on Crystal 0.35?
<FromGitter> <OpakAlex> yep
<FromGitter> <OpakAlex> master green with 0/36
<FromGitter> <robacarp> but the rest of the specs past?
<FromGitter> <OpakAlex> this is new spec i added today
<FromGitter> <OpakAlex> yes, all another looks good
<FromGitter> <robacarp> but what I'm saying is there are a bunch of spec's that pass this behavior
<FromGitter> <OpakAlex> not this.....it's only one with id: []
<robacarp> your spec doesn't have that
<robacarp> found = Review.where(id: [review1.id, review2.id]).select
<FromGitter> <OpakAlex> yes: id: [Int32 | Int64]
<robacarp> there are a couple dozen tests which check that an array can be passed to the where
<FromGitter> <Blacksmoke16> key difference is this context is just `id: [review1.id, review2.id]`
<FromGitter> <Blacksmoke16> and uses objects within the array, versus scalar values
<FromGitter> <Blacksmoke16> granted i didnt look into this at all yet tho
<robacarp> a object.id is just an Int, no magic there
<robacarp> it might be an Int?
<robacarp> is that the problem?
<robacarp> it's an optional type?
<FromGitter> <Blacksmoke16> everything is nilable
<FromGitter> <Blacksmoke16> er but that getter is not nilable i think
<robacarp> I think id isn't nilable
<FromGitter> <Blacksmoke16> i would expect it to be `Int32` since they're both the same model
<FromGitter> <Blacksmoke16> it has to be
<FromGitter> <Blacksmoke16> doesnt have one until its saved
<robacarp> I thought it raised if you tried to read it before save
<FromGitter> <Blacksmoke16> not sure
<robacarp> in any case, all the examples in the tests from last jan are literals, which aren't nilable
<FromGitter> <OpakAlex> they are not nil
<robacarp> okay, I don't think you mean `id: []` (query for id= empty array), I think you mean `id: Array(Int32?)` (query for id= one of the values in an array where they _may_ be nil)
<robacarp> I don't see why that would cause an infinite loop...but I could easily see that being a bug
<robacarp> when crystal sees an infinite loop, it says so explicitly:
<robacarp> crystal eval 'def yolo; yolo; end; yolo'
<robacarp> Stack overflow (e.g., infinite or very deep recursion)
<FromGitter> <Blacksmoke16> It does say that
<robacarp> I'm apparently lost, I don't see that anywhere
<FromGitter> <Blacksmoke16> He didn't include it in the trace
<FromGitter> <Blacksmoke16> Trace is like a few thousand lines
<robacarp> :headdesk:
<FromGitter> <OpakAlex> i am sorry it's end of output which i see on my mac