@@ -19,6 +19,7 @@ module Database.Beam.Schema.Tables
19
19
, DatabaseEntityDescriptor (.. )
20
20
, DatabaseEntity (.. ), TableEntity , ViewEntity , DomainTypeEntity
21
21
, dbEntityDescriptor
22
+ , dbName , dbSchema , dbTableFields
22
23
, DatabaseModification , EntityModification (.. )
23
24
, FieldModification (.. )
24
25
, dbModification , tableModification , withDbModification
@@ -96,7 +97,6 @@ import GHC.TypeLits
96
97
import GHC.Types
97
98
98
99
import Lens.Micro hiding (to )
99
- import qualified Lens.Micro as Lens
100
100
101
101
-- | Allows introspection into database types.
102
102
--
@@ -311,7 +311,7 @@ class RenamableWithRule (FieldRenamer (DatabaseEntityDescriptor be entityType))
311
311
type DatabaseEntityRegularRequirements be entityType :: Constraint
312
312
313
313
dbEntityName :: Lens' (DatabaseEntityDescriptor be entityType ) Text
314
- dbEntitySchema :: Traversal ' (DatabaseEntityDescriptor be entityType ) (Maybe Text )
314
+ dbEntitySchema :: Lens ' (DatabaseEntityDescriptor be entityType ) (Maybe Text )
315
315
316
316
dbEntityAuto :: DatabaseEntityDefaultRequirements be entityType =>
317
317
Text -> DatabaseEntityDescriptor be entityType
@@ -387,7 +387,7 @@ instance IsDatabaseEntity be (DomainTypeEntity ty) where
387
387
type DatabaseEntityRegularRequirements be (DomainTypeEntity ty ) = ()
388
388
389
389
dbEntityName f (DatabaseDomainType s t ) = DatabaseDomainType s <$> f t
390
- dbEntitySchema f (DatabaseDomainType s t ) = DatabaseDomainType <$> f s <*> pure t
390
+ dbEntitySchema f (DatabaseDomainType s t ) = ( \ s' -> DatabaseDomainType s' t ) <$> f s
391
391
dbEntityAuto = DatabaseDomainType Nothing
392
392
393
393
-- | Represents a meta-description of a particular entityType. Mostly, a wrapper
@@ -398,8 +398,21 @@ data DatabaseEntity be (db :: (Type -> Type) -> Type) entityType where
398
398
IsDatabaseEntity be entityType =>
399
399
DatabaseEntityDescriptor be entityType -> DatabaseEntity be db entityType
400
400
401
- dbEntityDescriptor :: SimpleGetter (DatabaseEntity be db entityType ) (DatabaseEntityDescriptor be entityType )
402
- dbEntityDescriptor = Lens. to (\ (DatabaseEntity e) -> e)
401
+ dbEntityDescriptor :: Lens' (DatabaseEntity be db entityType ) (DatabaseEntityDescriptor be entityType )
402
+ dbEntityDescriptor f (DatabaseEntity d) = DatabaseEntity <$> f d
403
+
404
+ dbName :: IsDatabaseEntity be entityType => Lens' (DatabaseEntity be db entityType ) Text
405
+ dbName = dbEntityDescriptor . dbEntityName
406
+
407
+ dbSchema :: IsDatabaseEntity be entityType => Lens' (DatabaseEntity be db entityType ) (Maybe Text )
408
+ dbSchema = dbEntityDescriptor . dbEntitySchema
409
+
410
+ dbTableFields :: Lens' (DatabaseEntity be db (TableEntity table )) (TableSettings table )
411
+ dbTableFields = dbEntityDescriptor . (\ f DatabaseTable { dbTableSchema = sch
412
+ , dbTableOrigName = nm
413
+ , dbTableCurrentName = curNm
414
+ , dbTableSettings = s } ->
415
+ DatabaseTable sch nm curNm <$> f s)
403
416
404
417
-- | When parameterized by this entity tag, a database type will hold
405
418
-- meta-information on the Haskell mappings of database entities. Under the
0 commit comments