Skip to content

Commit d080bda

Browse files
committed
introduce name on entity
1 parent a3291c6 commit d080bda

14 files changed

Lines changed: 47 additions & 25 deletions

File tree

src/Database/SqlServer/Definition/Certificate.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ renderStartDate d = text "START_DATE = '" <> text (filter (/= '-') (show d)) <>
3636

3737
instance Arbitrary Certificate where
3838
arbitrary = do
39-
name <- arbitrary
39+
certName <- arbitrary
4040
afbd <- arbitrary
4141
eDay <- liftM3 fromGregorian (elements [2016..3000]) (choose(1,12)) (choose(1,31))
4242
x <- choose(- 1000,- 1)
@@ -45,7 +45,7 @@ instance Arbitrary Certificate where
4545
ep <- arbitrary
4646
sub <- arbitrary
4747
return Certificate {
48-
certificateName = name
48+
certificateName = certName
4949
, activeForBeginDialog = afbd
5050
, startDate = str
5151
, expiryDate = ex
@@ -54,7 +54,8 @@ instance Arbitrary Certificate where
5454
}
5555

5656
instance Entity Certificate where
57-
toDoc c = text "CREATE CERTIFICATE" <+> renderRegularIdentifier (certificateName c) $+$
57+
name = certificateName
58+
toDoc c = text "CREATE CERTIFICATE" <+> renderName c $+$
5859
renderEncryptionByPassword (encryptPassword c) $+$
5960
hcat (punctuate comma $ filter (/= empty)
6061
[ renderSubject (subject c)

src/Database/SqlServer/Definition/Credential.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ data Credential = CredentialDefintion
4444
derive makeArbitrary ''Credential
4545

4646
instance Entity Credential where
47-
toDoc s = text "CREATE CREDENTIAL" <+> renderRegularIdentifier (credentialName s) <+>
47+
name = credentialName
48+
toDoc s = text "CREATE CREDENTIAL" <+> renderName s <+>
4849
text "WITH IDENTITY =" <+> quotes (renderIdentity (identity s)) <+>
4950
maybe empty renderSecret (secret s) $+$
5051
text "GO"

src/Database/SqlServer/Definition/Database.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ data MasterKey = MasterKey
2828

2929
derive makeArbitrary ''MasterKey
3030

31-
instance Entity MasterKey where
32-
toDoc MasterKey = text "CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'weKKjwehg252t!!'" $+$
33-
text "GO"
31+
renderMasterKey :: MasterKey -> Doc
32+
renderMasterKey _ = text "CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'weKKjwehg252t!!'"
33+
$+$ text "GO"
3434

3535
data DatabaseDefinition = DatabaseDefinition
3636
{
@@ -60,7 +60,7 @@ renderDatabaseDefinition dd = text "USE master" $+$
6060
text "CREATE DATABASE" <+> dbName $+$
6161
text "GO" $+$
6262
text "USE" <+> dbName $+$
63-
toDoc (masterKey dd) $+$
63+
renderMasterKey (masterKey dd) $+$
6464
renderNamedEntities (tables dd) $+$
6565
renderNamedEntities (sequences dd) $+$
6666
renderNamedEntities (procedures dd) $+$
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
module Database.SqlServer.Definition.Entity
22
(
33
Entity,
4-
toDoc
4+
toDoc,
5+
name,
6+
renderName
57
) where
68

9+
import Database.SqlServer.Definition.Identifier
10+
711
import Text.PrettyPrint
812

913
class Entity a where
1014
toDoc :: a -> Doc
15+
name :: a -> RegularIdentifier
16+
renderName :: a -> Doc
17+
renderName = renderRegularIdentifier . name
1118

1219

src/Database/SqlServer/Definition/FullTextCatalog.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ renderOptions True = text "WITH ACCENT_SENSITIVITY = ON"
3232
renderOptions False = text "WITH ACCENT_SENSITIVITY = OFF"
3333

3434
instance Entity FullTextCatalog where
35+
name = catalogName
3536
toDoc ftc = text "CREATE FULLTEXT CATALOG" <+>
36-
renderRegularIdentifier (catalogName ftc) $+$
37+
renderName ftc $+$
3738
maybe empty renderFileGroup (filegroup ftc) $+$
3839
maybe empty renderOptions (accentSensitive ftc) $+$
3940
if asDefault ftc then text "AS DEFAULT" else empty $+$

src/Database/SqlServer/Definition/FullTextStopList.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ instance Arbitrary FullTextStopList where
2323
return (FullTextStopList x y)
2424

2525
instance Entity FullTextStopList where
26+
name = stoplistName
2627
toDoc f = maybe empty toDoc (join (sourceStopList f)) $+$
2728
text "CREATE FULLTEXT STOPLIST" <+>
28-
renderRegularIdentifier (stoplistName f) <+>
29+
renderName f <+>
2930
maybe (text ";") (\q -> text "FROM" <+>
3031
maybe (text "SYSTEM STOPLIST;\n") (\x -> renderRegularIdentifier (stoplistName x) <> text ";\n") q <>
3132
text "GO\n") (sourceStopList f)

src/Database/SqlServer/Definition/Function.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ data Function = ScalarFunctionC ScalarFunction
9494
derive makeArbitrary ''Function
9595

9696
instance Entity Function where
97-
toDoc (ScalarFunctionC f) = text "CREATE FUNCTION" <+> renderRegularIdentifier (scalarFunctionName f) <+>
97+
name (ScalarFunctionC f) = scalarFunctionName f
98+
toDoc fn@(ScalarFunctionC f) = text "CREATE FUNCTION" <+> renderName fn <+>
9899
parens (hcat (punctuate comma (map renderParameter (parameters f)))) $+$
99100
text "RETURNS" <+> renderReturnType (returnType f) $+$
100101
renderFunctionOptions (functionOption f) $+$

src/Database/SqlServer/Definition/Login.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ renderMustChange False = empty
2828
renderMustChange True = text "MUST_CHANGE" <> comma <> text "CHECK_EXPIRATION=ON"
2929

3030
instance Entity Login where
31-
toDoc a = text "CREATE LOGIN" <+> renderRegularIdentifier (loginName a) $+$
31+
name = loginName
32+
toDoc a = text "CREATE LOGIN" <+> renderName a $+$
3233
renderPassword (password a) <+> renderMustChange (mustChange a)
3334

3435

src/Database/SqlServer/Definition/MessageType.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Database.SqlServer.Definition.MessageType
88
) where
99

1010
import Database.SqlServer.Definition.Identifier hiding (unwrap)
11-
import Database.SqlServer.Definition.User (User,Role,roleName,renderUserName)
11+
import Database.SqlServer.Definition.User (User,Role)
1212
import Database.SqlServer.Definition.Entity
1313

1414
import Test.QuickCheck
@@ -36,17 +36,18 @@ renderPreRequisites (Left x) = toDoc x $+$ text "GO"
3636
renderPreRequisites (Right x) = toDoc x $+$ text "GO"
3737

3838
renderAuthorization :: Either User Role -> Doc
39-
renderAuthorization (Left x) = text "AUTHORIZATION" <+> renderUserName x
40-
renderAuthorization (Right x) = text "AUTHORIZATION" <+> renderRegularIdentifier (roleName x)
39+
renderAuthorization (Left x) = text "AUTHORIZATION" <+> renderName x
40+
renderAuthorization (Right x) = text "AUTHORIZATION" <+> renderName x
4141

4242
renderValidation :: Validation -> Doc
4343
renderValidation None = text "VALIDATION = NONE"
4444
renderValidation Empty = text "VALIDATION = EMPTY"
4545
renderValidation WellFormedXml = text "VALIDATION = WELL_FORMED_XML"
4646

4747
instance Entity MessageType where
48+
name = messageTypeName
4849
toDoc m = maybe empty renderPreRequisites (authorization m) $+$
49-
text "CREATE MESSAGE TYPE" <+> renderRegularIdentifier (messageTypeName m) $+$
50+
text "CREATE MESSAGE TYPE" <+> renderName m $+$
5051
maybe empty renderAuthorization (authorization m) $+$
5152
maybe empty renderValidation (validation m)
5253

src/Database/SqlServer/Definition/Procedure.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ statementBody :: String
4646
statementBody = "select 1\n"
4747

4848
instance Entity Procedure where
49-
toDoc p = text "CREATE PROCEDURE" <+> renderRegularIdentifier (procedureName p) $+$
49+
name = procedureName
50+
toDoc p = text "CREATE PROCEDURE" <+> renderName p $+$
5051
hcat (punctuate comma (map renderParameter (parameters p))) <+> text "AS" $+$
5152
text statementBody $+$
5253
text "GO"

0 commit comments

Comments
 (0)