ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<SamantazFox_> Hello! I don't understand how an Array is used along a prepared DB query, can someone tell me what's wrong?
<SamantazFox_> SELECT * FROM table WHERE id IN ($1)
<SamantazFox_> the Array passed in is an `Array(String)`
ur5us has quit [Ping timeout: 240 seconds]
<FromGitter> <Blacksmoke16> i think it should just work
<FromGitter> <Blacksmoke16> can you share your code?
<SamantazFox_> https://bpa.st/PIQQ
<FromGitter> <Blacksmoke16> and does that produce an error or?
<SamantazFox_> with `(($1))` I'm getting no error. with `($1)` I'm getting `Unhandled exception: syntax error at or near "$1"`
<SamantazFox_> (before that, the old code was using `IN (($1),($2),($3),($4))`
<SamantazFox_> (extended to `$#(array.size}`)
<SamantazFox_> Okay, nevermind `WHERE id = ANY($1)` works
<FromGitter> <Blacksmoke16> what happens if you do like `PG_DB.query_all(request, args: ids, as: ChannelVideo)`
<SamantazFox_> And to answer your question, using `args:` yields: `Unhandled exception: bind message supplies 4 parameters, but prepared statement "" requires 1`
<FromGitter> <Blacksmoke16> when using `WHERE id IN ($1)`
<SamantazFox_> yes
<FromGitter> <Blacksmoke16> about about that + `WHERE id IN ($1::text[])`
<SamantazFox_> gimme a sec
<SamantazFox_> `Unhandled exception: operator does not exist: text = text[]`
<SamantazFox_> trying without the parenthesis
<SamantazFox_> (and yes, I've removed `args:` from the `query_all` call)
<SamantazFox_> Nope, another error without parenthesis
<FromGitter> <Blacksmoke16> you need `args:`
<FromGitter> <Blacksmoke16> https://crystal-lang.github.io/crystal-db/api/0.10.1/DB/QueryMethods.html#query(query,*args_,args:Array?=nil)-instance-method, assuming this applies to the other methods as well
<SamantazFox_> args is used to pass an array of arguments, that are mapped to $1, $2 $3 and so on
<SamantazFox_> In my case, I want to provide the array directly
<FromGitter> <Blacksmoke16> yea you're right, not what you want
<FromGitter> <Blacksmoke16> im sure theres a way...
ur5us has joined #crystal-lang
ur5us has quit [Quit: Leaving]
ur5us has joined #crystal-lang
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Quit: Leaving]
maddi has left #crystal-lang [#crystal-lang]
greenbigfrog has quit [Ping timeout: 240 seconds]
greenbigfrog has joined #crystal-lang
greenbigfrog has quit [Remote host closed the connection]
greenbigfrog has joined #crystal-lang
jrayhawk_ is now known as jrayhawk
ur5us has joined #crystal-lang
yxhuvud has quit [Read error: Connection reset by peer]
yxhuvud has joined #crystal-lang
<FromGitter> <dscottboggs:matrix.org> is there an easy way to tell if an optional dependency (like GMP or regex) is installed in order to fall back on a different implementation?
<FromGitter> <Blacksmoke16> be easier to just say, hey go install this
<FromGitter> <RespiteSage> Yeah, I recall reading recently (maybe on the forum) about a way of doing that at runtime, but I think that's the hardest (followed by doing it at compile-time, then by just telling users to install something).
<FromGitter> <RespiteSage> Though that's about using `.so` files at runtime, so maybe there's an easier way of just checking if they're there.
<FromGitter> <RespiteSage> I guess if your executable has permissions to run `ldconfig`, you could just run that using `Process`.
rymiel_ has quit [Quit: quit]
rymiel has joined #crystal-lang
<FromGitter> <moe:busyloop.net> yea, i would rather do that at compile time (and link statically if at all possible). runtime deps are nothing but pain. having random binaries break after an `apt upgrade` is no fun.
ur5us has quit [Ping timeout: 240 seconds]