Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alterações feitas pelo WillHubner com algumas correções #60

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
<p align="center">
<a href="https://github.com/bittencourtthulio/SimpleORM/blob/master/assets/logo.fw.png">
<img alt="router4d" src="https://github.com/bittencourtthulio/SimpleORM/blob/master/assets/logo.fw.png">
</a>
</p>
<br>
<p align="center">
<img src="https://img.shields.io/github/v/release/bittencourtthulio/SimpleORM?style=flat-square">
<img src="https://img.shields.io/github/stars/bittencourtthulio/SimpleORM?style=flat-square">
<img src="https://img.shields.io/github/contributors/bittencourtthulio/SimpleORM?color=orange&style=flat-square">
<img src="https://img.shields.io/github/forks/bittencourtthulio/SimpleORM?style=flat-square">
<img src="https://tokei.rs/b1/github/bittencourtthulio/SimpleORM?color=red&category=lines">
<img src="https://tokei.rs/b1/github/bittencourtthulio/SimpleORM?color=green&category=code">
<img src="https://tokei.rs/b1/github/bittencourtthulio/SimpleORM?color=yellow&category=files">
</p>


# SimpleORM
ORM Simples para Aplicações Delphi

Expand Down Expand Up @@ -76,7 +93,11 @@ Obs.: Em casos como o "Campo('ID')" a anotação é opcional, pois a `property`


## Instalação
Basta adicionar ao LibraryPatch o Caminho do SimpleORM ou via [Boss](https://github.com/HashLoad/boss) com o comando `boss install academiadocodigo/SimpleORM`, não precisa realizar a instalação de nenhum componente.
Basta adicionar ao LibraryPatch o Caminho do SimpleORM ou via [Boss](https://github.com/HashLoad/boss) com o comando `boss install bittencourtthulio/SimpleORM`, não precisa realizar a instalação de nenhum componente.

## Dependências
- DataSetConverter4Delphi
- Rest Dataware CORE

## Uses Necessárias

Expand Down
17 changes: 15 additions & 2 deletions Sample/horse/Controller/Controller.Produto.pas
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,31 @@ procedure GetID(Req: THorseRequest; Res: THorseResponse; Next: TProc);
end;

procedure Insert(Req: THorseRequest; Res: THorseResponse; Next: TProc);
var
FDAO : iDAOGeneric<TProduto>;
vJSONResult : TJSONObject;
begin
FDAO := TDAOGeneric<TProduto>.New;

vJSONResult := FDAO.Insert(Req.Body<TJSONObject>);

Res.Send<TJSONObject>(vJSONResult).Status(THTTPStatus.Created);;
end;

procedure Update(Req: THorseRequest; Res: THorseResponse; Next: TProc);
var
FDAO : iDAOGeneric<TProduto>;
begin

FDAO := TDAOGeneric<TProduto>.New;
Res.Send<TJSONObject>(FDAO.Update(Req.Body<TJSONObject>)).Status(THTTPStatus.Accepted);
end;

procedure Delete(Req: THorseRequest; Res: THorseResponse; Next: TProc);
var
FDAO : iDAOGeneric<TProduto>;
begin

FDAO := TDAOGeneric<TProduto>.New;
Res.Send<TJSONObject>(FDAO.Delete('GUUID', Req.Params.Items['id'])).Status(THTTPStatus.NoContent);
end;


Expand Down
9 changes: 4 additions & 5 deletions Sample/horse/Model/Connection/Model.Connection.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ interface
FireDAC.Comp.Client,
Firedac.DApt,
FireDAC.Phys.FB,
FireDAC.Phys.SQLite,
FireDAC.Phys.FBDef,
System.Generics.Collections;

var
FDriver : TFDPhysFBDriverLink;
FDriver : TFDPhysSQLiteDriverLink;
FConnList : TObjectList<TFDConnection>;

function Connected : Integer;
Expand All @@ -36,10 +37,8 @@ function Connected : Integer;

FConnList.Add(TFDConnection.Create(nil));
Result := Pred(FConnList.Count);
FConnList.Items[Result].Params.DriverID := 'FB';
FConnList.Items[Result].Params.Database := 'D:\Projetos\Componentes\SimpleORM\SimpleORM.git\trunk\Sample\Database\PDVUPDATES.FDB';
FConnList.Items[Result].Params.UserName := 'SYSDBA';
FConnList.Items[Result].Params.Password := 'masterkey';
FConnList.Items[Result].Params.DriverID := 'SQLite';
FConnList.Items[Result].Params.Database := 'C:/Users/Willian Hubner/Desktop/SimpleORM-master/Sample/Database/DB.db';
FConnList.Items[Result].Connected;
end;

Expand Down
56 changes: 33 additions & 23 deletions Sample/horse/Model/Connection/Model.DaoGeneric.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ interface
REST.Json,
SimpleInterface,
SimpleDAO,
SimpleTypes,
SimpleAttributes,
SimpleQueryFiredac,
Data.DB,
DataSetConverter4D,
DataSetConverter4D.Impl,
DataSetConverter4D.Helper,
DataSetConverter4D.Util;
SimpleDAO.DataSetToJSON,
Model.Connection;

type

iDAOGeneric<T : Class> = interface
['{2A6C6ED9-40BC-4AF5-A635-26615D8DD321}']
iDAOGeneric<T : Class> = Interface
['{27E6C035-9979-4656-B8E7-CC11084DC49B}']
function Find : TJsonArray; overload;
function Find (const aID : String; var aObject : T ) : iDAOGeneric<T>; overload;
function Find (const aID : String ) : TJsonObject; overload;
function Find (const aID : String; var aObject : T) : iDAOGeneric<T>; overload;
function Find (const aID : String) : TJsonObject; overload;
function Find (aKey: String; aValue: String) : TJsonArray; overload;
function Insert (const aJsonObject : TJsonObject) : TJsonObject;
function Update (const aJsonObject : TJsonObject) : TJsonObject; overload;
function Update (const aObject : T) : iDAOGeneric<T>; overload;
Expand All @@ -30,7 +29,7 @@ interface
function DataSetAsJsonArray : TJsonArray;
function DataSetAsJsonObject : TJsonObject;
function DataSet : TDataSet;
end;
End;

TDAOGeneric<T : class, constructor> = class(TInterfacedObject, iDAOGeneric<T>)
private
Expand All @@ -43,8 +42,9 @@ TDAOGeneric<T : class, constructor> = class(TInterfacedObject, iDAOGeneric<T>)
destructor Destroy; override;
class function New : iDAOGeneric<T>;
function Find : TJsonArray; overload;
function Find (const aID : String; var aObject : T ) : iDAOGeneric<T>; overload;
function Find (const aID : String ) : TJsonObject; overload;
function Find (const aID : String; var aObject : T) : iDAOGeneric<T>; overload;
function Find (const aID : String) : TJsonObject; overload;
function Find (aKey: String; aValue: String) : TJsonArray; overload;
function Insert (const aJsonObject : TJsonObject) : TJsonObject;
function Update (const aJsonObject : TJsonObject) : TJsonObject; overload;
function Update (const aObject : T) : iDAOGeneric<T>; overload;
Expand All @@ -57,15 +57,16 @@ TDAOGeneric<T : class, constructor> = class(TInterfacedObject, iDAOGeneric<T>)

implementation

{ TDAOGeneric<T> }
uses
System.SysUtils;

uses Model.Connection, System.SysUtils;
{ TDAOGeneric<T> }

constructor TDAOGeneric<T>.Create;
begin
FDataSource := TDataSource.Create(nil);
FIndexConn := Model.Connection.Connected;
FConn := TSimpleQueryFiredac.New(Model.Connection.FConnList.Items[FIndexConn]);
FConn := TSimpleQueryFiredac.New(Model.Connection.FConnList.Items[FIndexConn]).SQLType(SQLite);
FDAO := TSimpleDAO<T>.New(FConn).DataSource(FDataSource);
end;

Expand All @@ -81,49 +82,52 @@ function TDAOGeneric<T>.DataSet: TDataSet;

function TDAOGeneric<T>.DataSetAsJsonArray: TJsonArray;
begin
Result := FDataSource.DataSet.AsJSONArray;
Result := TDataSetToJSON<T>.New.DataSetToJSONArray(FDataSource.DataSet);
end;

function TDAOGeneric<T>.DataSetAsJsonObject: TJsonObject;
begin
Result := FDataSource.DataSet.AsJSONObject;
Result := TDataSetToJSON<T>.New.DataSetToJSONObject(FDataSource.DataSet);
end;

function TDAOGeneric<T>.Delete(aField, aValue: String): TJsonObject;
begin
FDAO.Delete(aField, aValue);
Result := FDataSource.DataSet.AsJSONObject;
Result := TJSONObject.Create;
end;

destructor TDAOGeneric<T>.Destroy;
begin
FDataSource.Free;

Model.Connection.Disconnected(FIndexConn);

inherited;
end;

function TDAOGeneric<T>.Find(const aID: String; var aObject: T): iDAOGeneric<T>;
begin
Result := Self;

aObject := FDAO.Find(StrToInt(aID));
end;

function TDAOGeneric<T>.Find(const aID: String): TJsonObject;
begin
FDAO.Find(StrToInt(aID));
Result := FDataSource.DataSet.AsJSONObject;
Result := TDataSetToJSON<T>.New.DataSetToJSONObject(FDataSource.DataSet);
end;

function TDAOGeneric<T>.Find: TJsonArray;
begin
FDAO.Find;
Result := FDataSource.DataSet.AsJSONArray;
Result := TDataSetToJSON<T>.New.DataSetToJSONArray(FDataSource.DataSet);
end;

function TDAOGeneric<T>.Insert(const aJsonObject: TJsonObject): TJsonObject;
begin
FDAO.Insert(TJson.JsonToObject<T>(aJsonObject));
Result := FDataSource.DataSet.AsJSONObject;
Result := TDataSetToJSON<T>.New.DataSetToJSONObject(FDataSource.DataSet);
end;

class function TDAOGeneric<T>.New: iDAOGeneric<T>;
Expand All @@ -134,13 +138,19 @@ class function TDAOGeneric<T>.New: iDAOGeneric<T>;
function TDAOGeneric<T>.Update(const aJsonObject: TJsonObject): TJsonObject;
begin
FDAO.Update(TJson.JsonToObject<T>(aJsonObject));
Result := FDataSource.DataSet.AsJSONObject;
Result := TDataSetToJSON<T>.New.DataSetToJSONObject(FDataSource.DataSet);
end;

function TDAOGeneric<T>.Update(const aObject: T): iDAOGeneric<T>;
begin
FDAO.Update(aObject);
FDAO.Update( aObject );
Result := Self;
end;

function TDAOGeneric<T>.Find(aKey: String; aValue: String): TJsonArray;
begin
FDAO.Find(aKey, aValue);
Result := TDataSetToJSON<T>.New.DataSetToJSONArray(FDataSource.DataSet);
end;

end.
30 changes: 15 additions & 15 deletions Sample/horse/Model/Entity/Model.Entity.Produto.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ interface
[Tabela('PRODUTO')]
TPRODUTO = class
private
FGUUID :String;
FID :Integer;
FCODIGO :String;
FDESCRICAO :String;
FPRODUTO :String;
FPRECO :Currency;
FNCM :Integer;
FALIQUOTA :Currency;
FST :Integer;
FSTATUS :Integer;
FDATAALTERACAO :TDateTime;

procedure SetGUUID (const Value :String);
function GetGUUID :String;
procedure SetGUUID (const Value :Integer);
function GetGUUID :Integer;

procedure SetCODIGO (const Value :String);
function GetCODIGO :String;
Expand Down Expand Up @@ -51,12 +51,12 @@ TPRODUTO = class
constructor Create;
destructor Destroy; override;
procedure Limpar;
[Campo('GUUID'), PK]
property GUUID :String read GetGUUID write SetGUUID;
[Campo('GUUID'), PK, AutoInc]
property ID :Integer read GetGUUID write SetGUUID;
[Campo('CODIGO')]
property CODIGO :String read GetCODIGO write SetCODIGO;
[Campo('DESCRICAO')]
property DESCRICAO :String read GetDESCRICAO write SetDESCRICAO;
property PRODUTO :String read GetDESCRICAO write SetDESCRICAO;
[Campo('PRECO')]
property PRECO :Currency read GetPRECO write SetPRECO;
[Campo('NCM')]
Expand Down Expand Up @@ -85,14 +85,14 @@ destructor TPRODUTO.Destroy;
inherited;
end;

procedure TPRODUTO.SetGUUID (const Value :String);
procedure TPRODUTO.SetGUUID (const Value :Integer);
begin
FGUUID := Value;
FID := Value;
end;

function TPRODUTO.GetGUUID :String;
function TPRODUTO.GetGUUID : Integer;
begin
Result := FGUUID;
Result := FID;
end;

procedure TPRODUTO.SetCODIGO (const Value :String);
Expand All @@ -107,12 +107,12 @@ function TPRODUTO.GetCODIGO :String;

procedure TPRODUTO.SetDESCRICAO (const Value :String);
begin
FDESCRICAO := Value;
FPRODUTO := Value;
end;

function TPRODUTO.GetDESCRICAO :String;
begin
Result := FDESCRICAO;
Result := FPRODUTO;
end;

procedure TPRODUTO.SetPRECO (const Value :Currency);
Expand Down Expand Up @@ -179,9 +179,9 @@ function TPRODUTO.GetDATAALTERACAO :TDateTime;
procedure TPRODUTO.Limpar;
begin

Self.GUUID := '';
Self.ID := 0;
Self.CODIGO := '';
Self.DESCRICAO := '';
Self.PRODUTO := '';
Self.PRECO := 0;
Self.NCM := 0;
Self.ALIQUOTA := 0;
Expand Down
4 changes: 0 additions & 4 deletions Sample/horse/SimpleORMHorse.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ uses
Horse.Jhonson,
Horse.CORS,
Model.Connection in 'Model\Connection\Model.Connection.pas',
DataSetConverter4D.Helper in 'DataSetConverter4D.Helper.pas',
DataSetConverter4D.Impl in 'DataSetConverter4D.Impl.pas',
DataSetConverter4D in 'DataSetConverter4D.pas',
DataSetConverter4D.Util in 'DataSetConverter4D.Util.pas',
Controller.Produto in 'Controller\Controller.Produto.pas',
Model.Entity.Produto in 'Model\Entity\Model.Entity.Produto.pas',
Model.DaoGeneric in 'Model\Connection\Model.DaoGeneric.pas';
Expand Down
Loading