summaryrefslogtreecommitdiff
path: root/demo/more/orm.urs
blob: b173d2034bde3e869d4c457fea0d965bee2e4dba (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
con link :: (Type * Type) -> Type
val noParent : t ::: Type -> link (t, unit)

con meta = fn col_parent :: (Type * Type) => {
	      Link : link col_parent,
	      Inj : sql_injectable col_parent.1
	      }

val local : t :: Type -> sql_injectable t -> meta (t, unit)

functor Table(M : sig
		  con cols :: {(Type * Type)}
		  val cols : $(map meta cols)
		  constraint [Id] ~ cols
		  val folder : folder cols
	      end) : sig
    type id
    type row' = $(map fst M.cols)
    type row = $([Id = id] ++ map fst M.cols)

    val inj : sql_injectable id
    val id : meta (id, row)

    val create : row' -> transaction row
    val delete : row -> transaction unit
    val save : row -> transaction unit
    val lookup : id -> transaction (option row)
    val list : transaction (list row)

    con col :: Type -> Type
    val idCol : col id
    val cols : $(map (fn col_parent :: (Type * Type) =>
                         {Col : col col_parent.1,
                          Parent : row -> transaction (option col_parent.2)}) M.cols)

    type filter
    val find : filter -> transaction (option row)
    val search : filter -> transaction (list row)

    val eq : t ::: Type -> col t -> t -> filter
    val ne : t ::: Type -> col t -> t -> filter
    val lt : t ::: Type -> col t -> t -> filter
    val le : t ::: Type -> col t -> t -> filter
    val gt : t ::: Type -> col t -> t -> filter
    val ge : t ::: Type -> col t -> t -> filter

    val _and : filter -> filter -> filter
    val or : filter -> filter -> filter
end