<FromGitter>
<jwoertink> Ok, so what makes it "weird" is that with the `DB.exec`, if I add the tuple to specify the types, the error goes away. Alternatively, if I remove the `to_json` with this setup, it will work
<FromGitter>
<johnjansen> what does the hash look like (does that work) without the to_json
<FromGitter>
<jwoertink> yes, without the `to_json` it works. It's just a normal hash
<FromGitter>
<raydf> the problem i believe is that some types, like Array(PG::Geo::Point) are not very json serialization friendly
<FromGitter>
<jwoertink> ^ that's what I figured
<FromGitter>
<jwoertink> which is why I'm thinking it's a pg error
<FromGitter>
<johnjansen> agreed,
<FromGitter>
<johnjansen> its not PG IMO
<FromGitter>
<johnjansen> can you drop the hash into that gist
<FromGitter>
<raydf> you should do this: DB.exec({Int32, String} ,"SELECT id, username FROM members LIMIT 1000")
<FromGitter>
<raydf> try to restrict the returning data types for better experience with the lib
pawnbox has joined #crystal-lang
<FromGitter>
<johnjansen> @raydf you hit the mark ;-)
pawnbox has quit [Remote host closed the connection]
<FromGitter>
<jwoertink> yeah, that works, but for my queries, I can't specify the types
<FromGitter>
<raydf> then use case when Int32, String, etc...
<FromGitter>
<johnjansen> why not, the data in the DB is a fixed type
<FromGitter>
<raydf> he's using dynamic sql
<FromGitter>
<johnjansen> not to be argumentative
<FromGitter>
<johnjansen> ok ;-)
<FromGitter>
<raydf> i suppose
<FromGitter>
<jwoertink> yup
<FromGitter>
<raydf> I'm almost sure you're only returning some limited types like, String, Int64, Float64, etc. etc. if you use case of types you'll have a clean structure to serialize
<FromGitter>
<raydf> Generics could help you in this case
<FromGitter>
<jwoertink> my database has some tables without IDs, some had IDs as ints, some have IDs as strings
<FromGitter>
<jwoertink> so, the types have to be specified per "model"
<FromGitter>
<raydf> use generics
<FromGitter>
<jwoertink> ?
<FromGitter>
<raydf> in each model try to specify with free variables the type of data for the id
<FromGitter>
<jwoertink> Have an example?
<FromGitter>
<jwoertink> Like, what would that look like in a simple example?
<FromGitter>
<jwoertink> Just trying to wrap my head around this
<FromGitter>
<jwoertink> So you have something like `class Whatever < Warp::View` and then you can just do `Whatever.new`? Where does that `T` come in to play?
<FromGitter>
<raydf> as you may see props[:title]? is a String | Nil
<FromGitter>
<raydf> there's the generics in action
<FromGitter>
<raydf> if i use a Int32 in title then the types would be String | Int32
<FromGitter>
<raydf> For your models you can create some kind of usage like that for each column
<FromGitter>
<jwoertink> The concept makes sense. I'm still unclear how you would instantiate the `Entities`. Would it just be `Web::View::Entities::Entities(String).new` ?
<FromGitter>
<raydf> in the @johnjansen case: ⏎ ``````
<FromGitter>
<raydf> Thanks @johnjansen, much simpler example
<FromGitter>
<jwoertink> Oh, ok. That's cool
<FromGitter>
<raydf> :)
<FromGitter>
<johnjansen> right, and i often use it for Enumerables of unknown types, where the collection has behaviours, but i dont know what the collection will have in it
<FromGitter>
<johnjansen> oh and @jwoertink if its not obvious `T` is not the only name you can use, its just the standard one, call it anything that makes sense
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
pawnbox has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Philpax has quit [Ping timeout: 260 seconds]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 265 seconds]
mhib has quit [Quit: Leaving]
fedruantine has quit [Ping timeout: 252 seconds]
jwaldrip has quit [Read error: Connection reset by peer]
jwaldrip has joined #crystal-lang
daekano has quit [Ping timeout: 256 seconds]
daekano has joined #crystal-lang
<FromGitter>
<jwoertink> Anyone that's used the pg shard know how to just get the raw response from a query? I'm digging through the source but not seeing any methods
<FromGitter>
<sdogruyol> How was the reaction of people
<FromGitter>
<sdogruyol> @jwoertink results.rows?
<FromGitter>
<jwoertink> I'm using the postgres json, so my raw result is json, but `rows` returns hashes
<FromGitter>
<jwoertink> I was hoping to just do something like `JSON.parse(DB.exec(...).raw)`, and be done with it instead of iterating over the results and having to map each one
<FromGitter>
<johnjansen> @jwoertink can you put the json somewhere for a quick look
<FromGitter>
<jwoertink> nothing fancy. Just normal JSON
<FromGitter>
<johnjansen> whats that wrapped in, i mean to make it “rows"
<FromGitter>
<jwoertink> I can run `SELECT json_build_object('id', id, 'username', username) FROM members LIMIT 1000;` in `psql` to get that result, but once I run it through `DB.exec` I get back `[[{"id" => "2776339000b56f68e8", "username" => "jmic4231"}]]`
<FromGitter>
<jwoertink> but calling `to_json` on that hash throws that wonky error
<FromGitter>
<johnjansen> whats the error
<FromGitter>
<jwoertink> the one that I posted last night
<FromGitter>
<johnjansen> oh that one again ;-)
<FromGitter>
<jwoertink> I know why I get that error. I'm just trying to come up with a solution around it
<FromGitter>
<johnjansen> i have to run, but ill have alook at it later on
<FromGitter>
<paulcsmith> If I move the FIELDS constant outside the inherited macro it works, but then that same constant is shared across all subclasses that inherit from `App::Record`, which I don't want
<FromGitter>
<sdogruyol> @jwoertink ugh now that's tough
<FromGitter>
<jwoertink> Looks like @paulcsmith is headed down the same road I am lol
<FromGitter>
<jwoertink> my issue would probably be solved by the active_record.cr shard, but it looks like that's not really being updated
<FromGitter>
<sdogruyol> A shard for that kind of conversion would be great
bjz has joined #crystal-lang
<FromGitter>
<paulcsmith> Haha. Yeah I had `FIELDS` outside of the `macro inherited`, but then when I went to add another model I realized the `FIELDS` constant was shared :S
<FromGitter>
<paulcsmith> @jwoertink Looks like we definitely are. I'm trying to learn Crystal by building an app and the web framework at the same time
<FromGitter>
<jwoertink> scary!
<FromGitter>
<sdogruyol> @paulcsmith use kemal
<FromGitter>
<paulcsmith> Yeah, but fun
<FromGitter>
<sdogruyol> And build some product so that we can showcase
<FromGitter>
<paulcsmith> I'd rather build my own thing right now. It's fun :)
<FromGitter>
<paulcsmith> I've been looking at Kemal though, and I've used some of the concepts in my app :D
<FromGitter>
<sdogruyol> :smile:
<FromGitter>
<sdogruyol> Cool
<FromGitter>
<jwoertink> unfortunately, you won't be able to showcase my apps :(
<FromGitter>
<paulcsmith> The ORM is the hard part. I know you don't like ORMs, but I do haha. It's proving difficult though. Trying to figure out how to do things without `send` is tricky
<FromGitter>
<sdogruyol> I am building a big platform gateway with Kemal
<FromGitter>
<paulcsmith> I'd love to share the app I'm working on, but probably won't be done for at least a few months
<FromGitter>
<sdogruyol> @paulcsmith use tren I know it's more code but it's just sql
<FromGitter>
<paulcsmith> I saw that. It was interesting, but I like the comparability of query builders
<FromGitter>
<sdogruyol> @jwoertink we can If the company wants to
<FromGitter>
<paulcsmith> Plus I want to make the queries type safe. By declaring fields and their types in the model I can ensure that the fields actually exist and that types are correct. I think that would be really cool
<FromGitter>
<sdogruyol> You can do that with tren
<FromGitter>
<sdogruyol> Even overload queries
<FromGitter>
<sdogruyol> For nilable or optional params
<FromGitter>
<paulcsmith> Oh I see that now. Very cool.
<FromGitter>
<paulcsmith> But how can you compose queries? I want to be able to do something like `Post.published.popular`
<FromGitter>
<sdogruyol> I do that in sql
<FromGitter>
<paulcsmith> That's pretty important IMO
<FromGitter>
<paulcsmith> Can you give an example of what you mean?
<FromGitter>
<sdogruyol> Tren has composable queries
<FromGitter>
<jwoertink> @sdogruyol I think the company would be ok with it, but I work in the Adult video industry ;) lol
<FromGitter>
<sdogruyol> Hold on
<FromGitter>
<sdogruyol> @jwoertink rofl
<FromGitter>
<jwoertink> and most of our logos alone are pretty gnarly.... So even just showing a logo would be pretty bad haha
<FromGitter>
<paulcsmith> @sdogruyol Ah I see the example in the readme now. That's an interesting way to handle it
<FromGitter>
<jwoertink> but once I have Namechk fully moved over, that will be a good one to showcase :D
<FromGitter>
<jwoertink> @paulcsmith I have no clue, but going to take a guess here. The outter macro generates the inner macro. The inner macro has the {% %} tags to generate crystal, but at the time that's ran, the outter macro hasn't generated the FIELDS constant yet
<FromGitter>
<paulcsmith> Oh yeah that makes sense
<FromGitter>
<paulcsmith> Thanks Jeremy :)
<FromGitter>
<jwoertink> I could be totally wrong, but that would be my best guess
<FromGitter>
<sdogruyol> @paulcsmith I'd advise you to take a look at Tren code
<FromGitter>
<sdogruyol> The run macro may be what you are looking for
<Papierkorb>
A port of the (albeit huge) `sequel` gem would be amazing
<FromGitter>
<sdogruyol> It's kinda hard to get at first but pretty useful
<FromGitter>
<paulcsmith> @sdogruyol Will do. Thanks for the tip!
<FromGitter>
<sdogruyol> Just a wild guess
<FromGitter>
<sdogruyol> Wish I could be more help
<FromGitter>
<paulcsmith> And what does the `\` do before macro interpolation? I checked the macro docs, but haven't ever found anything about that :S
<FromGitter>
<sdogruyol> It's actually for escaping
<FromGitter>
<sdogruyol> Takes a bit trial and error to actually understand macros
<FromGitter>
<paulcsmith> Ohhh, gotcha
<FromGitter>
<paulcsmith> Yeah it's tricky :P
<FromGitter>
<sdogruyol> But it's super powerful
<FromGitter>
<sdogruyol> You should really talk to @f when it comes to macros
<FromGitter>
<sdogruyol> He built some crazy stuff with macros
<FromGitter>
<fkchang> @sdogruyol they liked it, I generally frame crystal as the go to for Rubyists who need the speed/perf/low resources, I think they were surprised at both results and how close to Ruby it is
<FromGitter>
<sdogruyol> That's really nice to hear
<FromGitter>
<johnjansen> BTW @zatherz you can also send that msgpack data around the place, as you can unpack it to something usable without the class ⏎ ```unpacker = MessagePack::Unpacker.new(File.read("msgpack_test")) ⏎ unpacker.read``` [https://gitter.im/crystal-lang/crystal?at=5813c1fa0e25dbfa11715844]
woodruffw has joined #crystal-lang
<FromGitter>
<zatherz> oh, nice! what does .read return? the class that was packed?
<FromGitter>
<johnjansen> from the House example `{"address" => "Something", "location" => {"lat" => 12.3, "lng" => 34.5}}`
<FromGitter>
<johnjansen> its meant to be used for API’s etc
<FromGitter>
<johnjansen> im tempted to use it for all my internal stuff, but then id be forgetting that it can be unpacked in the browser too http://msgpack.org/#msgpack-lite--
<FromGitter>
<zatherz> wow, nice
soveran has quit [Remote host closed the connection]
<crystal-gh>
[crystal] ysbaddaden pushed 11 new commits to master: https://git.io/vXIVe