Finding the most frequent value in a SQLite column

I have a table with a list of trails that I’ve biked. I wanted to find out which trail I’ve biked the most. I used the following SQL query to find out: SELECT name, count(name) AS ct FROM trails GROUP BY name ORDER BY ct DESC LIMIT 5 This gave me the 5 trails I’ve biked the most. Translated to SQLAlchemy. from sqlalchemy import func def most_common_trails(db: Session): return ( db....

June 9, 2023 · 1 min

Updating a SQLite row with a value from another row

I had a table with a bunch of users and one of the users is a demo user and I wanted to copy the login token from my row to the demo user. This is how I managed to do that. UPDATE users SET token = (SELECT token FROM users u WHERE u.id = 1) WHERE id = 2; This will update the token column for the user with the id 2 with the value from the user with the id 1....

June 9, 2023 · 1 min

Vector Search

Recently I learned about a new kind of search called Vector Search or Semantic Search. This is a search technique that tries to find documents that match the meaning of the user’s search term instead of trying to match keywords like a Full Text Search (FTS). I wanted to try Semantic Search for my blog. I came across Alex Garcia’s post about a new SQLite extension for Vector Search called sqlite-vss....

June 1, 2023 · 6 min

Search (FTS)

Now that my blog is statically generated I need a way to support searching. Fuse.js ships with the theme and does a pretty good job of matching words in the blog posts. I want something a little bit more powerful. I mentioned in my previous post that I am using SQLite to store the blog posts. SQLite has a full text search feature that I can use to implement search....

May 30, 2023 · 2 min

Migrating out of PostHaven

My blog was hosted on PostHaven for about 12 years now. It’s a pretty good platform and has served me well. But I wanted to move my blog to a MarkDown powered static site. Unfortunately, posthaven doesn’t provide an export option, probably because it not in their financial interest. Oh well, I’ll scrape my own blog and extract the posts. My first attempt was to use the requests and BeautifulSoup to fetch the urls from the archives page....

May 19, 2023 · 2 min