Commit e66d38db authored by MrMan's avatar MrMan

Type-level database paradigm polymorphism

parent 3e229344
......@@ -278,23 +278,28 @@ newtype TableName = TN { getTableName :: DT.Text } deriving (Eq, Show, Read)
newtype SQLColumnNames = SQLCN { getColumnNames :: [DT.Text] } deriving (Eq, Show, Read)
newtype SQLValueGetters entity = SQLVG { getValueGetters :: [entity -> Maybe SQLData] }
class SQLEntityStore store => SQLInsertable store entity where
tableName :: TableName
columnNames :: SQLColumnNames
columnValues :: SQLValueGetters entity
-- | Alias for the kind of types with f bounded type polymorphism applied to one or more fields
-- ex. data T f = T { name :: f DT.Text }, where f might be a type like `Maybe a` or `Identity a`
type FBounded = (Type -> Type) -> Type
data DBParadigm = SQL
| DocumentStore
deriving (Eq, Show, Read)
class Insertable (paradigm :: DBParadigm) entity where
getInsertInfo :: EntityInsertInfo paradigm
data EntityInsertInfo (p :: DBParadigm) where
EII_SQL :: TableName -> SQLColumnNames -> SQLValueGetters entity -> EntityInsertInfo 'SQL
EII_DocumentStore :: TableName -> EntityInsertInfo 'DocumentStore
-- | Generalized typeclass for entity storage.
class SQLEntityStore store where
-- | Create an entity
class EntityStore (paradigm :: DBParadigm) store where
create :: forall (entity :: FBounded).
SQLInsertable store (Complete entity)
=> store
-> Validated (Complete entity)
-> IO (Either EntityStoreError (Complete entity))
Insertable paradigm entity =>
store
-> Validated (Complete entity)
-> IO (Either EntityStoreError (Complete entity))
-- | Get an entity by ID
get :: forall entity. store -> Complete entity -> IO (Either EntityStoreError (Complete entity))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment