Git Product home page Git Product logo

lmxpackage's Introduction

lmxpackage

Versão atual 1.0.0

Instalação

Não é nescessária nenhuma instalação, basta adicionar o caminho do repositório no path do Delphi

boss

para usar no boss, basta instalar o boss e no seu projeto usar

boos init

boss install https://github.com/luizsfolia/lmxpackage.git

Exemplos

você pode abrir um server de exemplo que está em https://github.com/luizsfolia/lmxpackage/blob/main/exemplos/GrupoExemplos.groupproj

Abaixo seguem alguns exemplos utilizados do projeto acima

Crinado Server HTTP

var
  FServer : TLmxHttpServer;
begin
  FServer := TLmxHttpServer.Create;
  FServer.AdicionarComando(TModuloCllientes, '/Clientes'); // Classe descrita abaixo na opção sem ORM 
  FServer.Ativar(8500); // server sendo ativado na porta 8500
end

Sem OrmLmx

Exemplo de classe de comando

  TModuloCllientes = class(TLmxServerComand)
  public
    [HttpGet]
    [TLmxAttributeComando('')]
    function GetClientes : ILmxRetorno<TClientes>;

    [HttpGet]
    [TLmxAttributeComando('/{id}')]
    function GetCliente([FromParams] const id : Integer) : ILmxRetorno<TCliente>;

    [HttpPost]
    [TLmxAttributeComando('')]
    function PostCliente(const pCliente : TCliente) : ILmxRetorno<TCliente>;
  end;

Implementação da classe de comando

function TModuloCllientes.GetCliente(const id: Integer): ILmxRetorno<TCliente>;
begin
  Result := TLmxRetorno<TCliente>.Create;
  Result.Retorno.Nome := 'Luiz';
  Result.Retorno.Id := id;
end;

function TModuloCllientes.GetClientes : ILmxRetorno<TClientes>;
var
  lCliente: TCliente;
begin
  Result := TLmxRetorno<TClientes>.Create;

  lCliente := TCliente.Create;
  lCliente.Nome := 'Luiz';
  lCliente.Id := 1;

  Result.Retorno.Add(lCliente);

  lCliente := TCliente.Create;
  lCliente.Nome := 'Ricardo';
  lCliente.Id := 2;

  Result.Retorno.Add(lCliente);

end;

function TModuloCllientes.PostCliente(const pCliente: TCliente): ILmxRetorno<TCliente>;
begin
  // Salvar no DataBase o pCliente
  Result := GetCliente(pCliente.id);
end;

classe de modelo

uses
  uLmxCore, uLmxAttributes, System.Classes;

type

  [TLmxAttributeMetadata]
  TCliente = class(TBaseTabelaPadrao)
  private
    FNome: string;
  public
    [TLmxAttributeMetadata(80)]
    property Nome : string read FNome write FNome;
  end;

  TClientes = class(TBaseList<TCliente>)
  end;

Com Orm Lmx

Classe DataBaseExemplo

uses
  uLmxCore, uLmxAttributes, System.Math, Generics.Collections, System.Classes;

type

  TTipoUsuario = (tuUsuarioNormal, tuAdministrador);

  [TLmxAttributeMetadata]
  TUsuario = class(TBaseTabelaPadrao)
  private
    FEmail: string;
    FLogin: string;
    FNome: string;
    FTipoUsuario: TTipoUsuario;
  public
    [TLmxAttributeMetadata(100)]
    property Nome : string read FNome write FNome;
    [TLmxAttributeMetadata(100)]
    property Email : string read FEmail write FEmail;
    [TLmxAttributeMetadata(100)]
    property Login : string read FLogin write FLogin;
    [TLmxAttributeMetadata]
    property TipoUsuario : TTipoUsuario read FTipoUsuario write FTipoUsuario;
  end;

  TUsuarios = class(TBaseList<TUsuario>);

Conexao com DataBase (Firebird)

  TContextDataBaseConfig.Default.RegistrarConexao(TLmxConexaoFirebird,
    procedure (const pControleConexao : TLmxControleConexao)
    begin
      pControleConexao.HostName := 'localhost';
      pControleConexao.DataBase :=  'c:\tmp\Database\lmxteste.FDB';
      pControleConexao.ClasseDriver := TLmxConexaoFirebird.ClassName;
      pControleConexao.User_Name := 'sysdba';
      pControleConexao.Password := 'masterkey';
    end

Criando/Atualizando DataBase

  lConexao := TLmxConexaoFirebird.Create;
      try
        lConexao.ConfigurarConexao(pControleConexao);

        LmxMetadata.SetConexao(lConexao);
        LmxMetadata.ExecutarNoBancoDeDados := True;
        LmxMetadata.OnAlteracaoDataBaseEvent := OnAlterarBancoDados;
        LmxMetadata.CriarDataBase;

        if (not LmxMetadata.TemTelaRegistrada) then
          LmxMetadata.AtualizarTabelasRegistradas;
      finally
        lConexao.Free;
      end;

Criando Server HTTP

  FServer := TLmxHttpServer.Create;
  FServer.AdicionarComando(THttpUsuario, '/Usuarios');

Classe Exemplo Http

uses
  System.Classes, 
  uLmxHttpServer, uLmxHelper, uLmxAttributes, uLmx.Context.Usuario, uLmx.Model.Usuario,
  uLmx.Http.Base, uLmxCore;

type

  THttpUsuario = class(THttp<TUsuario,IContextUsuario,TBaseList<TUsuario>>);

Exemplo Context

uses
  System.Classes, 
  System.SysUtils, 
  Generics.Collections,
  uLmxInterfaces,
  uLmx.Context.DataBase,
  uLmxHelper,
  uLmxCore,
  uLmx.Model.Usuario;

type

  IContextUsuario = interface(IContextDataBase<TUsuario>)
    ['{C783A57C-B5B6-42E8-A466-9075583DE035}']
  end;
  
  TContextUsuario = class(TContextDataBase<TUsuario>, IContextUsuario);

Exemplo Gerador de Consulta

TLmxGeradorConsultaUsuario = class(TLmxGeradorConsulta)
  public
    procedure DoGerarConsulta; override;
  end;

procedure TLmxGeradorConsultaUsuario.DoGerarConsulta;
begin
  inherited;
  From('usuario');
  AddCampo('usuario', '*');
  AddCampoCalculado('0', 'teste');
end;

lmxpackage's People

Contributors

luizsfolia avatar luizsfoliatmr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.