-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdata.pro
More file actions
83 lines (61 loc) · 2.17 KB
/
Copy pathdata.pro
File metadata and controls
83 lines (61 loc) · 2.17 KB
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
:- module(data, [
, entity_field/4
, entity_field_nullable/3
, sql_java_type/3
]).
/** <module> describe all data?
Note: We are moving this to enterprise.pro.
Intended usage:
- enterprise web application
*/
% Records.
% match_one(Pat, List, Unmatched)
match_one(Pat, [Head | Tail], Tail) :- Pat = Head.
match_one(Pat, [Head | Tail], [Head | Unmatched]) :- match_one(Pat, Tail, Unmatched).
% match_many(Pats, List, Unmatched)
match_many([], List, Unmatched) :- List = Unmatched.
match_many([Pat | Pats], List, Unmatched) :- true
, match_one(Pat, List, Unmatched_0)
, match_many(Pats, Unmatched_0, Unmatched_1)
, Unmatched_1 = Unmatched
.
/** entity_field(?Entity, ?Name, ?Type, ?Opts).
We assume the existence of a predicate entity/2 somewhere else.
entity(Name, Fields).
- Name is an atom.
- Fields is a list.
Each element of Fields is a list [Field_name, Field_type | Field_options].
- Field_name is an atom.
- Field_type:
- The atom int32 is a Field_type.
- If Length is a nonnegative integer, then the compound varchar(Length) is a Field_type.
- Field_options is a list.
*/
entity_field(Entity, Name, Type, Opts) :- true
, entity(Entity, Fields)
, member([Name, Type | Opts], Fields)
.
entity_field_type(Entity, Name, Type) :- entity_field(Entity, Name, Type, _).
entity_field_opts(Entity, Name, Opts) :- entity_field(Entity, Name, _, Opts).
entity_field_nullable(Entity, Name, Nullable) :- true
, entity_field_opts(Entity, Name, Opts)
, (member(nullable, Opts) -> Nullable = nullable ; Nullable = not_nullable).
% Mapping between SQL type and Java type.
sql_java_type_primitive(S, J) :- member((S, J), [
(int16, short)
, (int32, int)
, (int64, long)
]).
% The part of the relation that is not affected by nullability.
sql_java_type_general(S, J) :- member((S, J), [
(varchar(_), 'java.lang.String')
, (timestamp, 'java.util.Instant')
]).
sql_java_type(S, J, not_nullable) :- false
; sql_java_type_primitive(S, J)
; sql_java_type_general(S, J)
.
sql_java_type(S, J, nullable) :- false
; sql_java_type_primitive(S, P), java_primitive_reference_type(P, J)
; sql_java_type_general(S, J)
.