hnix-store-db: Nix store database support

[ apache, library, nix ] [ Propose Tags ] [ Report a vulnerability ]

Implementation of the Nix store database


[Skip to Readme]

Flags

Automatic Flags
NameDescriptionDefault
build-bench

Build db-bench executable

Disabled
build-readme

Build README.lhs example

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies attoparsec, base (>=4.12 && <5), bytestring, data-default-class, esqueleto (>=3.5.10 && <3.6), fast-logger, hnix-store-core (>=0.8), hnix-store-db, microlens, monad-logger, persistent (>=2.14.5 && <2.15), persistent-sqlite (>=2.13.1 && <2.14), template-haskell, text, time, transformers, unliftio-core [details]
License Apache-2.0
Copyright 2023 Sorki
Author Sorki
Maintainer srk@48.io
Category Nix
Home page https://github.com/haskell-nix/hnix-store
Uploaded by srk at 2024-07-31T15:36:49Z
Distributions
Executables db-bench, db-readme
Downloads 32 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-07-31 [all 1 reports]

Readme for hnix-store-db-0.1.0.0

[back to package description]

hnix-store-db

Nix SQLite database implementation.

Only read-only functionality provided for database schema version 10.

API

The interface is experimental and might change wildly.

Example

This example is runnable via cabal run db-readme.

{-# LANGUAGE OverloadedStrings #-}

import Data.Default.Class (Default(def))

import qualified Control.Monad
import qualified Control.Monad.IO.Class

import qualified Database.Esqueleto.Experimental

import qualified System.Nix.StorePath
import qualified System.Nix.Store.DB.Run
import qualified System.Nix.Store.DB.Schema

import System.Nix.Store.DB.Query

main :: IO ()
main = do
  System.Nix.Store.DB.Run.runSystemSqlite $ do
    (paths, refs, drvOuts) <- queryEverything

    Control.Monad.IO.Class.liftIO $ do
      putStrLn $ "Stats: "
      let stat name v = putStrLn $ "- " ++ name ++ ": " ++ show (length v)
      stat "ValidPath(s)" paths
      stat "Ref(s)" refs
      stat "DerivationOutput(s)" drvOuts

    maybeValidPath <- queryOneValidDerivationEntity
    case maybeValidPath of
      Nothing -> pure ()
      Just validPathEntity -> do
        let pth =
              System.Nix.Store.DB.Schema.validPathPath
              $ Database.Esqueleto.Experimental.entityVal validPathEntity

        (same, samePath, references, referrers, validDerivers, outputs) <- (,,,,,)
          <$> queryPathInfo pth
          <*> queryPathFromHashPart def (System.Nix.StorePath.storePathHash pth)
          <*> queryReferences validPathEntity
          <*> queryReferrers pth
          <*> queryValidDerivers pth
          <*> queryDerivationOutputs validPathEntity

        Control.Monad.unless (same == Just (Database.Esqueleto.Experimental.entityVal validPathEntity))
          $ error "queryPathInfo failed to roundtrip"
        Control.Monad.unless (samePath == Just pth)
          $ error "queryPathFromHashPart failed to roundtrip"

        Control.Monad.IO.Class.liftIO $ do
          putStrLn $ "References: "
          print references
          putStrLn $ "Referrers: "
          print referrers
          putStrLn $ "Valid derivers: "
          print validDerivers
          putStrLn $ "Derivation outputs: "
          print outputs

    pure ()