Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

ADRConnection

Classes de conexão com banco de dados

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

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:

bash
boss install github.com/adrianosantostreina/ADRConnection

⚡️ Quickstart

delphi
// 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

delphi
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

delphi
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

delphi

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;