Please enable JavaScript to view this site.

Codolex

Navigation: Data sources

Connecting to databases

Scroll Prev Top Next More

To use database activities such as "Get from DB", Codolex must be able to connect to a database. This requires the Delphi project that Codolex uses to have at least the data sources properties configured. The easiest way to retrieve the connection code is to right-click on a data source, and click "Copy connection code". Codolex will place the connection code in the clipboard, so you can place this in the initialization section (for example in the DPR file or in a data module) of your application.

 

To add database access manually, include the following units to your DPR file or to the initialisation code of your project:

 

 Codolex.Framework,
 Codolex.Database.Query.Interfaces,
 Codolex.Database.Query.FireDAC,
 Codolex.Database.Connection.FireDAC,
 System.SysUtils,

 

Define a function that provides an implementation of IDatabaseQuery. This interface allows Codolex to communicate with the database. There is a default implementation available for FireDac. Configure this function, the query provider, as follows:

 

  var QueryProvider: TFunc<IDatabaseQuery>;
  // It assumes that there is a FireDac connection available (MyConnection)
  QueryProvider :=
    function: IDatabaseQuery
    begin
      var DbConnection := TDatabaseConnectionFireDAC.Create(MyConnection);
      Result := TDatabaseQueryFireDAC.Create(DbConnection);
    end;

 

The Codolex Framework is the bridge between your application and the generated sources. Use the framework to link the database query provider to your data source by name.

 

// The name of the data source is e.g. 'MainDatabase'
CodolexFramework.DatabaseQueryProvider['MainDatabase'] := QueryProvider;

 

Add the following compiler directive to your Delphi project, for example in the DPR file:

 

{$STRONGLINKTYPES ON}

 

Codolex uses RTTI information to retrieve the Databroker for entities dynamically.

 

© by GDK Software