|
15 | 15 | {-# OPTIONS_GHC -Wno-orphans #-} |
16 | 16 |
|
17 | 17 | {-# LANGUAGE TypeOperators #-} |
18 | | -module U.Codebase.Sqlite.Queries where |
| 18 | +module U.Codebase.Sqlite.Queries ( |
| 19 | + -- * Constraint kinds |
| 20 | + DB, Err, |
| 21 | + -- * Error types |
| 22 | + Integrity(..), |
| 23 | + |
| 24 | + -- * text table |
| 25 | + saveText, |
| 26 | + loadText, |
| 27 | + loadTextById, |
| 28 | + |
| 29 | + -- * hash table |
| 30 | + saveHash, |
| 31 | + saveHashHash, |
| 32 | + loadHashId, |
| 33 | + loadHashById, |
| 34 | + loadHashIdByHash, |
| 35 | + expectHashIdByHash, |
| 36 | + saveCausalHash, |
| 37 | + loadCausalHash, |
| 38 | + saveBranchHash, |
| 39 | + |
| 40 | + -- * hash_object table |
| 41 | + saveHashObject, |
| 42 | + hashIdsForObject, |
| 43 | + hashIdWithVersionForObject, |
| 44 | + expectObjectIdForPrimaryHashId, |
| 45 | + expectObjectIdForAnyHashId, |
| 46 | + maybeObjectIdForPrimaryHashId, |
| 47 | + maybeObjectIdForAnyHashId, |
| 48 | + |
| 49 | + -- * object table |
| 50 | + saveObject, |
| 51 | + loadObjectById, |
| 52 | + loadPrimaryHashByObjectId, |
| 53 | + loadObjectWithTypeById, |
| 54 | + loadObjectWithHashIdAndTypeById, |
| 55 | + updateObjectBlob, -- unused |
| 56 | + |
| 57 | + -- * namespace_root table |
| 58 | + loadMaybeNamespaceRoot, |
| 59 | + setNamespaceRoot, |
| 60 | + loadNamespaceRoot, |
| 61 | + |
| 62 | + -- * causals |
| 63 | + -- ** causal table |
| 64 | + saveCausal, |
| 65 | + isCausalHash, |
| 66 | + loadCausalHashIdByCausalHash, |
| 67 | + loadCausalValueHashId, |
| 68 | + loadCausalByCausalHash, |
| 69 | + loadBranchObjectIdByCausalHashId, |
| 70 | + |
| 71 | + -- ** causal_parent table |
| 72 | + saveCausalParents, |
| 73 | + loadCausalParents, |
| 74 | + before, |
| 75 | + lca, |
| 76 | + |
| 77 | + -- * watch table |
| 78 | + saveWatch, |
| 79 | + loadWatch, |
| 80 | + loadWatchesByWatchKind, |
| 81 | + loadWatchKindsByReference, |
| 82 | + clearWatches, |
| 83 | + |
| 84 | + -- * indexes |
| 85 | + -- ** dependents index |
| 86 | + addToDependentsIndex, |
| 87 | + getDependentsForDependency, |
| 88 | + getDependenciesForDependent, |
| 89 | + getDependencyIdsForDependent, |
| 90 | + -- ** type index |
| 91 | + addToTypeIndex, |
| 92 | + getReferentsByType, |
| 93 | + getTypeReferenceForReferent, |
| 94 | + getTypeReferencesForComponent, |
| 95 | + -- ** type mentions index |
| 96 | + addToTypeMentionsIndex, |
| 97 | + getReferentsByTypeMention, |
| 98 | + getTypeMentionsReferencesForComponent, |
| 99 | + |
| 100 | + -- * hash prefix lookup |
| 101 | + objectIdByBase32Prefix, |
| 102 | + namespaceHashIdByBase32Prefix, |
| 103 | + causalHashIdByBase32Prefix, |
| 104 | + |
| 105 | + -- * db misc |
| 106 | + createSchema, |
| 107 | + schemaVersion, |
| 108 | + setFlags, |
| 109 | + |
| 110 | + DataVersion, |
| 111 | + dataVersion, |
| 112 | + |
| 113 | + savepoint, |
| 114 | + release, |
| 115 | + rollbackRelease, |
| 116 | + |
| 117 | + setJournalMode, |
| 118 | + traceConnectionFile, |
| 119 | +) where |
19 | 120 |
|
20 | 121 | import qualified Control.Exception as Exception |
21 | 122 | import Control.Monad (when) |
@@ -118,8 +219,6 @@ data Integrity |
118 | 219 | orError :: Err m => Integrity -> Maybe b -> m b |
119 | 220 | orError e = maybe (throwError e) pure |
120 | 221 |
|
121 | | -type TypeHashReference = Reference' TextId HashId |
122 | | - |
123 | 222 | -- * main squeeze |
124 | 223 | createSchema :: (DB m, MonadUnliftIO m) => m () |
125 | 224 | createSchema = do |
@@ -358,6 +457,8 @@ loadCausalParents h = queryAtoms sql (Only h) where sql = [here| |
358 | 457 | SELECT parent_id FROM causal_parent WHERE causal_id = ? |
359 | 458 | |] |
360 | 459 |
|
| 460 | +-- | The data version will increase if there has been any external |
| 461 | +-- modification to the database since the last observed data version. |
361 | 462 | newtype DataVersion = DataVersion Int |
362 | 463 | deriving (Eq, Ord, Show) |
363 | 464 | deriving FromField via Int |
@@ -714,6 +815,7 @@ queryTrace_ title query m = |
714 | 815 | throwIO e |
715 | 816 | else m |
716 | 817 |
|
| 818 | +-- |print the active database filename |
717 | 819 | traceConnectionFile :: DB m => m () |
718 | 820 | traceConnectionFile = do |
719 | 821 | c <- Reader.reader Connection.underlying |
@@ -769,4 +871,3 @@ instance FromField WatchKind where |
769 | 871 | 0 -> WatchKind.RegularWatch |
770 | 872 | 1 -> WatchKind.TestWatch |
771 | 873 | tag -> error $ "Unknown WatchKind id " ++ show tag |
772 | | - |
|
0 commit comments