#51 2024-08-16 02:17:21

ttomas
Member
Registered: 2013-03-08
Posts: 135

Re: Where do I start?

anouri wrote:

thanks. but yo write "TSQL*ConnectionProperties is connection pool, not real db connection! Real db connection is TSQL*ConnectionProperties"
it is same!
TSQL*ConnectionProperties = TSQL*ConnectionProperties

TSQL*ConnectionProperties.ThreadSafeConnection

Offline

#52 2024-08-17 11:33:35

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

I finished reading BeDelphi2014 today.
There are still some things that are unclear to me.
My first question is:
Has the syndb unit been removed from mormot2?

Offline

#53 2024-08-17 12:59:53

ttomas
Member
Registered: 2013-03-08
Posts: 135

Re: Where do I start?

mormot.db.proxy.pas

Offline

#54 2024-08-18 06:32:24

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

What is the reason for the following error?
Project TestServer.exe raised exception class EServiceException with message 'TServiceFactoryServer.Create: IProduct routing name is already used by a Product SQL table name'.

My test Project source
https://mega.nz/file/d5RTDB5A#f-mBchZj4 … a826ZtybbA

I haven't assigned the model to TRestHttpServer.Create yet, but the problem doesn't originate from there.

Last edited by Kabiri (2024-08-18 07:08:43)

Offline

#55 2024-08-18 09:04:28

flydev
Member
From: France
Registered: 2020-11-27
Posts: 73
Website

Re: Where do I start?

As the error say, routing name 'Product' (TOrmProduct) already exist when you register your Product (IProduct) interface. As the framework use automatic serialization via rtti, an error is triggered when you use same name for interface (service) and table (storage).
In other words, your interface is translated to 'Product' and your table to 'Product'.

To avoid these errors, just be consistent in your naming convention, eg. name your interface `IProductService`. You might register a custom serializer to evade from this, but I didnt used it, so wait for another answer smile

Last edited by flydev (2024-08-18 09:06:39)

Offline

#56 2024-08-18 11:29:59

ttomas
Member
Registered: 2013-03-08
Posts: 135

Re: Where do I start?

Better to create separate restserver for interface/methods with different root uri ex. api. Then you will have
/orm/Product for orm access and /api/Product for interface and method calls. In production when you put your service behind reverse proxy you will pass only /api uri, /orm access is not recommended for direct client access. You can still access /orm for some housekeeping on localhost.

Offline

#57 2024-08-18 17:58:54

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

Thank you.
I changed the interface name.
It's giving the error:
Project TestServer.exe raised exception class EHttpApiServer with message 'HttpSetServiceConfiguration failed: ERROR_ACCESS_DENIED (5)'.
But the database and table are created. (I also added the command ProductServer.Server.CreateMissingTables;).

Offline

#58 2024-08-19 09:47:12

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

I think my way of categorizing units into Controller and DAC is not very suitable for Mormot.
I should choose a different structure for categorizing files in Mormot.
Do you categorize your files in a specific way?
My next question is how to implement the List method to return the list of desired records to the client?

Thanks

Offline

#59 2024-08-20 07:45:31

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

Kabiri wrote:

Thank you.
I changed the interface name.
It's giving the error:
Project TestServer.exe raised exception class EHttpApiServer with message 'HttpSetServiceConfiguration failed: ERROR_ACCESS_DENIED (5)'.
But the database and table are created. (I also added the command ProductServer.Server.CreateMissingTables;).

Is this error a known occurrence?
What steps should be taken to rectify this error?

---Edit
I have also successfully modified the list method.

Is this the right and proper way to do this?

function TProductService.List(var AProduct: TProductParam): RawJson;
var
  Sql: RawUtf8;
begin
  Sql := 'select * from Product';
  Result := TRestServerDB(Self.Server).DB.ExecuteJson(Sql, True);
end;

How do I disable ORM for the client?
Currently, there are commands like :
http://127.0.0.1:8080/root/Product
http://127.0.0.1:8080/root/Product/1
are returning records without any filtering or validation

Last edited by Kabiri (2024-08-20 08:06:59)

Offline

#60 2024-08-20 08:10:01

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

Re: Where do I start?

HttpSetServiceConfiguration failed: ERROR_ACCESS_DENIED (5) has nothing to do with the ORM, it is a web server problem, when you use http.sys.

It is clearly documented that if you use the http.sys web server, you should register the URI to the system.
This is a Windows limitation.
https://synopse.info/files/html/Synopse … l#TITL_109
Either register the URI, or use the async socket web server.

To disable the ORM access to the client, as we already wrote here, you should better NOT put any TOrm in your TRestServer model published over HTTP.
And use another TRestServer for the persistence, this one NOT published over HTTP.

Offline

#61 2024-08-21 06:06:34

anouri
Member
Registered: 2024-02-11
Posts: 47

Re: Where do I start?

Hi mr TBO. property ConnectionPool is readonly property, how can I assgin connectionpool?
I passed it by TRestServer  constructor at the moment.

Last edited by anouri (2024-08-21 07:17:04)

Offline

#62 2024-08-31 11:43:37

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

I've been unable to locate a solution to prevent direct access to the ORM.
It would be convenient if the server offered a method named AllowDirectAccess. :rolleyes

Offline

#63 2024-08-31 12:01:11

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

Re: Where do I start?

What we wrote and propose is clear.

If you don't include any table to the main server model, you won't have any ORM exposed.

You could also set rsoNoTableURI to TRestServer.Options, if you really want to keep the tables within the main TRestServer model.

Offline

#64 2024-08-31 12:42:09

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

You have run so many marmot tests and everything is clear to you. It's not that clear to me.
I've modified the server by setting

HttpServer := TRestHttpServer.Create(HttpPort, [], '+', useHttpApiRegisteringURI,4);

, but my Delphi client can no longer connect to it.
I reverted the previous command to its original state and made changes to the service.
I modified the class from 'TProductServer = class(TRestServerDB)' to 'TProductServer = class(TRestServer)'.
However, I'm getting an access violation error at the line 'ServiceDefine(TProductService, [IProductService], sicShared);'
I really don't know where to delete the model from the server.

Offline

#65 2024-08-31 13:20:29

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

No, I don't want to keep the tables in the original TRestServer model.

Last edited by Kabiri (2024-08-31 14:39:25)

Offline

#66 2024-08-31 17:54:33

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

Re: Where do I start?

Please try to follow what we wrote here.
You fell back into your initial issue: TRestServer is not to be used, it is an abstract class.

You need to use TRestServerFullMemory.
https://synopse.info/forum/viewtopic.ph … 667#p41667

Offline

#67 2024-09-02 11:10:28

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

I think I was a bit confused, but I understand now. smile

Offline

#68 2024-09-03 10:34:44

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

When I switch from TRestServerDB to TRestServerFullMemory, how do I access the database?
Do I have to abandon ORM in this case and revert to the old method of database access?

Offline

#69 2024-09-06 14:29:36

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: Where do I start?

Do you have an external (existing) database?

In that case, that connection is independent of orm or TRestServerFullMemory.
You define and use TRestServerFullMemory as a server to which clients access and request data and then retrieve data from DB and send it to clients.

var
  conn: TSQLDBConnectionProperties;

  conn := TSQLDBZEOSConnectionProperties.Create(
    TSQLDBZEOSConnectionProperties.URI(dFIREBIRD, PrgSettings.DBServer.AsUTF, 'fbclient.dll', False),
    PrgSettings.DBPath.AsUTF, PrgSettings.DBUserName.AsUTF, PrgSettings.DBPass.AsUTF);

and when you need to retrieve something:
var
  json: RawUTF8;

  json := conn.Execute(ASQL, AParams).FetchAllAsJSON(True);

Offline

#70 2024-09-06 14:38:50

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: Where do I start?

You use ORM system and classes when you start with an empty system, empty database and you define tables and relations from Delphi code (ORM part),
it's also good to use it for authentication (TSQLRestServerAuthenticationDefault is quite good for Delphi server/client).

And you can mix and match, have something accessed through ORM (it goes directly to database and you never touch raw sql), or through some API, either via methods or interfaces (or both). In methods/interfaces you can use orm or you can use direct database access (for existing db outside of ORM).

mORMOt is complex because it has so many parts and systems, so just start small and see what  you need at the moment, use minimal approach and later add to it.

Offline

#71 2024-09-07 07:03:13

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

Thanks, @igors233.
I’m using SQL Server 2008 for the database.
I’m also using JWT and username/password for authentication.
I have an existing API written with HORSE, and I wanted to rewrite it with mORMot.
Additionally, I want to use the ORM feature of the mORMot framework in this rewrite (I have prior experience using TMS Aurelius).
The first challenge for me was understanding the different servers in mORMot, as I wasn’t sure which server is for what.
The second challenge was connecting it to SQL Server.
I haven’t yet tried JWT and authentication.
Regarding the servers, I realized that when I use TRestServerDB, the user or client can easily access the tables. Authentication might prevent this access, but from what I’ve studied, it doesn’t seem to check the access details. For example, imagine I have a "status" field that marks records as deleted (without physically deleting them). In the method for listing data, I don’t send these records, but since the client has access to the table through ORM, they can retrieve those records.
Also, when I use TRestServerFullMemory, I no longer have access to the ORM.

Offline

#72 2024-09-07 11:27:05

tbo
Member
Registered: 2015-04-20
Posts: 353

Re: Where do I start?

Kabiri wrote:

Regarding the servers, I realized that when I use TRestServerDB, the user or client can easily access the tables. Authentication might prevent this access, but from what I’ve studied, it doesn’t seem to check the access details. For example, imagine I have a "status" field that marks records as deleted (without physically deleting them). In the method for listing data, I don’t send these records, but since the client has access to the table through ORM, they can retrieve those records.
Also, when I use TRestServerFullMemory, I no longer have access to the ORM.

You don't read the answers to your questions carefully. You're making it difficult for everyone here to help you. You have already received useful links for the start in post #2. Have you studied this example, which only uses an HTTP server? Once you have found the entry point, you can search the mORMot source code for it and quickly find the answer to your questions. This example only uses a REST server and shows the use of the ORM. These two examples (here and here) show how REST and HTTP servers work together without using the ORM. Why should it be necessary to expose access to the ORM? Use TRestServerFullMemory as Main and only open access to the ORM in the interface-based services. You can combine everything and have already been shown how to do it here. Please let us help you too. Read through the tips you have received again.

With best regards
Thomas

Offline

#73 2024-09-07 12:39:49

Kabiri
Member
Registered: 2024-06-22
Posts: 35

Re: Where do I start?

Thank you, @Thomas.
I’m trying my best to read the answers carefully, but since English isn’t my native language, I don’t fully understand everything, and sometimes I even explain things poorly.
I apologize for that. I will try harder and ask fewer questions.

Offline

Board footer

Powered by FluxBB