Skip to content

Instantly share code, notes, and snippets.

@mrkgnao
Created February 19, 2018 16:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkgnao/77b98ce509d76370fa4c0c29d6e3e5e4 to your computer and use it in GitHub Desktop.
Save mrkgnao/77b98ce509d76370fa4c0c29d6e3e5e4 to your computer and use it in GitHub Desktop.
What hosts do you visit most often in Firefox?
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import Protolude hiding ((:*:), optional)
import Database.Selda
import Database.Selda.Generic
import Database.Selda.SQLite
firefoxDbPath = "/home/$USER/.mozilla/firefox/$PROFILE/places.sqlite"
main :: IO ()
main = do
putText "Top 5 sites by frecency:"
withSQLite firefoxDbPath $ topSites >>= traverse_ print
data ZHost = ZHost
{ id :: RowID
, host :: Text
, frecency :: Maybe Int64
, typed :: Text
, prefix :: Maybe Int64
} deriving Generic
hosts :: GenTable ZHost
hosts = genTable "moz_hosts" [id :- primaryGen]
-- I don't remember how to use Selda to do LIMIT
topSites :: SeldaM [Text]
topSites = map (take 5) . query $ do
(_ :*: zhost :*: zfrecency :*: _) <- select (gen hosts)
order zfrecency descending
pure zhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment