<FromGitter>
<naqvis> i would say you need to think about your design
<FromGitter>
<naqvis> more simple option would be to use `JSON::Any` as value, as that almost covers your value types
<FromGitter>
<naqvis> but to fix your problem, you would have to separate your declaration with all possible cases of types you are expecting to put into your hash
<FromGitter>
... ce832cc54f1a1d17ad4d81c0: {"message":"cast from Int64 to String failed, at /usr/local/lib/crystal/json/any.cr:215:5:215","errtype":"#<TypeCastError:cast from Int64 to String failed, at /usr/local/lib/crystal/json/any.cr:215:5:215>","jid":"ce832cc54f1a1d17ad4d81c0","backtrace":["/usr/local/lib/crystal/json/any.cr:214:3 in 'as_s'","Work ... [https://gitter.im/crystal-lang/crystal?at=60a62b3c77c281623c689f4e]
<FromGitter>
<emanzx> "destination" => "1.2.3.4", is a string.
<FromGitter>
<emanzx> why crystal say it Int64
fifth has quit [Quit: WeeChat 3.1]
<straight-shoota>
Are you sure the error is from accessing `destination`?
<straight-shoota>
It is clearly a string in the Crystal output
<jhass>
We gotta see WorkerMon.cr:122
<FromGitter>
<emanzx> sorry.. was focusing on my code.. save the trouble by serializing the JSON.. haha.. first time I serialize my JSON.. dont know it was better that way
<FromGitter>
<Blacksmoke16> ah, prob would have to use a converter, so on write it does `.to_json` and stores as string, on read it dose `JSON.parse` to get it back into `JSON::Any`
<FromGitter>
<emanzx> ok.. any doc I should refer too..
<FromGitter>
<emanzx> I actually need write only..
<FromGitter>
<Blacksmoke16> theres already a json convert built in, just need to use it
<FromGitter>
<emanzx> in granite?
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<emanzx> `Json(M, T)` - Converters an `Object` of type `M` to/from a database column of type `T.` Supported types for `T` are: `String`, `JSON::Any`, and `Bytes`.
<FromGitter>
<Blacksmoke16> ah, i think this built in one is mainly for like `SomeObj.from_json`
<FromGitter>
<Blacksmoke16> versus supporting the `JSON::Any` type. Could define your own tho :shrug:
<FromGitter>
<emanzx> trying to understand how to use the converter
<FromGitter>
<emanzx> any tutorial I can look into..
<FromGitter>
<Blacksmoke16> how to use them, or how to make one?
<FromGitter>
<Blacksmoke16> looks like it yea, what happens if you add a `pp str` and then like `pp "failed to parse"` before returning `nil` in `from_rs`
<FromGitter>
<Blacksmoke16> i guess one thing i should also ask, what type os the `extra` column in the db?
<FromGitter>
<emanzx> I still getting the cannot be nil error
<FromGitter>
<Blacksmoke16> welp, im out of ideas
<FromGitter>
<emanzx> hmm.. the weird thing is.. it does not display the pp value
<FromGitter>
<emanzx> @Blacksmoke16 if I set the field type to String it wont work?
<FromGitter>
<Blacksmoke16> on the model? idt because the data from the db isnt a string
<FromGitter>
<Blacksmoke16> ill try and reproduce and see if i can figure it out
<FromGitter>
<emanzx> ok.
<FromGitter>
<emanzx> do you want snapshot of my code?
<FromGitter>
<Blacksmoke16> i should have enough. already provided schema, model, and converter
<FromGitter>
<emanzx> ok
<FromGitter>
<emanzx> I would prefer if I can use JSONB in postgress.. because of indexing and casting of JSON data if not I need to change to String and just save the JSON string as String in DB
<FromGitter>
<emanzx> or ditch the granite and use crystal-pg instead?
<FromGitter>
<Blacksmoke16> if you care you wont be using an ORM at that piont
<FromGitter>
<Blacksmoke16> dont care*
<FromGitter>
<emanzx> I just need to save to DB only..
<FromGitter>
<Blacksmoke16> never read/query?
<FromGitter>
<emanzx> nope
<FromGitter>
<Blacksmoke16> if so then yea, prob could just do that
<FromGitter>
<emanzx> Ok I will look into that
<FromGitter>
<emanzx> @Blacksmoke16 how can I pass variable into a struct?
<FromGitter>
<Blacksmoke16> hm?
<FromGitter>
<emanzx> I create my own class to save to DB
<FromGitter>
<Blacksmoke16> does it even need to be a class? versus just like a module with a private const to store the URL and some class methods for doing the stuff?
<FromGitter>
<emanzx> actually my coding level still not surpass Class or other type apart from simple function using def
<FromGitter>
<emanzx> so this is the first time im using class or others
<FromGitter>
<emanzx> well mostly I follow tutorial..
<FromGitter>
<Blacksmoke16> guard clause is basically doing this
<FromGitter>
<emanzx> btw.. trying to understand this ⏎ ⏎ > does it even need to be a class? versus just like a module with a private const to store the URL and some class methods for doing the stuff?
<FromGitter>
<emanzx> I have many info inside the yml.. and some may not need in this code
<FromGitter>
<emanzx> can I serialize somepart of it?
<FromGitter>
<Blacksmoke16> should be possible to only deserialize the parts you need yea
<FromGitter>
<emanzx> I will do that.. today is the first time I do serialize for my json data.. I dont know it was so good
<FromGitter>
<emanzx> haha
<FromGitter>
<emanzx> > i was thinking a module because it's not likely you're going to be newing up more than 1 of them with different values ⏎ ⏎ for the tsdb.. yes it wont change
<FromGitter>
<Blacksmoke16> idk, code you posed earlier was typed to `JSON::Any`,
<FromGitter>
<Blacksmoke16> `.to_json` would return a `String`
<FromGitter>
<emanzx> oh
void09 has joined #crystal-lang
<FromGitter>
<emanzx> I wanted to save it to JSONB type.
<FromGitter>
<emanzx> so it should be in JSON right?
<FromGitter>
<Blacksmoke16> prob want `JSON::Any` then
<void09>
I'm thinking of hiring someone to build me a custom ecommerce platform, from scratch. I know someone that can do it for a reasonable price in ruby. But obviously not the fastest language out there.. Syntax of ruby is almost identical, i know, but the gems don't work out of the box
<void09>
Anyone know attemps to build something like this with crystal ?
<void09>
And how good of an idea would it be to choose crystal for such a project
<FromGitter>
<emanzx> I would not say Syntax of ruby is identical.. the basic is identical.. but for most part I dont think it optimized
<FromGitter>
<emanzx> I still having problem migrating to crystal myself
<FromGitter>
<emanzx> hahaha
<FromGitter>
<Blacksmoke16> yea, its impt to remember just because the syntax looks the same doesnt mean they're the same lang
<void09>
well, that's what the person said, looking at crystal code, that it's no problem for him. But the problem is, can't use rubygems
<void09>
they'd have to be converted, and some can be pretty large. Is there an attempt to rewrite ruby gems to shards ?
<FromGitter>
<Blacksmoke16> what im getting at is just because the code looks familiar to him doesn't mean it'll be easy to learn/use/port things
<FromGitter>
<Blacksmoke16> as its not as simple as 1:1 porting
deavmi has joined #crystal-lang
<deavmi>
Is this room on oftc of libera.chat?
<FromGitter>
<Blacksmoke16> there is not a goal to port all gems to shards no
<FromGitter>
<Blacksmoke16> would have to see whats available and use one of them, or port what you need over/start from scratch
<FromGitter>
<Blacksmoke16> whats gems in particular are you needing?
<void09>
No idea, I just know he uses lots of them to code
<void09>
I could ask
<FromGitter>
<Blacksmoke16> thats one of the cons of crystal atm. Its a younger lang so the ecosystem isn't as large
<void09>
so no ecommerce attempts ? even rudimentary ones?
_whitelogger has joined #crystal-lang
<void09>
I found about 5 of them in elixir/phoenix, but all abandoned :(
<void09>
still better than 0 in crystal.. i wonder why no one bothered?
<FromGitter>
<Blacksmoke16> prob same reason those other 5 are abandoned :P just takes time/effort
<void09>
well, elixir seems to be 3 years younger than crystal
<void09>
faker, tinymce-rails,roo,activerecord-import,wicked_pdf,bcrypt - most needed gems
<xybre-libera>
void09: bcrypt is in the stdlib
<FromGitter>
<Blacksmoke16> there's a faker lib iirc
<FromGitter>
<Blacksmoke16> AR import one is prob not doable given AR doesnt exist really
<void09>
Yeah, Elixir seems to have a reasonable amount of popularity, but it's functional, not oop, and I'm no expert here, but isn't that suboptimal for writing a huge oop-organic kind of project like an ecommerce CMS ?
<xybre-libera>
I like how Elixir is so state averse that in order to keep a counter you have to spawn a thread and communicate with it via messages
sorcus has joined #crystal-lang
<FromGitter>
<emanzx> I change my data type in db into string or varchar
<FromGitter>
<emanzx> and I keep getting this error