Jump to content
3ddark

Simple ORM

Recommended Posts

Delphi Simple ORM using ZeosDBO

https://github.com/3ddark/delphi-orm-test

 

Two different version.

 

v2 supported actions

    function GetList(AClass: TClass; var AList: TArray<TTable>; AFilter: string; ALock: Boolean; APermissionCheck: Boolean=True): Boolean;
    function GetListCustom(AClass: TClass; var AList: TArray<TTable>; AFields: TArray<TFieldDB>; AFilter: string; ALock: Boolean; APermissionCheck: Boolean=True): Boolean;

    function GetOne(ATable: TTable; AFilter: string; ALock: Boolean; APermissionCheck: Boolean=True): Boolean; overload;
    function GetOneCustom(ATable: TTable; AFields: TArray<TFieldDB>; AFilter: string; ALock: Boolean; APermissionCheck: Boolean=True): Boolean; overload;

    function GetOne(ATable: TTable; AID: Int64; ALock: Boolean; APermissionCheck: Boolean=True): Boolean; overload;
    function GetOneCustom(ATable: TTable; AFields: TArray<TFieldDB>; AID: Int64; ALock: Boolean; APermissionCheck: Boolean=True): Boolean; overload;

    function Insert(ATable: TTable; APermissionCheck: Boolean=True): Boolean; virtual;

    function Update(ATable: TTable; APermissionCheck: Boolean=True): Boolean; virtual;
    function CustomUpdate(ATable: TTable; AFields: TArray<TFieldDB>; APermissionCheck: Boolean=True): Boolean; virtual;

    function DeleteBatch(AClass: TClass; AFilter: string; APermissionCheck: Boolean=True): Boolean; overload;
    function DeleteBatch(ATables: TArray<TTable>; APermissionCheck: Boolean=True): Boolean; overload;
    function Delete(ATable: TTable; APermissionCheck: Boolean=True): Boolean; virtual;

    function LogicalSelect(AClass: TClass; var ATable: TTable; AFilter: string; ALock, AWithBegin, APermissionCheck: Boolean; AProcBusinessSelect: TBusinessSelectEvent): TEntityManager; virtual;
    function LogicalInsert(ATable: TTable; AWithBegin, AWithCommit, APermissionCheck: Boolean; AProcBusinessInsert: TBusinessOperationEvent): Boolean; virtual;
    function LogicalUpdate(ATable: TTable; AWithBegin, AWithCommit, APermissionCheck: Boolean; AProcBusinessUpdate: TBusinessOperationEvent): Boolean; virtual;
    function LogicalDelete(ATable: TTable; AWithBegin, AWithCommit, APermissionCheck: Boolean; AProcBusinessDelete: TBusinessOperationEvent): Boolean; virtual;

    procedure Listen(ATableName: string); virtual;
    procedure Unlisten(ATableName: string); virtual;
    procedure Notify(ATableName: string); virtual;

    function IsAuthorized(ATableSourceCode: string; APermissionType: TPermissionType; APermissionCheck: Boolean; AShowException: Boolean=True): Boolean;

    procedure Start(AConnection: TZAbstractConnection = nil);
    procedure Commit(AConnection: TZAbstractConnection = nil);
    procedure Rollback(AConnection: TZAbstractConnection = nil);

frmMain contain example for using methods
 

  • Like 3

Share this post


Link to post
4 hours ago, Arnaud Bouchez said:

Generation of SQL with parameters should help the performance and security.

 

Can you explain with an example?

Share this post


Link to post
On 7/31/2023 at 2:31 PM, 3ddark said:

Can you explain with an example?

Instead of “SELECT * FROM MyTable WHERE ID = 99” use “SELECT * FROM MyTable WHERE ID = :pID”, then assign the value 99 for the parameter named pID.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×