-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcsv.urs
118 lines (96 loc) · 4.94 KB
/
csv.urs
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
(* Support for parsing comma-separated text files *)
val importTable : fs ::: {Type} -> cs ::: {{Unit}}
-> $(map sql_injectable fs) -> $(map read fs) -> folder fs
-> char (* separator character [conventionally comma] *)
-> sql_table fs cs
-> int (* the number of header lines to skip *)
-> string
-> transaction unit
val parse : fs ::: {Type}
-> $(map sql_injectable fs) -> $(map read fs) -> folder fs
-> char (* separator *)
-> int (* the number of header lines to skip *)
-> string
-> list $fs
val importTableWithHeader : fs ::: {Type} -> fsC ::: {Type} -> cs ::: {{Unit}}
-> [fs ~ fsC]
=> $(map sql_injectable (fs ++ fsC)) -> $(map read fs)
-> folder fs -> folder fsC
-> char (* separator character *)
-> $(map (fn _ => string) fs)
(* for each column, the name of its header in the CSV file *)
-> $fsC
-> sql_table (fs ++ fsC) cs
-> string
-> transaction unit
val splitLine : char (* separator *) -> string -> list string
(* A handy exported helper: split a single line into fields at commas (taking quoting into account). *)
val nextLine : string -> option (string * string)
(* Split at first line of a CSV text, if there is a first line. *)
(* For exporting CSV: *)
val build : fs ::: {Type} -> tab ::: Name
-> folder fs
-> char (* separator *)
-> $(map show fs)
-> $(map (fn _ => string) fs)
-> sql_query [] [] [tab = fs] []
-> transaction string
val buildComputed : fs ::: {Type}
-> folder fs
-> char (* separator *)
-> $(map show fs)
-> $(map (fn _ => string) fs)
-> sql_query [] [] [] fs
-> transaction string
(* Let's expose all that as a UI. *)
functor Import1(M : sig
con fs :: {Type}
con cs :: {{Unit}}
val tab : sql_table fs cs
val injs : $(map sql_injectable fs)
val reads : $(map read fs)
val fl : folder fs
val labels : $(map (fn _ => string) fs)
val skipHeaderLines : int
val mayAccess : transaction bool
val separator : char
(* This additional UI is shown below the import button
* and recreated after every import. *)
type refreshed
val refreshed : Ui.t refreshed
end) : Ui.S0
functor ImportWithHeader1(M : sig
con fs :: {Type}
con fsC :: {Type}
constraint fs ~ fsC
con cs :: {{Unit}}
val tab : sql_table (fs ++ fsC) cs
val title : string
val injs : $(map sql_injectable (fs ++ fsC))
val reads : $(map read fs)
val fl : folder fs
val flC : folder fsC
val headers : $(map (fn _ => string) fs)
(* This record says which CSV-file header corresponds to each field.
* Note that there may be fields of the CSV file that are not used to import data. *)
val constants : $fsC
val mayAccess : transaction bool
val separator : char
type refreshed
val refreshed : Ui.t refreshed
val label : option string (* describes the full we ask to have uploaded *)
val showTextarea : bool (* in addition to normal file upload,
* also allow copying and pasting CSV text? *)
end) : Ui.S0
(* And we can also generate CSV data: *)
functor Generate1(M : sig
con fs :: {Type}
con tab :: Name
val query : sql_query [] [] [tab = fs] []
val fl : folder fs
val shows : $(map show fs)
val labels : $(map (fn _ => string) fs)
val mayAccess : transaction bool
val filename : string (* Tell browsers this is the name of the file being downloaded. *)
val separator : char
end) : Ui.S0