File: dmrestbridge.pp

package info (click to toggle)
lazarus 2.2.6%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 219,980 kB
  • sloc: pascal: 1,944,919; xml: 357,634; makefile: 270,608; cpp: 57,115; sh: 3,249; java: 609; perl: 297; sql: 222; ansic: 137
file content (132 lines) | stat: -rw-r--r-- 4,080 bytes parent folder | download | duplicates (3)
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 dmRestBridge;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, sqldbrestbridge, sqldbrestschema, pqconnection, ibconnection, sqldbrestauth,db,
  // Register formats
  sqldbrestcsv ,sqldbrestxml, sqldbrestcds, sqldbrestado;

type

  { TRestDataModule }

  TRestDataModule = class(TDataModule)
    AuthBasic: TRestBasicAuthenticator;
    Dispatcher: TSQLDBRestDispatcher;
    ExpensesSchema: TSQLDBRestSchema;
    BPProjects: TSQLDBRestBusinessProcessor;
    procedure DataModuleCreate(Sender: TObject);
    procedure DispatcherLog(Sender: TObject; aType: TRestDispatcherLogOption;
      const aMessage: UTF8String);
    procedure DoAllowedOperations(aSender: TObject; aContext: TBaseRestContext; var aOperations: TRestOperations);
    procedure DoAllowedRecord(aSender: TObject; aContext: TBaseRestContext; aDataSet: TDataset; var allowRecord: Boolean);
    procedure DoAllowResource(aSender: TObject; aContext: TBaseRestContext; var allowResource: Boolean);
    procedure DoCheckParams(aSender: TObject; aContext: TBaseRestContext; aOperation: TRestOperation; Params: TParams);
    procedure DoGetDataset(aSender: TObject; aContext: TBaseRestContext;  aFieldList: TRestFieldPairArray; aOrderBy: TRestFieldOrderPairArray;    aLimit, aOffset: Int64; var aDataset: TDataset);
  private
  public

  end;

var
  RestDataModule: TRestDataModule;

implementation

{$R *.lfm}

uses sqldbrestini, custapp;

{ TRestDataModule }

procedure TRestDataModule.DataModuleCreate(Sender: TObject);

Var
  D,Cfg : String;

begin
  D:=ExtractFilePath(ParamStr(0));
  if CustomApplication.Hasoption('c','connection') then
    Cfg:=CustomApplication.GetoptionValue('c','connection')
  else
    Cfg:=D+'connection.ini';
  if FileExists(Cfg) then
    Dispatcher.Connections[0].LoadFromIniFile('connection.ini');
  if CustomApplication.Hasoption('c','connection') then
    Cfg:=CustomApplication.GetoptionValue('i','ini')
  else
    Cfg:=D+'server.ini';
  if FileExists(Cfg) then
    Dispatcher.LoadFromFile('server.ini',[]);
  // Manual config
  if CustomApplication.Hasoption('b','basedir') then
    Dispatcher.BasePath:=CustomApplication.GetoptionValue('b','basedir');
  if CustomApplication.HasOption('q','quiet') then
    begin
    Dispatcher.OnLog:=Nil;
    Dispatcher.LogOptions:=[];
    end
  else if CustomApplication.HasOption('v','verbose') then
    Dispatcher.LogOptions:=Dispatcher.LogOptions+[rloSQL];
  // Activate
  Dispatcher.Active:=True;
end;

procedure TRestDataModule.DispatcherLog(Sender: TObject;
  aType: TRestDispatcherLogOption; const aMessage: UTF8String);
begin
  if isConsole then
    Writeln('['+LogNames[aType]+'] '+aMessage)
  else if Assigned(CustomApplication) then
    CustomApplication.Log(etInfo,'['+LogNames[aType]+'] '+aMessage);
end;

procedure TRestDataModule.DoAllowedOperations(aSender: TObject;
  aContext: TBaseRestContext; var aOperations: TRestOperations);
begin
  if IsConsole then
    Writeln('[Debug] AllowedOperations for ',aContext.UserID);
end;

procedure TRestDataModule.DoAllowedRecord(aSender: TObject;
  aContext: TBaseRestContext; aDataSet: TDataset; var allowRecord: Boolean);
begin
  if IsConsole then
    Writeln('[Debug] AllowedRecord for ',aContext.UserID);
  AllowRecord:=True;
end;

procedure TRestDataModule.DoAllowResource(aSender: TObject;
  aContext: TBaseRestContext; var allowResource: Boolean);
begin
  if IsConsole then
    Writeln('[Debug]  AllowedResource for ',aContext.UserID);
end;

procedure TRestDataModule.DoCheckParams(aSender: TObject;
  aContext: TBaseRestContext; aOperation: TRestOperation; Params: TParams);

Var
  P : TParam;
begin
  if IsConsole then
    begin
    Writeln('CheckParams for ',aContext.UserID,', aOperation : ',aOperation);
    For P in Params do
      Writeln('Param ',P.Name,' : ',P.AsString);
    end;
end;

procedure TRestDataModule.DoGetDataset(aSender: TObject;
  aContext: TBaseRestContext; aFieldList: TRestFieldPairArray;
  aOrderBy: TRestFieldOrderPairArray; aLimit, aOffset: Int64;
  var aDataset: TDataset);
begin
  Writeln('DoGetDataset for ',aContext.UserID);
end;

end.