@@ -11,6 +11,7 @@ type SsdtSchema = {
11
11
Relationships: SsdtRelationship list
12
12
Descriptions: SsdtDescriptionItem list
13
13
UserDefinedDataTypes: SsdtUserDefinedDataType
14
+ Functions: SsdtStoredProc list
14
15
}
15
16
and SsdtTable = {
16
17
FullName: string
@@ -377,6 +378,38 @@ let parseXml(xml: string) =
377
378
Name = parts.[ 1 ]
378
379
Parameters = parameters |> Seq.toList }
379
380
381
+ let parseFunctions ( funElement : XmlNode ) =
382
+ let fullName = funElement |> att " Name" |> RegexParsers.splitFullName |> fun n -> String.Join( " ." , n) |> fun n -> n.ToUpper()
383
+ let parameters =
384
+ let paramsNode = funElement |> nodes " x:Relationship" |> Seq.tryFind ( fun r -> r |> att " Name" = " Parameters" )
385
+ match paramsNode with
386
+ | Some e ->
387
+ e
388
+ |> nodes " x:Entry"
389
+ |> Seq.map ( fun entry ->
390
+ let el = entry |> node " x:Element"
391
+ let parameterName = el |> att " Name"
392
+ let isOutput =
393
+ match el |> nodes " x:Property" |> Seq.tryFind ( fun p -> p |> att " Name" = " IsOutput" ) with
394
+ | Some p when p |> att " Value" = " True" -> true
395
+ | _ -> false
396
+ let dataType =
397
+ el
398
+ |> node " x:Relationship/x:Entry/x:Element/x:Relationship/x:Entry/x:References"
399
+ |> att " Name"
400
+ { FullName = parameterName
401
+ Name = parameterName |> RegexParsers.splitFullName |> Array.last
402
+ DataType = dataType |> removeBrackets
403
+ Length = ValueNone
404
+ IsOutput = isOutput })
405
+ | None -> Seq.empty
406
+
407
+ let parts = fullName |> RegexParsers.splitFullName
408
+ { FullName = fullName
409
+ Schema = parts.[ 0 ]
410
+ Name = parts.[ 1 ]
411
+ Parameters = parameters |> Seq.toList }
412
+
380
413
let parseDescription ( extElement : XmlNode ) =
381
414
let fullName = extElement |> att " Name"
382
415
let parts = fullName |> RegexParsers.splitFullName
@@ -412,6 +445,16 @@ let parseXml(xml: string) =
412
445
|> Seq.map parseUserDefinedDataType
413
446
|> Map.ofSeq
414
447
448
+ let functions =
449
+ let filterPredicate elem =
450
+ ( att " Type" elem) = " SqlScalarFunction"
451
+ || ( att " Type" elem) = " SqlInlineTableValuedFunction"
452
+ model
453
+ |> nodes " x:Element"
454
+ |> Seq.filter filterPredicate
455
+ |> Seq.map parseFunctions
456
+ |> Seq.toList
457
+
415
458
let storedProcs =
416
459
model
417
460
|> nodes " x:Element"
@@ -492,4 +535,5 @@ let parseXml(xml: string) =
492
535
TryGetTableByName = fun nm -> tablesAndViews |> ( List.tryFind ( fun t -> t.Name = nm) >> function Some x -> ValueSome x | None -> ValueNone)
493
536
Relationships = relationships
494
537
Descriptions = descriptions
495
- UserDefinedDataTypes = userDefinedDataTypes } : SsdtSchema
538
+ UserDefinedDataTypes = userDefinedDataTypes
539
+ Functions = functions } : SsdtSchema
0 commit comments