Skip to content

Generic Database Connection Pooling for Delphi/Lazarus/FreePascal

Notifications You must be signed in to change notification settings

ronaldobim/PascalDBPoolConnection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PascalDBPoolConnection

Generic Database Connection Pooling for Delphi/Lazarus/FreePascal

Why use a connection pool?

Using connection pooling on application servers increases application performance. Avoiding connections at all times.

Functionalities

  • Compatibility with Delphi XE7(Up) and Lazarus(Last version).
  • Simple and secure, just request connections to the pool. connections are returned to the pool automatically using reference counting.
  • Fully Thread-Safe, test project included to perform stress testing.
  • Works with any type of database access component because it does not use dependency on them (Zeos, Unidac, FireDac, etc.), the dependency is only with your application.
  • Multitenant Control.
  • Flexible to use with any development framework (Datasnap, Horse, RDW, etc).

Initialize Pool

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

function NewDatabase(ATenantDatabase: string): TObject;
var
  Conn: TZConnection;
begin
  Conn := TZConnection.Create(nil);
  //..config your connection and open connection, check your TenantDatabse in Ini File for example
  //Conn.Open;
  //Sleep(100); //Uncomment this line to test with delay
  Result := Conn;
end;

procedure TFrmMain.FormCreate(Sender: TObject);
begin
  FPool := TDBPoolConnection.GetInstance
    .SetMaxPool(100)
    .SetOnCreateDatabaseComponent(NewDatabase);
end;

Get connection from pool

var
  vDBConnection: IDBConnection;
begin
  vDBConnection := FPool.GetDBConnection;
  if vDBConnection <> nil then
  begin   
    //Using your connection
    //ZQuery.Connection := vDBConnection.DatabaseComponent as TZConnection;
    //ZQuery.SQL.Text := 'select * from dual';
    //ZQuery.Open;
  end  
end;

About

Generic Database Connection Pooling for Delphi/Lazarus/FreePascal

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages