#1 2020-04-20 10:36:11

alexdmatveev
Member
Registered: 2014-09-12
Posts: 87

interface based services: Bulk insert on the server side

Hello,

pls show me the way or a part of the documentation...

Environment: UniDAC + MySQL.

I have interface based services.
On Server side I got a collection of TPersistent DTOs as in [..\SQLite3\Samples\20 - DTO interface based service] sample.
Everything works good but a bit slow.

unit uServiceBehandlerDef;

interface

uses
  SysUtils, mormot, uServiceInterfaces, uModel, uModelDB, uServer;

type
  TBehandlerDefPostService = class(TInterfacedObject, IBehandlerDefPostService)
  public
    procedure Post(const items: TDTOBehandlerDefs);
  end;

implementation

procedure TBehandlerDefPostService.Post(const items: TDTOBehandlerDefs);
var
  obj: TBehandlerDef;
  i: Integer;
  dto: TDTOBehandlerDef;
begin
  aRestServer.Delete(TBehandlerDef, Format('Username=''%s''', [ServiceContext.Request.SessionUserName]));

  for i := 0 to items.Count - 1 do
  begin
    obj := TBehandlerDef.Create;
    try
      dto := TDTOBehandlerDef(items[i]);
      obj.BDEF_NR := dto.BDEF_NR;
      obj.INTERN_NAME := dto.INTERN_NAME;
      obj.EXTERN_NAME := dto.EXTERN_NAME;
      aRestServer.Add(obj, True);
    finally
      obj.Free;
    end;
  end;
end;

end.

I would like to use bulk mysql insert on the server side.

I see the method Batch but do not understand how I should use it.

  TSQLRestServer = class(TSQLRest)
    procedure Batch(Ctxt: TSQLRestServerURIContext);

Thanks.

Offline

#2 2020-04-20 11:20:29

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

Re: interface based services: Bulk insert on the server side

Offline

#3 2020-04-20 13:03:05

alexdmatveev
Member
Registered: 2014-09-12
Posts: 87

Re: interface based services: Bulk insert on the server side

The solution from [12.3.3.1. Several Batches] works like a charm.
Thanks a lot for the great help!

Offline

#4 2020-04-20 15:30:44

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

Re: interface based services: Bulk insert on the server side

A quick search in the documentation headlines would have found the page I guess.

Offline

Board footer

Powered by FluxBB