summaryrefslogtreecommitdiff
path: root/demo/more/orm.ur
blob: 9abc0234283d032d98ed2a2c2c0907601c9af219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
con link = fn t :: Type => unit

con meta = fn col :: Type => {
              Link : link col,
              Inj : sql_injectable col
              }

functor Table(M : sig
                  con cols :: {Type}
                  val cols : $(map meta cols)
                  constraint [Id] ~ cols
                  val folder : folder cols
              end) = struct
    type id = int
    val inj = _
    val id : meta id = {Link = (),
                        Inj = inj}

    sequence s
    table t : ([Id = id] ++ M.cols)

    fun create (r : $M.cols) =
        id <- nextval s;
        dml (insert t ({Id = sql_inject id}
                           ++ map2 [meta] [Top.id] [sql_exp [] [] []]
                           (fn [t ::: Type] (meta : meta t) (v : t) => @sql_inject meta.Inj v)
                           [_] M.folder M.cols r));
        return id
end