Sign in Join

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

Catalog · How the catalog works

Random project

RiceFramework

The RiceFramework aims to help those who develop something for MongoDB with Delphi.

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

RiceFramework

The RiceFramework aims to help those who develop something for MongoDB with Delphi. It has been tested with versions XE5, XE6, XE7 and Berlin 10.1. Where as driver was used TMongoWire(https://github.com/stijnsanders/TMongoWire))

Examples:

Class TAluno

pascal
[DocumentName('aluno')]
TAluno = class(TGenericEntity)
private
  FMatricula: string;
  FNotas: TNotas;
  FNome: string;
  FEndereco: string;
  FId: string;
public
  [IdField('id')]
  property Id:string read FId write FId;
  property Nome:string read FNome write FNome;
  property Endereco:string read FEndereco write FEndereco;
  property Matricula: string read FMatricula write FMatricula;
  property Notas: TNotas read FNotas write FNotas;
pascal
constructor Create();
destructor Destroy; override;
pascal
end;

DAO

pascal
type
TAlunoDAO = class(TGenericDAO)
public
end;

Insert

pascal
Var
  Aluno: TAluno;
begin
  Aluno := TAluno.Create();
  Aluno.Id := mongoObjectId;
  Aluno.Nome := dtsDadosNome.AsString;
  Aluno.Endereco := dtsDadosEndereco.AsString;
  Aluno.Matricula := dtsDadosMatricula.AsString;
  Aluno.Notas.Nota := dtsDadosNota.AsFloat;
pascal
try
  TAlunoDAO.Insert<TAluno>(Aluno);
  showmessage('Aluno inserido!');
except
  showmessage('Aluno não inserido!')
end;
Aluno.Free;

Delete

pascal
TAlunoDAO.Delete<TAluno>(dtsDadosId.AsString);

Update

pascal
Var
  Aluno: TAluno;
begin
pascal
Aluno := TAluno.Create();
Aluno.Id := dtsDadosId.AsString;
Aluno.Nome := dtsDadosNome.AsString;
Aluno.Endereco := dtsDadosEndereco.AsString;
Aluno.Matricula := dtsDadosMatricula.AsString;
Aluno.Notas.Nota := dtsDadosNota.AsFloat;
pascal
try
  TAlunoDAO.SaveOrUpdate(Aluno);
  showmessage('Aluno inserido!');
except
  showmessage('Aluno não inserido!')
end;
pascal
Aluno.Free;

GetAll

pascal
var
   vObjetos: TObjectList<TAluno>;
begin   
   vObjetos := TAlunoDAO.GetAll<TAluno>();
   for Aluno in vObjetos do
        dtsDados.Insert;
        dtsDadosId.AsString := Aluno.Id;
        dtsDadosNome.AsString := Aluno.Nome;
        dtsDadosMatricula.AsString := Aluno.Matricula;
        dtsDadosEndereco.AsString := Aluno.Endereco;
        dtsDadosNota.AsFloat := Aluno.Notas.Nota;
        dtsDados.Post;
   end;
   FreeAndNil(vObjetos);
end;

GetByID

pascal
Var
  Aluno: TAluno;
begin
  Aluno := TAlunoDAO.GetByID<TAluno>(dtsDadosId.AsString);
end;