#1 Re: mORMot 1 » High-performance frameworks » 2022-08-15 03:04:04

Hi ab,

Thank you for the notice! I will follow the forum rules. I do know there are many things need to be optimized. I will do a benchmark and post into another thread. Return this thread back to TechEmpower Framework Benchmarks smile

#2 Re: mORMot 1 » High-performance frameworks » 2022-08-14 07:22:46

Hi ab,

I follow mORMot in a long time bcs your works are amazing! I'm not sure about runtime ORM. Here is my ORM does:

  /// <summary>
  ///
  /// </summary>
  TDBException = class(TDBModel)
  public
    const FIELD_ID          = 'id';
    const FIELD_MESSAGE     = 'message';
    const FIELD_STACK_TRACE = 'stack_trace';
    const FIELD_MODULE      = 'module';
    const FIELD_CREATED_AT  = 'created_at';
  private
    fID        : Int64;
    fMessage   : string;
    fStackTrace: string;
    fModule    : string;
    fCreatedAt : TDateTime;
    procedure SetMessage(const aValue: string);
    procedure SetStackTrace(const aValue: string);
    procedure SetModule(const aValue: string);
    procedure SetCreatedAt(const aValue: TDateTime);
  protected
    function DoGetFieldValue(const aField: string): TValue; override;
    class function DoGetFieldType(const aField: string): TFieldType; override;
    procedure DoSetInteger(const aField: string; const aValue: Int64); override;
    procedure DoSetDouble(const aField: string; const aValue: Double); override;
    procedure DoSetText(const aField: string; const aValue: string); override;
  public
    class function GetFieldList: TArray<string>; override;
    class function GetDataFieldList: TArray<string>; override;
    class function GetPrimaryKeyFields: TArray<string>; override;
    class function GetTableName: string; override;
  public
    property ID: Int64 read fID;
    property Message: string read fMessage write SetMessage;
    property StackTrace: string read fStackTrace write SetStackTrace;
    property Module: string read fModule write SetModule;
    property CreatedAt: TDateTime read fCreatedAt write SetCreatedAt;
  end;


class function TDBException.DoGetFieldType(const aField: string): TFieldType;
begin
  if InArray(aField,
    [
      FIELD_ID
    ])
  then
    Result := ftInteger
  else if InArray(aField,
    [
      FIELD_MESSAGE,
      FIELD_STACK_TRACE,
      FIELD_MODULE
    ])
  then
    Result := ftText
  else if InArray(aField,
    [
      FIELD_CREATED_AT
    ])
  then
    Result := ftDouble
  else
    Result := ftNone;
end;

function TDBException.DoGetFieldValue(const aField: string): TValue;
begin
  if aField = FIELD_ID then
    Result := fID
  else if aField = FIELD_MESSAGE then
    Result := fMessage
  else if aField = FIELD_STACK_TRACE then
    Result := fStackTrace
  else if aField = FIELD_MODULE then
    Result := fModule
  else if aField = FIELD_CREATED_AT then
    Result := fCreatedAt;
end;

procedure TDBException.DoSetDouble(const aField: string; const aValue: Double);
begin
  if aField = FIELD_CREATED_AT then
    fCreatedAt := aValue;
end;

procedure TDBException.DoSetInteger(const aField: string; const aValue: Int64);
begin
  if aField = FIELD_ID then
    fID := aValue;
end;

procedure TDBException.DoSetText(const aField, aValue: string);
begin
  if aField = FIELD_MESSAGE then
    fMessage := aValue
  else if aField = FIELD_STACK_TRACE then
    fStackTrace := aValue
  else if aField = FIELD_MODULE then
    fModule := aValue;
end;

class function TDBException.GetDataFieldList: TArray<string>;
begin
  Result := [
    FIELD_MESSAGE,
    FIELD_STACK_TRACE,
    FIELD_MODULE,
    FIELD_CREATED_AT
  ];
end;

class function TDBException.GetFieldList: TArray<string>;
begin
  Result := [
    FIELD_ID,
    FIELD_MESSAGE,
    FIELD_STACK_TRACE,
    FIELD_MODULE,
    FIELD_CREATED_AT
  ];
end;

class function TDBException.GetPrimaryKeyFields: TArray<string>;
begin
  Result := [
    FIELD_ID
  ];
end;

class function TDBException.GetTableName: string;
begin
  Result := 'exceptions';
end;

procedure TDBException.SetCreatedAt(const aValue: TDateTime);
begin
  if (CompareDateTime(fCreatedAt, aValue) <> EqualsValue) or IsNull(FIELD_CREATED_AT) then
  begin
    fCreatedAt := aValue;
    MarkNotNullAndDirtyField(FIELD_CREATED_AT);
  end;
end;

procedure TDBException.SetMessage(const aValue: string);
begin
  if (fMessage <> aValue) or IsNull(fMessage) then
  begin
    fMessage := aValue;
    MarkNotNullAndDirtyField(FIELD_MESSAGE);
  end;
end;

procedure TDBException.SetModule(const aValue: string);
begin
  if (fModule <> aValue) or IsNull(FIELD_MODULE) then
  begin
    fModule := aValue;
    MarkNotNullAndDirtyField(FIELD_MODULE);
  end;
end;

procedure TDBException.SetStackTrace(const aValue: string);
begin
  if (fStackTrace <> aValue) or IsNull(FIELD_STACK_TRACE) then
  begin
    fStackTrace := aValue;
    MarkNotNullAndDirtyField(FIELD_STACK_TRACE);
  end;
end;

This is for example only. It does not use RTTI. It runs fast in my cases. If you would like to use the idea of my ORM, please let me know. I will post the full source here!

Board footer

Powered by FluxBB