#1 2024-01-06 23:14:51

nakisen
Member
Registered: 2021-04-30
Posts: 16

Simple testing without using ORM

Hello

I wanted to do a simple test without using any ORM instance, but I'm getting an "Access Violation" error. What am I missing?

mormot.rest.core.pas

procedure TRest.OnBeginCurrentThread(Sender: TThread);
begin
  fOrmInstance.BeginCurrentThread(Sender);  <<< fOrmInstance has not been created; Access Violation
end;
...
type
  TSampleServer = class(TRestServer)
  published
    procedure test(Ctxt: TRestServerUriContext);
  end;
...
FApiServer:TSampleServer;
FHttpServer:TRestHttpServer;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
  FApiServer:=TSampleServer.Create('api');

  FHttpServer := TRestHttpServer.Create('80', [FApiServer], '+', HTTP_DEFAULT_MODE, 4);
  FHttpServer.AccessControlAllowOrigin := '*';
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FHttpServer.Free;
  FApiServer.Free;
end;

procedure TSampleServer.test(Ctxt: TRestServerUriContext);
begin
  Ctxt.Returns('{"result":null}');
end;

Offline

#2 2024-01-07 12:04:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Simple testing without using ORM

TRestServer is an ABSTRACT class which should not be used as parent class.

Inherit from TRestStorageInMemory instead, even if you don't need any ORM support.

Offline

#3 2024-01-07 14:22:45

nakisen
Member
Registered: 2021-04-30
Posts: 16

Re: Simple testing without using ORM

Thanks ab :$

I want to get rid of SQL, so I'll use ORM smile

Offline

#4 2024-01-07 15:31:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Simple testing without using ORM

I made a typo above: you need to use TRestServerFullMemory, not TRestStorageInMemory.
wink

Offline

#5 2024-01-07 15:58:21

nakisen
Member
Registered: 2021-04-30
Posts: 16

Re: Simple testing without using ORM

I had already realized that I needed to use TRestServerFullMemory after your message. Thanks

Offline

#6 2024-01-07 16:52:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Simple testing without using ORM

In the future, I would like to make a high-level wrapper server class around all those multiple classes, to make it easier to use.
The framework has so many possibilities, it is likely to be intimidating and confusing.

Offline

#7 2024-01-07 22:17:58

nakisen
Member
Registered: 2021-04-30
Posts: 16

Re: Simple testing without using ORM

First of all, you did a great job. Thanks again.

Like you, I think some structures should be simplified. For those new to mORMot, the learning curve should be rapid. After learning mORMot, I would like to contribute.

//I think these types of regulations you are talking about are;

FHttpServer:TContainerHttpServer;	// or TAppHttpServer
FRestApp:TRestHttpApplication;		// or TRestHttpService
FRawApp:TRawHttpAppication;		// or TRawHttpService
FMvcApp:TMvcHttpApplication;		// or TMvcHttpService
	
FHttpServer.Create('0.0.0.0:80', [FRestApp, FRawApp]);

FRestApp.Root:='/api';
FRestApp.Storage:=TOrmModel;
//FRestApp.Storage:=TMemoryModel;

FRawApp.Root:='/';
FRawApp.StaticsPath:='/statics'

Last edited by nakisen (2024-01-07 22:29:13)

Offline

#8 2024-01-08 08:05:36

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Simple testing without using ORM

I have enhanced the documentation about not to use TRestServer:
https://github.com/synopse/mORMot2/commit/a141b409

Offline

Board footer

Powered by FluxBB