-
Notifications
You must be signed in to change notification settings - Fork 4
/
DataServer.pas
75 lines (56 loc) · 1.74 KB
/
DataServer.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
unit dataserver;
{$I Synopse.inc}
interface
uses
{$ifdef Darwin}
Unix,
{$endif}
SysUtils, Classes,
SynCommons, mORMot,
mORMotSQLite3, SynSQLite3Static,
ODataRestServer,
SampleData;
type
TmORMotODataServer = class(TSQLRestServerDB)
private
Model:TSQLModel;
protected
fRootFolder: TFileName;
fDataFolder: TFileName;
fAppFolder: TFileName;
public
Server: TODataHttpServer;
constructor Create(const aRootFolder: TFileName=''; const aRootURI: RawUTF8='root'); reintroduce;
destructor Destroy; override;
end;
implementation
uses
SynLog;
constructor TmORMotODataServer.Create(const aRootFolder: TFileName; const aRootURI: RawUTF8);
begin
fRootFolder := EnsureDirectoryExists(ExpandFileName(aRootFolder),true);
if fRootFolder=PathDelim then fRootFolder:='.'+fRootFolder;
//fDataFolder := EnsureDirectoryExists(fRootFolder+'data'+PathDelim,true);
//if fDataFolder=PathDelim then fDataFolder:='.'+fDataFolder;
fAppFolder := EnsureDirectoryExists(ExpandFileName(''),true);
if fAppFolder=PathDelim then fAppFolder:='.'+fAppFolder;
with TSQLLog.Family do begin
Level := [sllError, sllDebug, sllSQL, sllCache, sllResult, sllDB, sllHTTP, sllClient, sllServer];
LevelStackTrace:=[sllNone];
DestinationPath := 'log'+PathDelim;
if not FileExists(DestinationPath) then CreateDir(DestinationPath);
//NoFile := true;
//EchoCustom := OnLogEvent;
EchoToConsole := LOG_VERBOSE; // log all events to the console
end;
Model := CreateSampleModel;
inherited Create(Model,fRootFolder+'data.db3',False);
CreateMissingTables;
Server := TODataHttpServer.Create(PORT,Self);
end;
destructor TmORMotODataServer.Destroy;
begin
Server.Free;
if Assigned(Model) then Model.Free;
end;
end.