#1 2024-02-23 21:50:34

Magnele Sales
Member
From: Brazil
Registered: 2024-02-23
Posts: 1

Beginner's questions...

I'm starting with mORMot and I have some questions...

1 - When I expose an ORM class as a service, is the protocol used oData?

2 - For client applications in Delphi, do we have any classes that facilitate the application of CRUD methods to a Dataset such as an FDMemtable for example?

3 - Is there a class generator from an existing database?

Thanks.

Offline

#2 2024-02-25 08:09:17

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

Re: Beginner's questions...

Hello and welcome

1. With SOA interface based services, there is no protocol, just the plain JSON output of the ORM class as JSON object.
You can also publish ORM tables as REST, ,but the protocol is not oData, it is the older and simplier YUI URI encoding standard - but you can customize it if needed. We advice against publishing ORM tables as REST on production for security reasons - use save and well defined SOA interface based services instead.

2. You have several units in mormot.ui.*.pas which can feed a TDataSet from JSON.

3. There is one in the mORMot 1 SynDbExplorer tool.

Offline

#3 2024-02-25 12:32:20

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

Re: Beginner's questions...

Hello . I want to check one of the demos related to mormot1 but TCQRSResult is missing in mormot2. What is its equivalent?

Offline

#4 2024-02-25 19:17:01

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

Re: Beginner's questions...

The mORMot 1 DDD code was a bit bloated, so we didn't migrate it to mORMot 2.
You can just copy the enumeration type in your test project from mORMOt 1.

Offline

#5 2024-03-01 16:14:59

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

Re: Beginner's questions...

Hi AB. Thank you for very good mORMot framework.
This code work client side.
var
  OrmTable: TOrmTable;
  OrmTableDataSet: TOrmTableDataSet;
begin
  OrmTable := HttpClient.ExecuteList([],'select * from user limit 10');
  ShowMessage(OrmTable.RowCount.ToString);
  OrmTableDataSet := TOrmTableDataSet.Create(nil, OrmTable);

  DataSource1.DataSet := OrmTableDataSet;
end;


but in server side not working:Result is empty. I can't find why

procedure TUserService.List(var ATable: TOrmTable); //UserService is interface base service
begin
  ATable := Self.Server.ExecuteList([],'select * from user');
end;

Offline

#6 2024-03-03 08:42:30

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

Re: Beginner's questions...

Hi.
For reports I have very complex sql,what is the best way for executing this kind of sql?
Is it correct using :

function TReportService.Report: RawJson;
var
  MyComplexSql: RawUtf8;
begin
  MyComplexSql := 'my sql with left joins and subquery ...';
  Result := TRestServerDB(Self.Server).DB.ExecuteJson(MyComplexSql, True);
end;

Last edited by anouri (2024-03-03 08:57:28)

Offline

#7 2024-03-03 14:45:11

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

Re: Beginner's questions...

ExecuteJson() is indeed a right way to execute complex SQL from the ORM point of view.

But if you use an external database, and don't expect to switch to another database, so don't need the ORM overhead, you could use directly the mormot.sql.db units for plain SQL execution.

Offline

#8 2024-03-04 11:37:38

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

Re: Beginner's questions...

I have truble in mormot + mysql + enum fields.
Imagine that the data type is enum('large','small') when entering information in the corresponding orm class, it should be written like this (Otherwise, the error "Data truncated for column 'column_name' will be generated):

Rec.size := '1';

That is, we must enter the enum index. While I used the enum text itself in the previous software:

query.fieldbyname('size').asstring := 'large';

The solution that comes to my mind is to find the corresponding index by a function based on the enum text and write like this:
Rec.size := Get_inum_index('large');

Last edited by anouri (2024-03-04 12:12:07)

Offline

#9 2024-03-04 14:46:05

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

Re: Beginner's questions...

Define the field as published property of type RawUtf8.
So it will be stored as text in the MySQL database.

Then defined some getter/setter methods of a public enumerate field.
You can use mormot.core.rtti.pas to convert the enumerates from or back to RawUtf8 content.

Offline

#10 2024-03-04 21:40:31

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

Re: Beginner's questions...

Thank you.
Setter solved the problem. but i have alot of tables (600 tables), with many enum fields. I want to use existing database structure as possible.

procedure TOrmInvoice.SetSize(const Value: RawUtf8);
begin
  //xxlarge,xlarge,large,medium,small
  if Value = 'xxlarge' then
    FSize := '1'
  else if Value = 'xlarge' then
    FSize := '2'
  else if Value = 'large' then
    FSize := '3'
  else if Value = 'medium' then
    FSize := '4'
  else if Value = 'small' then
    FSize := '5';
end;

publish
  Size: RawUtf8;

field data type is enum('xxlarge','xlarge','large','medium','small');
I don't know where this conversion is happen. In orm level or Zeus level.

Last edited by anouri (2024-03-04 21:42:40)

Offline

#11 2024-04-02 19:43:53

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

Re: Beginner's questions...

Hi AB
many thanks to excellent mormot2 framework.
,what is the wrong with swagger :
(when I use TNullableUtf8Text)

Resolver error at paths./InvoiceService/Insert.post.parameters.0.schema.properties.AInvoice.properties.remarks.$ref
Could not resolve reference: Could not resolve pointer: /definitions/TNullableUtf8Text does not exist in document.

Last edited by anouri (2024-04-02 19:44:07)

Offline

Board footer

Powered by FluxBB