{-# LANGUAGE QuasiQuotes #-}

module Unison.Sqlite.DataVersion
  ( DataVersion (..),
    getDataVersion,
  )
where

import Unison.Prelude
import Unison.Sqlite.Sql (sql)
import Unison.Sqlite.Transaction

newtype DataVersion
  = DataVersion Int64
  deriving stock (DataVersion -> DataVersion -> Bool
(DataVersion -> DataVersion -> Bool)
-> (DataVersion -> DataVersion -> Bool) -> Eq DataVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DataVersion -> DataVersion -> Bool
== :: DataVersion -> DataVersion -> Bool
$c/= :: DataVersion -> DataVersion -> Bool
/= :: DataVersion -> DataVersion -> Bool
Eq)
  deriving newtype (Int -> DataVersion -> ShowS
[DataVersion] -> ShowS
DataVersion -> String
(Int -> DataVersion -> ShowS)
-> (DataVersion -> String)
-> ([DataVersion] -> ShowS)
-> Show DataVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DataVersion -> ShowS
showsPrec :: Int -> DataVersion -> ShowS
$cshow :: DataVersion -> String
show :: DataVersion -> String
$cshowList :: [DataVersion] -> ShowS
showList :: [DataVersion] -> ShowS
Show)

getDataVersion :: Transaction DataVersion
getDataVersion :: Transaction DataVersion
getDataVersion =
  forall a b. Coercible a b => a -> b
forall a b. Coercible a b => a -> b
coerce @(Transaction Int64) (Sql -> Transaction Int64
forall a. (FromField a, HasCallStack) => Sql -> Transaction a
queryOneCol [sql| PRAGMA data_version |])