←back to thread

261 points david927 | 1 comments | | HN request time: 0.325s | source

What are you working on? Any new ideas that you're thinking about?
Show context
maattdd ◴[] No.43160786[source]
I've been updating my HN bot (watch comments for keywords and post to Slack/Discord) written in Crystal to use raw SQL instead of unmaintained ORM.

Turns out the whole app needs only ~ 10 SQL requests, and it's way funier to write modern SQL than fighting the ORM.

The new code looks like this :

    db_message = Model.save_new_message!(@conf.db, DbButler::Hn, item, DbState::Processing)
Than I have a Model module with all the interactions with the DB

    def self.save_new_message!(db, butler, external_id, state) : Message
        sql = {{ read_file "./db/save_new_message.sql" }}
        db.query_one(sql, butler.to_s.downcase, external_id, state.to_s.downcase, as: Message)
   end
(thanks to Crystal ability to read a file at compile time - I can write raw SQL in a file with syntax highlithing and maybe typesafe if I connect the DB to the editor)

The land page is not ready, but the bot has been working for me for months https://newsbutler.xyz/

replies(1): >>43172332 #
lippihom ◴[] No.43172332[source]
Hmm any plans on integrating it with Discord instead of Slack? Also, aware of https://f5bot.com/?
replies(1): >>43191661 #
1. maattdd ◴[] No.43191661[source]
It is working with both Slack and Discord already.

I was not aware of f5bot, but I got inspired by another bot called Little Birdie which doesn't exist anymore and it's basically just a re-implementation of it.