persistent-audit-0.1.0.2: Parses a Persist Model file and produces Audit Models

Safe HaskellNone
LanguageHaskell2010

Database.Persist.Audit.Generator

Synopsis

Documentation

data AuditGeneratorSettings Source #

Five options for generating Audit Models and ToAudit Instances.

Constructors

AuditGeneratorSettings 

Fields

data ForeignKeyType Source #

All foreign keys are kept in the audit models but derefenced so the original models | can be deleted without affecting the audit models. This is a work around in case the | original models and the audit models are stored in different databases. | Persist cannot handle keys across SQL and Mongo.

Constructors

OriginalKey

Default setting. Link the ids as the original type with a "noreference" tag.

MongoKeyInSQL

Store Mongo Key as a ByteString in SQL.

SQLKeyInMongo

Store SQL Key as an Int64 in Mongo.

defaultSettings :: AuditGeneratorSettings Source #

Settings that the author assumed would be most common.

generateAuditModels :: AuditGeneratorSettings -> PersistModelFile -> Text Source #

Convert a list of TopLevel to a list of Audit Models in Text.

printForeignKey :: ForeignKeyType -> Text -> (Text, Text) Source #

Select the correct type from Audit Model to original Model. Used for cross database. | fst is the type and snd is the original type in comment for if using cross database.

printTopLevel :: AuditGeneratorSettings -> PersistModelFilePiece -> Text Source #

Convert a TopLevel to an Audit Model, white space or comment in Text.

printEntityChild :: AuditGeneratorSettings -> EntityChild -> Text Source #

Convert an EntityChild to a piece of an Audit Model in Text. | It does not generate anything for EntityUnique, EntityPrimary or EntityForeign | because Audits do not need to be unique, they will have an automatically produced Key | and should not have any foreign keys connecting back to the original model.

generateToAuditInstances :: AuditGeneratorSettings -> PersistModelFile -> Text Source #

Convert a list of TopLevel to a to a list of ToAudit in Text.

printToAuditInstance :: AuditGeneratorSettings -> PersistModelFilePiece -> Text Source #

Convert TopLevel to an instance of ToAudit in Text.

printIfForeignKeyAlternate :: ForeignKeyType -> Text -> Text Source #

Select the correct function for handling foreign keys.

printEntityFieldTypeFunctionConnector :: EntityFieldType -> (Bool, Text) Source #

If fst True then prefix the function with fmap

stringEndsInId :: String -> Bool Source #

Return true if the last two characters are Id.

firstLetterToUpperCase :: String -> String Source #

Convert the first letter of a String to the corresponding uppercase letter.

firstLetterToLowerCase :: String -> String Source #

Convert the first letter of a String to the corresponsing lowercase letter.