2021-03-15 19:10:01 +03:00
|
|
|
module Psl.Common.ModelTest where
|
|
|
|
|
2021-11-11 15:26:20 +03:00
|
|
|
import qualified Wasp.Psl.Ast.Model as AST
|
2021-03-15 19:10:01 +03:00
|
|
|
|
|
|
|
-- | Corresponds to sampleBodyAst below.
|
|
|
|
sampleBodySchema :: String
|
|
|
|
sampleBodySchema =
|
|
|
|
unlines
|
2021-04-28 18:36:00 +03:00
|
|
|
[ " id Int @id @default(value: autoincrement())",
|
2022-08-24 17:32:46 +03:00
|
|
|
" username String? @db.VarChar(200)",
|
2021-04-28 18:36:00 +03:00
|
|
|
" posts Post[] @relation(\"UserPosts\", references: [id]) @customattr",
|
|
|
|
" weirdType Unsupported(\"weird\")",
|
|
|
|
"",
|
2022-08-24 17:32:46 +03:00
|
|
|
" @@someattr([id, username], 2 + 4, [posts])"
|
2021-04-28 18:36:00 +03:00
|
|
|
]
|
2021-03-15 19:10:01 +03:00
|
|
|
|
|
|
|
-- | Corresponds to sampleBodySchema above.
|
|
|
|
sampleBodyAst :: AST.Body
|
|
|
|
sampleBodyAst =
|
|
|
|
AST.Body
|
2021-04-28 18:36:00 +03:00
|
|
|
[ AST.ElementField
|
|
|
|
( AST.Field
|
|
|
|
{ AST._name = "id",
|
|
|
|
AST._type = AST.Int,
|
|
|
|
AST._typeModifiers = [],
|
|
|
|
AST._attrs =
|
|
|
|
[ AST.Attribute
|
|
|
|
{ AST._attrName = "id",
|
|
|
|
AST._attrArgs = []
|
|
|
|
},
|
|
|
|
AST.Attribute
|
|
|
|
{ AST._attrName = "default",
|
|
|
|
AST._attrArgs =
|
|
|
|
[ AST.AttrArgNamed "value" (AST.AttrArgFunc "autoincrement")
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
),
|
|
|
|
AST.ElementField
|
|
|
|
( AST.Field
|
2022-08-24 17:32:46 +03:00
|
|
|
{ AST._name = "username",
|
2021-04-28 18:36:00 +03:00
|
|
|
AST._type = AST.String,
|
|
|
|
AST._typeModifiers = [AST.Optional],
|
|
|
|
AST._attrs =
|
|
|
|
[ AST.Attribute
|
|
|
|
{ AST._attrName = "db.VarChar",
|
|
|
|
AST._attrArgs =
|
|
|
|
[ AST.AttrArgUnnamed (AST.AttrArgNumber "200")
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
),
|
|
|
|
AST.ElementField
|
|
|
|
( AST.Field
|
|
|
|
{ AST._name = "posts",
|
|
|
|
AST._type = AST.UserType "Post",
|
|
|
|
AST._typeModifiers = [AST.List],
|
|
|
|
AST._attrs =
|
|
|
|
[ AST.Attribute
|
|
|
|
{ AST._attrName = "relation",
|
|
|
|
AST._attrArgs =
|
|
|
|
[ AST.AttrArgUnnamed (AST.AttrArgString "UserPosts"),
|
|
|
|
AST.AttrArgNamed "references" (AST.AttrArgFieldRefList ["id"])
|
|
|
|
]
|
|
|
|
},
|
|
|
|
AST.Attribute
|
|
|
|
{ AST._attrName = "customattr",
|
|
|
|
AST._attrArgs = []
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
),
|
|
|
|
AST.ElementField
|
|
|
|
( AST.Field
|
|
|
|
{ AST._name = "weirdType",
|
|
|
|
AST._type = AST.Unsupported "weird",
|
|
|
|
AST._typeModifiers = [],
|
|
|
|
AST._attrs = []
|
|
|
|
}
|
|
|
|
),
|
|
|
|
AST.ElementBlockAttribute
|
|
|
|
( AST.Attribute
|
|
|
|
{ AST._attrName = "someattr",
|
|
|
|
AST._attrArgs =
|
2022-08-24 17:32:46 +03:00
|
|
|
[ AST.AttrArgUnnamed (AST.AttrArgFieldRefList ["id", "username"]),
|
2021-04-28 18:36:00 +03:00
|
|
|
AST.AttrArgUnnamed (AST.AttrArgUnknown "2 + 4"),
|
|
|
|
AST.AttrArgUnnamed (AST.AttrArgFieldRefList ["posts"])
|
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
]
|