-
Notifications
You must be signed in to change notification settings - Fork 1
/
Web.mORMot.OrmTypes.pas
132 lines (100 loc) · 3.75 KB
/
Web.mORMot.OrmTypes.pas
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
unit Web.mORMot.OrmTypes;
{-------------------------------------------------------------------------------
mORMot for pas2js/TMS WebCore.
Port of TSQLRecord and other Orm-related classes from SynCrossPlatformREST.
Adapted from mORMot v1 CrossPlatform units.
See original file for copyright and licence information at:
https://github.com/synopse/mORMot
1. Remove all constructors that involve a dependency on TRest. In mORMot v2 the
TOrm constructors use the IRestOrm interface instead. The initial version for
WebCore will not provide direct access to the ORM.
-------------------------------------------------------------------------------}
interface
uses
Classes,
Web.mORMot.Types,
Web.mORMot.Utils;
type
TOrm = class; // TSQLRecord
TORMModel = class; // TSQLModel
TOrmClass = class of TOrm;
TOrmClassDynArray = array of TOrmClass;
/// abstract ORM class to access remote tables
// - in comparison to mORMot.pas TSQLRecord published fields, dynamic arrays
// shall be defined as JSValue (since SynCrossPlatformJSON do not serialize)
// - inherit from TPersistent to have RTTI for its published properties
// (SmartMobileStudio does not allow {$M+} in the source)
TOrm = class(TPersistent)
protected
fID: TID;
fInternalState: cardinal;
public
/// this constructor initializes the record
constructor Create; overload; virtual;
/// internal state counter of the mORMot server at last access time
// - can be used to check if retrieved data may be out of date
property InternalState: cardinal read fInternalState;
published
/// stores the record's primary key
property ID: TID read fID write fID;
end;
TORMModel = class
protected
fRoot: string;
//fInfo: TOrmModelInfoDynArray;
public
/// initialize the Database Model
// - set the Tables to be associated with this Model, as TSQLRecord classes
// - set the optional Root URI path of this Model - default is 'root'
constructor Create(const Tables: array of TORMClass;
const aRoot: string ='root');
(*
/// register a new Table class to this Model
procedure Add(Table: TSQLRecordClass);
{$ifndef ISSMS}
/// finalize the memory used
destructor Destroy; override;
{$endif}
/// get index of aTable in Tables[], returns -1 if not found
function GetTableIndex(aTable: TSQLRecordClass): integer; overload;
/// get index of aTable in Tables[], returns -1 if not found
function GetTableIndex(const aTableName: string): integer; overload;
/// get index of aTable in Tables[], raise an ERestException if not found
function GetTableIndexExisting(aTable: TSQLRecordClass): integer;
/// get the RTTI information for the specified class or raise an ERestException
function InfoExisting(aTable: TSQLRecordClass): TSQLModelInfo;
/// the RTTI information for each class
property Info: TSQLModelInfoDynArray read fInfo;
*)
/// the Root URI path of this Database Model
property Root: string read fRoot;
end;
implementation
{ TOrm }
//------------------------------------------------------------------------------
constructor TOrm.Create;
begin
// -- Leave empty for now.
end;
{ TORMModel }
//------------------------------------------------------------------------------
constructor TORMModel.Create(const Tables: array of TORMClass;
const aRoot: string);
//var t: integer;
begin
(*
{$ifdef ISSMS}
for t := 0 to high(Tables) do
fInfo.Add(TSQLModelInfo.CreateFromRTTI(Tables[t]));
{$else}
SetLength(fInfo, length(Tables));
for t := 0 to high(fInfo) do
fInfo[t] := TSQLModelInfo.CreateFromRTTI(Tables[t]);
{$endif}
*)
if aRoot<>'' then
if aRoot[length(aRoot)] = '/' then
fRoot := copy(aRoot, 1, Length(aRoot) - 1) else
fRoot := aRoot;
end;
end.