Skip to content

adrianosantostreina/ADRConnection

Repository files navigation

ADRConnection

ADRConnection

Database connection abstraction. Encapsulates multiple connection components into a single interface.

🧬Available Components

Component Delphi Directive
Firedac    ✔️ ADRCONN_FIREDAC
PGDAC    ✔️ ADRCONN_PGDAC
Unidac    ✔️ ADRCONN_UNIDAC
ZEOS    ✔️ ADRCONN_ZEOS

⚙️ Installation

Installation is done using the boss install command:

boss install github.com/adrianosantostreina/ADRConnection

⚡️ Quickstart

// Create a Connection
uses
  ADRConn.Model.Interfaces;

var
  FConnection: IADRConnection;
begin
  FConnection := CreateConnection;
  FConnection.Params
    .Driver(adrPostgres)
    .Database('demoadrconnection')
    .Server('127.0.0.1')
    .Port(5432)
    .UserName('postgres')
    .Password('postgres');

  FConnection.Connect;    
end.

// Create a Query
var
  FQuery: IADRQuery;
begin
  FQuery := CreateQuery(FConnection);
  FQuery.SQL('select id, name, document, phone')
    .SQL('from person')
    .Open;
end;

There is the possibility to include custom parameters to connection

FConnection.Params
    .Driver(adrPostgres)
    .Database('demoadrconnection')
    .Server('127.0.0.1')
    .Port(5432)
    .UserName('postgres')
    .Password('postgres');
    .AddParam('CharacterSet', 'UTF8') //<-- custom parameters Here
    .AddParam('lc_ctype', 'UTF8'); //<-- custom parameters Here

To execute Insert, update or Delete, use

var
  FQuery: IADRQuery;
begin
  FQuery := CreateQuery(FConnection);
  FQuery.SQL('insert into person (id, name, document, phone)')
    .SQL('values(1, 'DinosDev', '00001', '11 9 12345656')')
    .ExecSQL;
end;
    

If you need works with TDataSet, you can convert this query on Dataset Easily

var
  lCds: TDataSet;
begin
  lCds := CreateQuery(FConnection);
            .SQL('select id, name, document, phone')
            .SQL('from person')
          .OpenDataSet;
end;

// Or you can use that
var
  FQuery: IADRQuery;
  lCds: TDataSet;
  lDataSource: TDataSource;
begin
  FQuery := CreateQuery(FConnection);
  FQuery.SQL('select id, name, document, phone')
    .SQL('from person')
    .Open;

  lCds := FQuery.DataSet;

  // you can extract the DataSource to link on Grid
  FQuery.DataSource(lDataSource); //Return a interface IADRQuery
  Grid.DataSource := lDataSource;
end;
    

About

Classes de conexão com banco de dados

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 7

Languages