exilon / quickorm Goto Github PK
View Code? Open in Web Editor NEWQuick ORM RestServer and RestClient based on mORMot framework
Quick ORM RestServer and RestClient based on mORMot framework
First of all thanks for your effort, making the awsome mormot more easy to be used.
Change the search path of the project from "....\common" to "..\common;" in the client and server project.
To run the sample ORMRestServerDemo without exceptions in delphi 10.3 CE I have to rewrite the line in unit ORMRestServer.dpr:
// RestServer.Security.Groups['Operator'].Table('AGroup').AllowAll.CanDelete := False;
RestServer.Security.Groups['Operator'].Table('AGroup').AllowAll;
RestServer.Security.Groups['Operator'].Table('AGroup').CanDelete := False;
and add the line:
Login := TLogin.Create;
after the line:
User := TAUser.Create;
and install your other librari exilon/QuickLogger wiht delphinus, I think it should be added as a dependency in delphinus and commented in the readme.md.
In the clientmain.pas I've changed
if assigned(User.Login) then begin
meInfo.Lines.Add(Format('%s / %d year(s) / LastLogin: %s',[User.Name,User.Age,DateTimeToStr(User.Login.LastLogin)]));
end
else begin
meInfo.Lines.Add(Format('%s / %d year(s) ',[User.Name,User.Age]));
end;
instead of:
meInfo.Lines.Add(Format('%s / %d year(s) / LastLogin: %s',[User.Name,User.Age,DateTimeToStr(User.Login.LastLogin)]));
In the unit Quick.ORM.RestClient I got several too many arguments in function call when calling spHTTP_Socket, spHTTP_WebSocket, spWebSocketBidir_JSON, spWebSocketBidir_Binary, spWebSocketBidir_BinaryAES, just deleting "False, fHTTPOptions.ProxyName, fHTTPOptions.ProxyPass," like this all compile and run.
// ORM := TSQLHttpClientWebsockets.Create(fHost,IntToStr(fPort), fDataBase.Model, False, fHTTPOptions.ProxyName, fHTTPOptions.ProxyPass, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
ORM := TSQLHttpClientWebsockets.Create(fHost,IntToStr(fPort), fDataBase.Model, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
the function modified is:
function TORMRestClient.Connect : Boolean;
begin
Result := False;
try
if fHTTPOptions.AuthMode in [TAuthMode.amDefault,TAuthMode.amSimple] then fDataBase.IncludedClasses := fDataBase.IncludedClasses + [TORMAuthUser] + [TORMAuthGroup];
fDataBase.Model := TSQLModel.Create(fDataBase.IncludedClasses,fDataBase.aRootURI);
//Protocol initialization
case fHTTPOptions.Protocol of
spHTTP_Socket:
begin
// ORM := TSQLHttpClientWinSock.Create(fHost, IntToStr(fPort), fDataBase.Model, False, fHTTPOptions.ProxyName, fHTTPOptions.ProxyPass, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
ORM := TSQLHttpClientWinSock.Create(fHost, IntToStr(fPort), fDataBase.Model, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
TSQLHttpClientWinSock(ORM).KeepAliveMS := fHTTPOptions.ConnectionTimeout;
end;
spHTTPsys:
begin
ORM := TSQLHttpClientWinHTTP.Create(fHost,IntToStr(fPort), fDataBase.Model, False, fHTTPOptions.ProxyName, fHTTPOptions.ProxyPass, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout,fHTTPOptions.ConnectTimeout);
TSQLHttpClientWinHTTP(ORM).KeepAliveMS := fHTTPOptions.ConnectionTimeout;
TSQLHttpClientWinHTTP(ORM).Compression := [hcSynShaAes];
end;
{$ifdef MSWINDOWS}
spHTTPsys_SSL:
begin
ORM := TSQLHttpClientWinHTTP.Create(fHost,IntToStr(fPort), fDataBase.Model, True, fHTTPOptions.ProxyName, fHTTPOptions.ProxyPass, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
TSQLHttpClientWinHTTP(ORM).KeepAliveMS := fHTTPOptions.ConnectionTimeout;
TSQLHttpClientWinHTTP(ORM).Compression := [hcSynShaAes];
end;
{$endif}
spHTTPsys_AES:
begin
ORM := TSQLHttpClientWinHTTP.Create(fHost,IntToStr(fPort), fDataBase.Model, True, fHTTPOptions.ProxyName, fHTTPOptions.ProxyPass, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
TSQLHttpClientWinHTTP(ORM).KeepAliveMS := fHTTPOptions.ConnectionTimeout;
TSQLHttpClientWinHTTP(ORM).Compression := [hcSynShaAes];
end;
spHTTP_WebSocket:
begin
// ORM := TSQLHttpClientWebsockets.Create(fHost,IntToStr(fPort), fDataBase.Model, False, fHTTPOptions.ProxyName, fHTTPOptions.ProxyPass, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
ORM := TSQLHttpClientWebsockets.Create(fHost,IntToStr(fPort), fDataBase.Model, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
TSQLHttpClientWebsockets(ORM).KeepAliveMS := fHTTPOptions.ConnectionTimeout;
end;
spWebSocketBidir_JSON:
begin
// ORM := TSQLHttpClientWebsockets.Create(fHost,IntToStr(fPort), fDataBase.Model, False, fHTTPOptions.ProxyName, fHTTPOptions.ProxyPass, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
ORM := TSQLHttpClientWebsockets.Create(fHost,IntToStr(fPort), fDataBase.Model, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
TSQLHttpClientWebsockets(ORM).KeepAliveMS := fHTTPOptions.ConnectionTimeout;
(ORM as TSQLHttpClientWebsockets).WebSocketsUpgrade('', True);
end;
spWebSocketBidir_Binary:
begin
// ORM := TSQLHttpClientWebsockets.Create(fHost,IntToStr(fPort), fDataBase.Model, False, fHTTPOptions.ProxyName, fHTTPOptions.ProxyPass, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
ORM := TSQLHttpClientWebsockets.Create(fHost,IntToStr(fPort), fDataBase.Model, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
TSQLHttpClientWebsockets(ORM).KeepAliveMS := fHTTPOptions.ConnectionTimeout;
(ORM as TSQLHttpClientWebsockets).WebSocketsUpgrade('', False);
end;
spWebSocketBidir_BinaryAES:
begin
// ORM := TSQLHttpClientWebsockets.Create(fHost,IntToStr(fPort), fDataBase.Model, False, fHTTPOptions.ProxyName, fHTTPOptions.ProxyPass, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
ORM := TSQLHttpClientWebsockets.Create(fHost,IntToStr(fPort), fDataBase.Model, fHTTPOptions.SendTimeout, fHTTPOptions.ReceiveTimeout, fHTTPOptions.ConnectTimeout);
TSQLHttpClientWebsockets(ORM).KeepAliveMS := fHTTPOptions.ConnectionTimeout;
(ORM as TSQLHttpClientWebsockets).WebSocketsUpgrade(fHTTPOptions.WSEncryptionKey, False);
end;
spNamedPipe:
begin
ORM := TSQLRestClientURINamedPipe.Create(fDataBase.Model,'\\.\pipe\' + fHTTPOptions.NamedPipe);
end
else
begin
raise Exception.Create('Protocol not available!');
end;
end;
//Authmode initialization
case fHTTPOptions.AuthMode of
amNoAuthentication: //No user Authentication
begin
//nothing to do here
Result := True; //shows as connected ever ???
end;
amSimple:
begin //TSQLRestServerAuthenticationNone (uses user/pass but not signature on client side)
Result := TSQLRestServerAuthenticationNone.ClientSetUser(ORM,fLogin.UserName,fLogin.HashedPassword,passHashed);
end;
amDefault: //TSQLRestServerAuthenticationDefault (uses user/pass with signature on client side)
begin
Result := ORM.SetUser(fLogin.UserName,fLogin.HashedPassword,True);
end;
amHttpBasic: //TSQLRestServerAuthenticationHttpBasic
begin
Result := TSQLRestServerAuthenticationHttpBasic.ClientSetUser(ORM,fLogin.UserName,fLogin.HashedPassword,passHashed);
end;
{$IFDEF MSWINDOWS}
amSSPI: //TSQLRestServerAuthenticationSSPI
begin
Result := TSQLRestServerAuthenticationSSPI.ClientSetUser(ORM,fLogin.UserName,fLogin.HashedPassword,passHashed);
end;
{$ENDIF}
else
begin
raise Exception.Create('Authentication mode not available');
end;
end;
if Result then
begin
//Check TimeSync with Server
if not ORM.ServerTimeStampSynchronize() then
begin
Result := False;
raise Exception.Create(ORM.LastErrorMessage);
end;
//Service initialization
if fService.Enabled then
begin
fService.SetORM(ORM);
ORM.ServiceDefine([fService.fMethodInterface],fService.fInstanceImplementation);
end;
//get Auth Group
fMyAuthGroup := TORMAuthGroup.CreateAndFillPrepare(ORM,'ID=?',[ORM.SessionUser.GroupRights.ID]);
if not fMyAuthGroup.FillOne then
begin
//raise Exception.Create('No group assigned or error on get group info!');
end;
end;
finally
if Result then
begin
if Assigned(fOnConnect) then fOnConnect;
end
else
begin
if Assigned(fOnConnectError) then fOnConnectError;
end
end;
end;
I hope my comments will be usefull.
First,. thanks again for your effort and awsome work.
Don't khnow if its mormot problem, quickorm or configuration but when I open services or methods whith chrome like http://127.0.0.1:8099/root/ServiceMethods.Sum?[2,2] i get then following exception:
First chance exception at $741218E2. Exception class ECrtSocket with message 'SockRecvLn [10060 WSAETIMEDOUT "Se produjo un error durante el intento de conexión ya que la parte conectada no respondió adecuadamente tras un periodo de tiempo, o bien se produjo un error en la conexión establecida ya que el host conectado no ha podido responder"]'. Process ORMRestServer.exe (7944)
When I access from ORMRestClient.exe everithing is OK.
I'cant debug it, but found a similar isue at https://synopse.info/forum/viewtopic.php?id=4439
I'm runnint it from delphi 10.3, and I've tried it in Windows 10 in two different computers.
Please can you upgrade Mormot 1.8 to 2.X ?
Thanks
find a bug in Quick.ORM.UTF8Helper.pas unit,unit header do not edit ,yet it is Quick.UTF8Helper
Is there any way that the server sends some kind of notification or message with data back to the clients connected to the server? Such functionality will be extremely useful as to notify connected client(s) of completion of lengthy process.
Many thanks indeed.
if I disable authentification in server and client in TORMRestClient.Connect I get an accces violation in the next line:
//get Auth Group
fMyAuthGroup := TORMAuthGroup.CreateAndFillPrepare(ORM,'ID=?',[ORM.SessionUser.GroupRights.ID]);
Correct me if Im wrong but, I think this should be enclosed in an if (fHTTPOptions.AuthMode<>amNoAuthentication) then
2 Issues
Sample in \samples\ORMRestServerDemo\source\delphi
1、 ORMRestServer AV Error
2、ORMRestClient Compile Error: Missing Quick.AppSecurity.pas
lazarus 2.2.4 FPC3.2.2
Consider this change in code :
procedure
TORMDataBase.SetDBFileName(const dbfname : RawUTF8);
begin
//if dbfile not found, sets as current app dir
// Modificado Juan
if (dbfname = SQLITE_MEMORY_DATABASE_NAME) or TFile.Exists(dbfname) then fDBFileName := dbfname
else fDBFileName := Format('%s%s',[path.EXEPATH,TPath.GetFileName(dbfname)]);
end;
`
And this to compatibility with custom external databases:
function TORMRestServer.Connect(DoCustomDb: TProc): Boolean; .. if not Assigned(DoCustomDb) then case DataBase.DBType of dtSQLite: begin .. end; dtMSSQL: begin .. end else DoCustomDb(); end; .. end;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.