drasil-database-0.1.1.0: A framework for code and document generation for scientific software - Database SubPackage
Safe HaskellSafe-Inferred
LanguageHaskell2010

Drasil.Database

Description

Re-export database types and functions to simplify external use.

Synopsis

Documentation

data Chunk Source #

A piece of reusable knowledge, with an internal identifier (UID), possibly dependant on other chunks.

Instances

Instances details
HasChunkRefs Chunk Source # 
Instance details

Defined in Drasil.Database.Chunk

Methods

chunkRefs :: Chunk -> Set UID Source #

HasUID Chunk Source # 
Instance details

Defined in Drasil.Database.Chunk

Methods

uid :: Getter Chunk UID Source #

Eq Chunk Source # 
Instance details

Defined in Drasil.Database.Chunk

Methods

(==) :: Chunk -> Chunk -> Bool #

(/=) :: Chunk -> Chunk -> Bool #

type IsChunk a = (HasUID a, HasChunkRefs a, Typeable a) Source #

Constraint for anything that may be considered a valid chunk type.

class HasChunkRefs a where Source #

All chunks should expose what chunks they reference/rely on, so that we can test ChunkDBs to ensure all presupposed chunks are already registered.

Methods

chunkRefs :: a -> Set UID Source #

Instances

Instances details
HasChunkRefs Chunk Source # 
Instance details

Defined in Drasil.Database.Chunk

Methods

chunkRefs :: Chunk -> Set UID Source #

mkChunk :: IsChunk a => a -> Chunk Source #

Create a Chunk, ensuring that Chunks are never placed within Chunks.

unChunk :: Typeable a => Chunk -> Maybe a Source #

Open chunks, casting them to a specific type.

chunkType :: Chunk -> TypeRep Source #

Ask a Chunk for the type of data it codifies.

Core database types and functions.

data ChunkDB Source #

Drasil's knowledge database.

fromList :: IsChunk a => [a] -> ChunkDB Source #

Create a ChunkDB from a list of chunks. This will insert all chunks into the database from the list, from left to right.

registered :: ChunkDB -> [UID] Source #

Query the ChunkDB for all registered chunks (by their UIDs).

typesRegistered :: ChunkDB -> [TypeRep] Source #

Enumerate all types registered in the ChunkDB.

size :: ChunkDB -> Int Source #

Get the number of chunks registered in the ChunkDB.

isRegistered :: UID -> ChunkDB -> Bool Source #

Check if a UID is registered in the ChunkDB.

findUnused :: ChunkDB -> [UID] Source #

Filter the ChunkDB for chunks that are not needed by any other chunks. These are the only chunks that can safely be removed from the database, though we do not include this functionality.

find :: Typeable a => UID -> ChunkDB -> Maybe a Source #

Find a chunk by its UID in the ChunkDB.

findOrErr :: forall a. Typeable a => UID -> ChunkDB -> a Source #

Find a chunk by its UID in the ChunkDB, throwing a hard error if it is not found.

findAll :: forall a. IsChunk a => ChunkDB -> [a] Source #

Find all chunks of a specific type in the ChunkDB.

findAll' :: TypeRep -> ChunkDB -> [UID] Source #

Find all chunks of a specific type in the ChunkDB, returning their UIDs rather than the chunks themselves.

dependants :: UID -> ChunkDB -> Maybe [UID] Source #

Find all chunks that depend on a specific one.

dependantsOrErr :: UID -> ChunkDB -> [UID] Source #

Find all chunks that depend on a specific one, throwing a hard error if the dependency chunk is not found.

findTypeOf :: UID -> ChunkDB -> Maybe TypeRep Source #

Find the type of a chunk by its UID.

insert :: IsChunk a => a -> ChunkDB -> ChunkDB Source #

Insert a chunk into the ChunkDB if it is sensible to do so (i.e., does not depend on itself, is not a ChunkDB, and does not overwrite another chunk).

insertAll :: IsChunk a => [a] -> ChunkDB -> ChunkDB Source #

Insert a list of chunks into a ChunkDB.

Temporary functions

insertAllOutOfOrder11 :: (IsChunk a, IsChunk b, IsChunk c, IsChunk d, IsChunk e, IsChunk f, IsChunk g, IsChunk h, IsChunk i, IsChunk j, IsChunk k) => ChunkDB -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h] -> [i] -> [j] -> [k] -> ChunkDB Source #

Insert 11 lists of unique chunk types into a ChunkDB, assuming the input ChunkDB does not already contain any of the chunks from the chunk lists.

type DumpedChunkDB = Map ChunkType [UID] Source #

A dumped representation of a ChunkDB, mapping chunk types (Strings) to lists of UIDs.

data UID Source #

A UID is a 'unique identifier' for things that we will put into our database of information. We use a newtype wrapper to make sure we are only using UIDs where desired.

Instances

Instances details
ToJSON UID Source # 
Instance details

Defined in Drasil.Database.UID

Methods

toJSON :: UID -> Value

toEncoding :: UID -> Encoding

toJSONList :: [UID] -> Value

toEncodingList :: [UID] -> Encoding

ToJSONKey UID Source # 
Instance details

Defined in Drasil.Database.UID

Methods

toJSONKey :: ToJSONKeyFunction UID

toJSONKeyList :: ToJSONKeyFunction [UID]

Generic UID Source # 
Instance details

Defined in Drasil.Database.UID

Associated Types

type Rep UID :: Type -> Type #

Methods

from :: UID -> Rep UID x #

to :: Rep UID x -> UID #

Show UID Source # 
Instance details

Defined in Drasil.Database.UID

Methods

showsPrec :: Int -> UID -> ShowS #

show :: UID -> String #

showList :: [UID] -> ShowS #

Eq UID Source # 
Instance details

Defined in Drasil.Database.UID

Methods

(==) :: UID -> UID -> Bool #

(/=) :: UID -> UID -> Bool #

Ord UID Source # 
Instance details

Defined in Drasil.Database.UID

Methods

compare :: UID -> UID -> Ordering #

(<) :: UID -> UID -> Bool #

(<=) :: UID -> UID -> Bool #

(>) :: UID -> UID -> Bool #

(>=) :: UID -> UID -> Bool #

max :: UID -> UID -> UID #

min :: UID -> UID -> UID #

type Rep UID Source # 
Instance details

Defined in Drasil.Database.UID

type Rep UID = D1 ('MetaData "UID" "Drasil.Database.UID" "drasil-database-0.1.1.0-5oPj4CLw7PwuDH58oM3Qz" 'False) (C1 ('MetaCons "UID" 'PrefixI 'True) (S1 ('MetaSel ('Just "_namespace") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [String]) :*: S1 ('MetaSel ('Just "_baseName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 String)))

class HasUID c where Source #

The most basic item: having a unique identifier key, here a UID.

Methods

uid :: Getter c UID Source #

Provides a unique id for internal Drasil use.

Instances

Instances details
HasUID Chunk Source # 
Instance details

Defined in Drasil.Database.Chunk

Methods

uid :: Getter Chunk UID Source #

mkUid :: String -> UID Source #

Smart constructor for UIDs from raw Values.

nsUid :: String -> UID -> UID Source #

Nest a UID under a namespace.

(+++) :: HasUID a => a -> String -> UID Source #

Append a suffix to a thing with a UID and get the resulting UID.

(+++.) :: UID -> String -> UID Source #

Append a suffix to a UID.

(+++!) :: (HasUID a, HasUID b) => a -> b -> UID Source #

Merge the UIDs of two chunks through simple concatenation.

showUID :: HasUID a => a -> String Source #

Get something's UID as a Value.

data TypedUIDRef typ Source #

UID references that contain information about the type of data the UID refers to, useful for type-safe dereferencing.

mkRef :: IsChunk t => t -> TypedUIDRef t Source #

Create a TypedUIDRef to a chunk.

typedFind :: IsChunk t => TypedUIDRef t -> ChunkDB -> Maybe t Source #

Find a chunk by its typed UID reference.

typedFindOrErr :: IsChunk t => TypedUIDRef t -> ChunkDB -> t Source #

Find a chunk by its typed UID reference, erroring if not found.