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
jmd_ has joined #crystal-lang
jmdaemon has quit [Ping timeout: 268 seconds]
<FromGitter> <stellarpower> Also a totally unimportant question, but does anyone know why `do`/`end` seems to be favoured over `{}` these days?
<FromGitter> <stellarpower> I far prefer the curly braces. I think it's very important when scanning code to see the difference between a block and a more general control statement, and thisstands out much more easily for me if I always use curly braces. Plus, they tend to nest themselves more naturally, so when several levels deep it's also easier to navigate by matching the pairs.
<FromGitter> <Blacksmoke16> the former is when its over multiple lines, braces when its a single line
<FromGitter> <Blacksmoke16> is how iv'e always done it
Guest1027 has joined #crystal-lang
<FromGitter> <stellarpower> Oh really? I'd never noticed before
Guest1027 has quit [Client Quit]
<FromGitter> <stellarpower> That's interesting.
<FromGitter> <Blacksmoke16> can mix/match ofc, but thats the general rule of thumb i always followed
<FromGitter> <stellarpower> Yeah of course.
<FromGitter> <stellarpower> I steadfastly refuse to use do/end XD
<FromGitter> <stellarpower> At least on my own code
<FromGitter> <moe:busyloop.net> braces remind me too much of javascript, so i avoid them whenever i can
frojnd has quit [*.net *.split]
oz has quit [*.net *.split]
frojnd has joined #crystal-lang
ox has joined #crystal-lang
notzmv has quit [Ping timeout: 260 seconds]
notzmv has joined #crystal-lang
ur5us has joined #crystal-lang
hightower4 has quit [Remote host closed the connection]
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
hightower2 has joined #crystal-lang
jmd_ has quit [Ping timeout: 260 seconds]
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
Sankalp has joined #crystal-lang
ox is now known as oz
ur5us has quit [Ping timeout: 255 seconds]
hightower2 has quit [Ping timeout: 240 seconds]
hightower2 has joined #crystal-lang
adam12 has left #crystal-lang [The Lounge - https://thelounge.chat]
frojnd has quit [Changing host]
frojnd has joined #crystal-lang
<FromGitter> <cinnamonz:matrix.org> I want to use sqlite with the std library and so I read the examples which are using `DB.open` and `DB.close` to manage connections. Though I want to store the `DB::Database` in an instance variable.
<FromGitter> <cinnamonz:matrix.org> Would something like this manage the connections alright? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=62c321b876cd751a2fba2466]
<FromGitter> <Blacksmoke16> idt you should close the entire connection on an exception like that, as i think that would prevent future queries?
<FromGitter> <Blacksmoke16> `DB::Database` represents a pool of connections, which internally handles what you're trying to do i think
<FromGitter> <Blacksmoke16> it's also fairly common to have it be a class var/const
<FromGitter> <Blacksmoke16> like a singleton
<FromGitter> <Blacksmoke16> the entire pool*
<FromGitter> <cinnamonz:matrix.org> I was looking for examples on how other people use it, I've kept seeing this pattern: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=62c326f39f29d42bedf864be]
<FromGitter> <cinnamonz:matrix.org> For every action, they open and close while having the connection uri in the scope
<FromGitter> <Blacksmoke16> yea i think thats not the best way to do it
<FromGitter> <cinnamonz:matrix.org> Agreed, that's why I started experimenting with it :)
_ht has joined #crystal-lang
<FromGitter> <cinnamonz:matrix.org> So according to this, if we use the yield blocks the connections are automatically managed.
<FromGitter> <Blacksmoke16> `DB.open` that is
<FromGitter> <cinnamonz:matrix.org> If not, you're supposed to handle it on your own
<FromGitter> <cinnamonz:matrix.org> Yeah
<FromGitter> <cinnamonz:matrix.org> It reads like this is the preferred method. Use `DB.open` in every action and use the yield block for auto management.
<FromGitter> <cinnamonz:matrix.org> I understand having the URI as a class const but how can I have the pool itself as a class const without manually opening/closing connections?
<FromGitter> <Blacksmoke16> i think you're still misundersatnding `DB.open`
<FromGitter> <Blacksmoke16> you'd just do like `@@database = DB.open "..."`
<FromGitter> <Blacksmoke16> `DB.open` returns a `DB::Database` which is the pool of connections, it doesnt matter if you use the yielding or non yielding version of `.open` as they both return the same type/obj
<FromGitter> <Blacksmoke16> in practice when your web server shuts down, the OS will close those connections for you
<FromGitter> <stellarpower> What would be the recommended way of searching the filesystem? Google is just giving me crap.
<FromGitter> <Blacksmoke16> for a file with a specific name?
<FromGitter> <stellarpower> I know there's Dir.glob, but are there any other options?
<FromGitter> <stellarpower> regex in this case
<FromGitter> <stellarpower> but yeah, that sort of thing
<FromGitter> <Blacksmoke16> glob is the only thing that comes to mind
<FromGitter> <Blacksmoke16> outside of the other Dir methods like entries/children
<FromGitter> <stellarpower> Back to the shell again XD
<FromGitter> <cinnamonz:matrix.org> Got it, for some reason `DB.open` didn't register as a pool in my head. Kept thinking it as a single connection. 😅
<FromGitter> <stellarpower> Or I oculd probably just glob for this
<FromGitter> <stellarpower> But seems less general
<FromGitter> <Blacksmoke16> `DB.connect` returns a single connection. there's also a `#with_connection(&)` method on `DB::Database` that yields/closes a connection from that pool
<FromGitter> <cinnamonz:matrix.org> Thanks! I'll read up on that one now.
<FromGitter> <Blacksmoke16> https://crystal-lang.org/reference/1.4/database/index.html this whole section might be a good read
<FromGitter> <cinnamonz:matrix.org> 👍️
<FromGitter> <dylanusdt:matrix.org> I'll help 10 individuals how to earn $20,000 in just 72 hours from the crypto/forex market. But you will pay me 10% commission when you receive your profit. if interested send me a direct message via Whatapp by asking me HOW for more details on how to get started ⏎ +1 (570) 801-0862
<FromGitter> <stellarpower> If you're gonna make promises you probably want a Javascript chat
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 264 seconds]
_ht has quit [Remote host closed the connection]
jmdaemon has joined #crystal-lang
hightower4 has joined #crystal-lang
hightower2 has quit [Ping timeout: 240 seconds]
Sankalp has quit [Ping timeout: 240 seconds]
Sankalp has joined #crystal-lang
foxxesStar has quit [Ping timeout: 246 seconds]
<FromGitter> <stellarpower> `Error: no overload matches 'Array(Float64 | String)#+' with type (Array(Float64) | Array(String))`
<FromGitter> <stellarpower> I'm going around in circles a bit here, trying to add two arrays of different types.
<FromGitter> <stellarpower> What ought I do in a case like this? I've tried specifying the type, using `[] of Float64|String`, or originally just used `+` and was hoping that it'd infer the type of the result, but instead it's calling + on the first array and failing
<FromGitter> <stellarpower> `[1,2,3] + %w(a b c)` just works in the interpreter, so not sure where I'm going wrong
<FromGitter> <stellarpower> Is it because there's a differece inb how the compiler can handle `Array(T|U)` vs. `Array(T)|Array(U)`?
foxxesStar has joined #crystal-lang