You are not logged in.
Pages: 1
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
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
Hello . I want to check one of the demos related to mormot1 but TCQRSResult is missing in mormot2. What is its equivalent?
Offline
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
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
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
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
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
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
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
Pages: 1