Skip to content

Commit

Permalink
ServiceNow: when looking up a table's schema, include the name of the…
Browse files Browse the repository at this point in the history
… display column
  • Loading branch information
achlipala committed Aug 30, 2023
1 parent 655ff02 commit 0069626
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
6 changes: 5 additions & 1 deletion examples/serviceNowDemo.ur
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ structure A = ServiceNow.ThreeLegged(struct
structure S = ServiceNow.Make(A)

fun table_ name =
cs <- S.Tables.columns name;
{Columns = cs, DisplayColumn = disp} <- S.Tables.columns name;
return <xml><body>
<h1>Columns</h1>

{case disp of
None => <xml></xml>
| Some disp => <xml><p>Display column is: <b>{[disp]}</b>.</p></xml>}

<table>
<tr><th>Name</th> <th>Type</th></tr>
{List.mapX (fn c => <xml>
Expand Down
28 changes: 23 additions & 5 deletions src/ur/serviceNow.ur
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,17 @@ type column = {

type column' = {
Nam : option string,
Typ : option reference
Typ : option reference,
Display : option bool
}
val _ : json column' = json_record_withOptional {} {Nam = "element",
Typ = "internal_type"}
Typ = "internal_type",
Display = "display"}

type full_table = {
Columns : list column,
DisplayColumn : option string
}

functor Make(M : AUTH) = struct
open M
Expand Down Expand Up @@ -120,9 +127,9 @@ functor Make(M : AUTH) = struct
if name = "" then
None
else
return {Nam = name, Typ = typ.Value}) raw)
return {Nam = name, Typ = typ.Value, Display = r.Display}) raw)

fun columns tabl =
fun columnsRaw tabl =
cs <- columnsWithoutInheritance tabl;
t <- get tabl;
case t of
Expand All @@ -135,8 +142,19 @@ functor Make(M : AUTH) = struct
case p of
None => return cs
| Some p =>
cs' <- columns p.Nam;
cs' <- columnsRaw p.Nam;
return (List.append cs cs')

fun columns tabl =
cs <- columnsRaw tabl;
disp <- return (case List.find (fn c => c.Display = Some True) cs of
Some c => Some c.Nam
| None =>
case List.find (fn c => c.Nam = "number" || c.Nam = "name" || c.Nam = "u_number" || c.Nam = "u_name") cs of
Some c => Some c.Nam
| None => None);
return {Columns = List.mp (fn c => c -- #Display) cs,
DisplayColumn = disp}
end

structure Table = struct
Expand Down
7 changes: 6 additions & 1 deletion src/ur/serviceNow.urs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ type column = {
Typ : string
}

type full_table = {
Columns : list column,
DisplayColumn : option string (* name of column to use in summarizing a row of this table, e.g. in a list of several rows somewhere *)
}

functor Make(M : AUTH) : sig
structure Incidents : sig
val list : transaction (list incident)
end

structure Tables : sig
val list : transaction (list tabl)
val columns : string -> transaction (list column)
val columns : string -> transaction full_table
end

structure Table : sig
Expand Down

0 comments on commit 0069626

Please sign in to comment.