├── .gitignore ├── LICENSE ├── README.md ├── Sample ├── ActiveRecord_Builder │ ├── .gitignore │ ├── BoasPraticasCRUD_N3.res │ ├── ProjectGroup1.groupproj │ ├── SimpleORM_Intensive.res │ ├── boss-lock.json │ ├── boss.json │ ├── controller │ │ ├── intensive.Controller.Interfaces.pas │ │ └── intensive.Controller.pas │ ├── database │ │ └── Dados.sdb │ ├── dto │ │ ├── intensive.Controller.DTO.Cliente.pas │ │ └── intensive.Controller.DTO.Interfaces.pas │ ├── intensive.dpr │ ├── intensive.dproj │ ├── intensive.res │ ├── model │ │ └── entity │ │ │ └── intensive.Model.Entity.Cliente.pas │ ├── resources │ │ ├── intensive.Resources.Conexao.pas │ │ └── intensive.Resources.Interfaces.pas │ ├── services │ │ └── intensive.Services.Generic.pas │ └── view │ │ ├── intensive.View.Principal.dfm │ │ ├── intensive.View.Principal.pas │ │ ├── intensive.view.Editar.dfm │ │ └── intensive.view.Editar.pas ├── Database │ ├── PDVUPDATES.FDB │ └── RTTI.FDB ├── Entidades │ └── Entidade.Pedido.pas ├── FMX │ ├── Principal.fmx │ ├── Principal.pas │ ├── Principal.vlb │ ├── SimpleOrmFmx.dpr │ ├── SimpleOrmFmx.dproj │ ├── SimpleOrmFmx.res │ └── SimpleOrmFmx.skincfg ├── Firedac │ ├── Principal.dfm │ ├── Principal.pas │ ├── SimpleORMFiredac.dpr │ ├── SimpleORMFiredac.dproj │ ├── SimpleORMFiredac.res │ ├── pessoa.interfaces.pas │ └── pessoa.pas ├── RestDW │ ├── SimpleORM_RestDW.dpr │ ├── SimpleORM_RestDW.dproj │ ├── SimpleORM_RestDW.res │ ├── Unit8.dfm │ └── Unit8.pas ├── Unidac │ ├── Principal.dfm │ ├── Principal.pas │ ├── SimpleORMUnidac.dpr │ ├── SimpleORMUnidac.dproj │ ├── SimpleORMUnidac.res │ └── SimpleORMUnidac.skincfg ├── Validation │ ├── Base │ │ └── View │ │ │ ├── ufBase.dfm │ │ │ └── ufBase.pas │ ├── Entidade │ │ └── Entidade.Cliente.pas │ ├── Export │ │ └── uExport.pas │ ├── SimpleORMValidation.dpr │ ├── SimpleORMValidation.dproj │ ├── SimpleORMValidation.res │ └── View │ │ ├── ufCliente.dfm │ │ └── ufCliente.pas └── horse │ ├── Controller │ └── Controller.Produto.pas │ ├── DataSetConverter4D.Helper.pas │ ├── DataSetConverter4D.Impl.pas │ ├── DataSetConverter4D.Util.pas │ ├── DataSetConverter4D.pas │ ├── Model │ ├── Connection │ │ ├── Model.Connection.pas │ │ └── Model.DaoGeneric.pas │ ├── Entity │ │ └── Model.Entity.Produto.pas │ └── Model.DaoGeneric.pas │ ├── Project1.res │ ├── SimpleORMHorse.dpr │ ├── SimpleORMHorse.dproj │ ├── SimpleORMHorse.dproj.local │ ├── SimpleORMHorse.identcache │ ├── SimpleORMHorse.res │ ├── boss-lock.json │ └── boss.json ├── SimpleAttributes.pas ├── SimpleDAO.DataSetToJSON.pas ├── SimpleDAO.pas ├── SimpleDAOSQLAttribute.pas ├── SimpleEntity.pas ├── SimpleInterface.pas ├── SimpleJSON.pas ├── SimpleJSONUtil.pas ├── SimpleORM.dpk ├── SimpleORM.dpr ├── SimpleORM.dproj ├── SimpleORM.res ├── SimpleORM_Group.groupproj ├── SimpleQueryFiredac.pas ├── SimpleQueryRestDW.pas ├── SimpleQueryUnidac.pas ├── SimpleQueryZeos.pas ├── SimpleRTTI.pas ├── SimpleRTTIHelper.pas ├── SimpleSQL.pas ├── SimpleTypes.pas ├── SimpleUtil.pas ├── SimpleValidator.pas ├── assets ├── logo.fw.png ├── logo2.jpg └── logo_2.fw.png ├── boss.json └── public └── logo.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Uncomment these types if you want even more clean repository. But be careful. 2 | # It can make harm to an existing project source. Read explanations below. 3 | # 4 | # Resource files are binaries containing manifest, project icon and version info. 5 | # They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files. 6 | #*.res 7 | # 8 | # Type library file (binary). In old Delphi versions it should be stored. 9 | # Since Delphi 2009 it is produced from .ridl file and can safely be ignored. 10 | #*.tlb 11 | # 12 | # Diagram Portfolio file. Used by the diagram editor up to Delphi 7. 13 | # Uncomment this if you are not using diagrams or use newer Delphi version. 14 | #*.ddp 15 | # 16 | # Visual LiveBindings file. Added in Delphi XE2. 17 | # Uncomment this if you are not using LiveBindings Designer. 18 | #*.vlb 19 | # 20 | # Deployment Manager configuration file for your project. Added in Delphi XE2. 21 | # Uncomment this if it is not mobile development and you do not use remote debug feature. 22 | #*.deployproj 23 | # 24 | # C++ object files produced when C/C++ Output file generation is configured. 25 | # Uncomment this if you are not using external objects (zlib library for example). 26 | #*.obj 27 | # 28 | 29 | # Delphi compiler-generated binaries (safe to delete) 30 | *.exe 31 | *.dll 32 | *.bpl 33 | *.bpi 34 | *.dcp 35 | *.so 36 | *.apk 37 | *.drc 38 | *.map 39 | *.dres 40 | *.rsm 41 | *.tds 42 | *.dcu 43 | *.lib 44 | *.a 45 | *.o 46 | *.ocx 47 | 48 | # Delphi autogenerated files (duplicated info) 49 | *.cfg 50 | *.hpp 51 | *Resource.rc 52 | 53 | # Delphi local files (user-specific info) 54 | *.local 55 | *.identcache 56 | *.projdata 57 | *.tvsconfig 58 | *.dsk 59 | 60 | # Delphi history and backups 61 | __history/ 62 | __recovery/ 63 | *.~* 64 | 65 | # Castalia statistics file (since XE7 Castalia is distributed with Delphi) 66 | *.stat 67 | 68 | *.bin -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Thulio Bittencourt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Logo da Minha Empresa](./public/logo.png) 2 | # SimpleORM 3 | ORM Simples para Aplicações Delphi 4 | 5 | O SimpleORM tem o Objetivo de facilitar suas implementações de CRUD, agilizando mais de 80% do seu processo de desenvolvimento de software. 6 | 7 | Homologado para os drivers de Conexão Firedac e RestDataware. 8 | 9 | #### Link do Grupo no Telegram 10 | [Grupo SimpleORM](https://t.me/joinchat/Tv8fVFe_hdz0rJwq) 11 | 12 | #### Gerador de Classes para o SimpleORM criados pela Comunidade 13 | 14 | [andersonlugarinhoramos](https://github.com/andersonlugarinhoramos/geradorsimpleorm)
15 | [alan-petry](https://github.com/alan-petry/GeraClassesSimpleORM)
16 | [Douglas09](https://github.com/Douglas09/GeradorDeClasses_SimpleORM_MySql)
17 | 18 | Entidade do Banco de Dados Mapeada 19 | 20 | ```delphi 21 | uses 22 | SimpleAttributes; 23 | 24 | Type 25 | [Tabela('PEDIDO')] 26 | TPEDIDO = class 27 | private 28 | FID: Integer; 29 | FCLIENTE: String; 30 | FDATAPEDIDO: TDatetime; 31 | FVALORTOTAL: Currency; 32 | procedure SetID(const Value: Integer); 33 | procedure SetCLIENTE(const Value: String); 34 | procedure SetDATAPEDIDO(const Value: TDatetime); 35 | procedure SetVALORTOTAL(const Value: Currency); 36 | public 37 | constructor Create; 38 | destructor Destroy; override; 39 | published 40 | [Campo('ID'), Pk, AutoInc] 41 | property ID: Integer read FID write SetID; 42 | [Campo('NOME')] 43 | property CLIENTE: String read FCLIENTE write SetCLIENTE; 44 | [Campo('DATA')] 45 | property DATAPEDIDO: TDatetime read FDATAPEDIDO write SetDATAPEDIDO; 46 | [Campo('VALOR')] 47 | property VALORTOTAL: Currency read FVALORTOTAL write SetVALORTOTAL; 48 | end; 49 | ``` 50 | 51 | Obs.: Em casos como o "Campo('ID')" a anotação é opcional, pois a `property` tem o mesmo nome do campo no banco de dados. 52 | 53 | ## Atributos 54 | `Tabela` - Informa o Nome da Tabela no Banco em que a Classe faz o mapeamento. 55 | 56 | `Campo` - Informa o Nome do Campo no Banco de Dados em que a property está fazendo Referência. 57 | 58 | `PK` - Informa se o Campo é PrimaryKey. 59 | 60 | `FK` - Informa se o Campo é ForeignKey. 61 | 62 | `NotNull` - Informa se o Campo é NotNull. 63 | 64 | `Ignore` - Ignorar o Campo nas Operações de CRUD. 65 | 66 | `AutoInc` - Informa se o Campo é AutoIncremento. 67 | 68 | `NumberOnly` - Informa se o Campo deve aceitar somente números. 69 | 70 | `Bind` - Informa o Nome do Campo no Banco de Dados ou a `property` que o componente visual está fazendo Referência. 71 | 72 | `Display` - Informa a descrição que deve aparecer no título de grids. 73 | 74 | `Format` - Informa o formato que o campo deve ter, coisas como (tamanho, precisão, máscara e range). 75 | 76 | # Principais Operações 77 | 78 | 79 | ## Instalação 80 | 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. 81 | 82 | ## Uses Necessárias 83 | 84 | SimpleInterface, 85 | 86 | SimpleDAO, 87 | 88 | SimpleAttributes, 89 | 90 | `Dependendo do seu driver de Conexão utilizar as Uses` SimpleQueryFiredac ou SimpleQueryRestDW 91 | 92 | ## Inicialização do SimpleORM 93 | 94 | ```delphi 95 | var 96 | Conn : iSimpleQuery; 97 | DAOPedido : iSimpleDAO; 98 | begin 99 | Conn := TSimpleQueryFiredac.New(FDConnection1); 100 | DAOPedido := TSimpleDAO 101 | .New(Conn) 102 | .DataSource(DataSource1) 103 | .BindForm(Self); 104 | end; 105 | ``` 106 | 107 | `Conn` - Instancia a Interface iSimpleQuery passando o componente de conexão que o SimpleORM irá trabalhar. 108 | 109 | `DAOPedido` - Instância o DAO para uma Entidade Mapeada, passando a Classe de Mapeamento como Atributo Genérico. 110 | 111 | `New` - Recebe a Interface de Conexão iSimpleQuery. 112 | 113 | `DataSource`- Você pode informar um DataSource para que os dados sejam armazenados nele para facilitar seu processo de listagem de dados, podem linkar ao DBGrid para exibição dos mesmos. 114 | 115 | `Bind` - Você pode informar o formulário que deseja que o SimpleORM faça o Bind automatico entre a Classe e os Componentes da tela (Edit, Combo, CheckBox, RadioButton e etc...) 116 | 117 | 118 | ## MAPEAMENTO DO BIND DO FORMULÁRIO 119 | Quando você fizer o mapeamento Bind do Formulário, não precisará ligar manualmente os campos da classe ao Edits, o SimpleORM faz isso automáticamente, basta você realizar o mapeamento correto conforme abaixo. 120 | 121 | ```delphi 122 | type 123 | TForm1 = class(TForm) 124 | [Bind('CLIENTE')] 125 | Edit1: TEdit; 126 | [Bind('ID')] 127 | Edit2: TEdit; 128 | [Bind('VALORTOTAL')] 129 | Edit3: TEdit; 130 | Button2: TButton; 131 | [Bind('DATAPEDIDO')] 132 | DateTimePicker1: TDateTimePicker; 133 | ``` 134 | 135 | No atributo Bind de cada campo, você deve informar o nome da Property correspondente na Classe Mapeada do banco de dados ou o nome do campo na tabela do banco de dados, ATENÇÃO de qualquer forma a Classe deve estar mapeada corretamente. 136 | 137 | ## INSERT COM BIND 138 | 139 | ```delphi 140 | begin 141 | DAOPedido.Insert; 142 | end; 143 | ``` 144 | 145 | ## INSERT COM OBJETO 146 | ```delphi 147 | var 148 | Pedido : TPEDIDO; 149 | begin 150 | Pedido := TPEDIDO.Create; 151 | try 152 | Pedido.ID := StrToInt(Edit2.Text); 153 | Pedido.CLIENTE := Edit1.Text; 154 | Pedido.DATAPEDIDO := now; 155 | Pedido.VALORTOTAL := StrToCurr(Edit3.Text); 156 | DAOPedido.Insert(Pedido); 157 | finally 158 | Pedido.Free; 159 | end; 160 | end; 161 | ``` 162 | 163 | ## INSERT COM OBJETO HERDADO DE `TSimpleEntity` E COM VALIDAÇÃO 164 | ```delphi 165 | var 166 | Cliente: TCliente; 167 | begin 168 | Cliente := TCliente.Create; 169 | try 170 | // PEGA OS VALORES DA TELA E PREENCHE O OBJETO VIA BIND 171 | Cliente.Parse(Self); 172 | 173 | // VALIDA SEGUNDO ANOTAÇÕES DO OBJETO 174 | TSimpleValidator.Validate(Cliente); 175 | 176 | // INSERE "CLIENTE" NO BANCO DE DADOS 177 | DAOCliente.Insert(Cliente); 178 | finally 179 | Cliente.Free; 180 | end; 181 | end; 182 | ``` 183 | 184 | ## UPDATE COM BIND 185 | ```delphi 186 | begin 187 | DAOPedido.Update; 188 | end; 189 | ``` 190 | 191 | ## UPDATE COM OBJETO 192 | ```delphi 193 | var 194 | Pedido : TPEDIDO; 195 | begin 196 | Pedido := TPEDIDO.Create; 197 | try 198 | Pedido.ID := StrToInt(Edit2.Text); 199 | Pedido.CLIENTE := Edit1.Text; 200 | Pedido.DATAPEDIDO := now; 201 | Pedido.VALORTOTAL := StrToCurr(Edit3.Text); 202 | DAOPedido.Update(Pedido); 203 | finally 204 | Pedido.Free; 205 | end; 206 | end; 207 | ``` 208 | 209 | ## UPDATE COM OBJETO HERDADO DE `TSimpleEntity` E COM VALIDAÇÃO 210 | ```delphi 211 | var 212 | Cliente: TCliente; 213 | begin 214 | Cliente := TCliente.Create; 215 | try 216 | Cliente.Parse(Self); 217 | TSimpleValidator.Validate(Cliente); 218 | DAOCliente.Update(Cliente); 219 | finally 220 | Cliente.Free; 221 | end; 222 | end; 223 | ``` 224 | 225 | ## DELETE COM BIND 226 | ```delphi 227 | begin 228 | DAOPedido.Delete; 229 | end; 230 | ``` 231 | 232 | ## DELETE COM OBJETO 233 | ```delphi 234 | var 235 | Pedido : TPEDIDO; 236 | begin 237 | Pedido := TPEDIDO.Create; 238 | try 239 | Pedido.ID := StrToInt(Edit2.Text); 240 | DAOPedido.Delete(Pedido); 241 | finally 242 | Pedido.Free; 243 | end; 244 | end; 245 | ``` 246 | 247 | ## SELECT 248 | Você pode executar desde operações simples como trazer todos os dados da tabela, como filtrar campos e outras instruções SQL, 249 | 250 | executando a instrução abaixo você retornará todos os dados da tabela 251 | ```delphi 252 | DAOPedido.Find; 253 | ``` 254 | 255 | Abaixo um exemplo de todas as operações possíveis no SimpleORM 256 | ```delphi 257 | begin 258 | DAOPedido 259 | .SQL 260 | .Fields('Informe os Campos que deseja trazer separados por virgula') 261 | .Join('Informe a Instrução Join que desejar ex INNER JOIN CLIENTE ON CLIENTE.ID = PRODUTO.CLIENTE') 262 | .Where('Coloque a Clausula Where que desejar ex: CODIGO = 1') 263 | .OrderBy('Informe o nome do Campo que deseja ordenar ex: ID') 264 | .GroupBy('Informe os campos que deseja agrupar separados por virgula') 265 | .&End 266 | .Find; 267 | end; 268 | ``` 269 | 270 | Você também pode retornar uma Lista de Objetos para trabalhar com ela manualmente, abaixo um exemplo de como trazer a lista e trabalhar com ela exibindo todos os valores em um Memo 271 | ```delphi 272 | var 273 | Pedidos : TObjectList; 274 | Pedido : TPEDIDO; 275 | begin 276 | Pedidos := TObjectList.Create; 277 | DAOPedido.Find(Pedidos); 278 | try 279 | for Pedido in Pedidos do 280 | begin 281 | Memo1.Lines.Add(Pedido.CLIENTE + DateToStr(Pedido.DATAPEDIDO)); 282 | end; 283 | finally 284 | Pedidos.Free; 285 | end; 286 | end; 287 | ``` 288 | 289 | ## Grupo do telegram 290 | Esse grupo tem como objetivo ajudar seus integrantes em assuntos diversos ao uso do componente, e colaboração para a evolução desse maravilhoso ORM ([Object-relational mapping](https://pt.wikipedia.org/wiki/Mapeamento_objeto-relacional)). 291 | Acesse com esse link para participar do [Grupo SimpleORM](https://t.me/joinchat/Tv8fVFe_hdz0rJwq) 292 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/delphi 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=delphi 4 | 5 | ### Delphi ### 6 | # Uncomment these types if you want even more clean repository. But be careful. 7 | # It can make harm to an existing project source. Read explanations below. 8 | # 9 | # Resource files are binaries containing manifest, project icon and version info. 10 | # They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files. 11 | #*.res 12 | # Type library file (binary). In old Delphi versions it should be stored. 13 | # Since Delphi 2009 it is produced from .ridl file and can safely be ignored. 14 | #*.tlb 15 | # Diagram Portfolio file. Used by the diagram editor up to Delphi 7. 16 | # Uncomment this if you are not using diagrams or use newer Delphi version. 17 | #*.ddp 18 | # Visual LiveBindings file. Added in Delphi XE2. 19 | # Uncomment this if you are not using LiveBindings Designer. 20 | #*.vlb 21 | # Deployment Manager configuration file for your project. Added in Delphi XE2. 22 | # Uncomment this if it is not mobile development and you do not use remote debug feature. 23 | #*.deployproj 24 | # C++ object files produced when C/C++ Output file generation is configured. 25 | # Uncomment this if you are not using external objects (zlib library for example). 26 | #*.obj 27 | 28 | # Delphi compiler-generated binaries (safe to delete) 29 | *.exe 30 | *.dll 31 | *.bpl 32 | *.bpi 33 | *.dcp 34 | *.so 35 | *.apk 36 | *.drc 37 | *.map 38 | *.dres 39 | *.rsm 40 | *.tds 41 | *.dcu 42 | *.lib 43 | *.a 44 | *.o 45 | *.ocx 46 | 47 | # Delphi autogenerated files (duplicated info) 48 | *.cfg 49 | *.hpp 50 | *Resource.rc 51 | 52 | # Delphi local files (user-specific info) 53 | *.local 54 | *.identcache 55 | *.projdata 56 | *.tvsconfig 57 | *.dsk 58 | 59 | # Delphi history and backups 60 | __history/ 61 | __recovery/ 62 | *.~* 63 | 64 | # Castalia statistics file (since XE7 Castalia is distributed with Delphi) 65 | *.stat 66 | 67 | # Boss dependency manager vendor folder https://github.com/HashLoad/boss 68 | modules/ 69 | 70 | # End of https://www.toptal.com/developers/gitignore/api/delphi -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/BoasPraticasCRUD_N3.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/ActiveRecord_Builder/BoasPraticasCRUD_N3.res -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/ProjectGroup1.groupproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {E28206FD-740A-41A1-BC73-8405921ED818} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Default.Personality.12 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/SimpleORM_Intensive.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/ActiveRecord_Builder/SimpleORM_Intensive.res -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/boss-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "hash": "bdfab74a412f12cca3751da9a4bbae0d", 3 | "updated": "2021-08-23T14:05:49.4408687-03:00", 4 | "installedModules": { 5 | "https://github.com/bittencourtthulio/simpleorm": { 6 | "name": "simpleorm", 7 | "version": "2.02.05", 8 | "hash": "0f928cee8a18de82e3f88a4f3411e98f", 9 | "artifacts": {}, 10 | "failed": false, 11 | "changed": false 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/boss.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BoasPraticasCRUDNivel3", 3 | "description": "", 4 | "version": "1.0.0", 5 | "homepage": "", 6 | "mainsrc": "./", 7 | "projects": [], 8 | "dependencies": { 9 | "https://github.com/bittencourtthulio/simpleorm": "^2.02.04" 10 | } 11 | } -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/controller/intensive.Controller.Interfaces.pas: -------------------------------------------------------------------------------- 1 | unit intensive.Controller.Interfaces; 2 | 3 | interface 4 | 5 | uses 6 | FireDAC.Stan.Intf, 7 | FireDAC.Stan.Option, 8 | FireDAC.Stan.Error, 9 | FireDAC.UI.Intf, 10 | FireDAC.Phys.Intf, 11 | FireDAC.Stan.Def, 12 | FireDAC.Stan.Pool, 13 | FireDAC.Stan.Async, 14 | FireDAC.Phys, 15 | FireDAC.Phys.SQLite, 16 | FireDAC.Phys.SQLiteDef, 17 | FireDAC.Stan.ExprFuncs, 18 | FireDAC.Phys.SQLiteWrapper.Stat, 19 | FireDAC.VCLUI.Wait, 20 | FireDAC.Comp.UI, 21 | Data.DB, 22 | FireDAC.Comp.Client, intensive.Controller.DTO.Interfaces; 23 | 24 | type 25 | iController = interface 26 | function Cliente : iClienteDTO; 27 | end; 28 | 29 | implementation 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/controller/intensive.Controller.pas: -------------------------------------------------------------------------------- 1 | unit intensive.Controller; 2 | 3 | interface 4 | 5 | uses 6 | FireDAC.Stan.Intf, 7 | FireDAC.Stan.Option, 8 | FireDAC.Stan.Error, 9 | FireDAC.UI.Intf, 10 | FireDAC.Phys.Intf, 11 | FireDAC.Stan.Def, 12 | FireDAC.Stan.Pool, 13 | FireDAC.Stan.Async, 14 | FireDAC.Phys, 15 | FireDAC.Phys.SQLite, 16 | FireDAC.Phys.SQLiteDef, 17 | FireDAC.Stan.ExprFuncs, 18 | FireDAC.Phys.SQLiteWrapper.Stat, 19 | FireDAC.VCLUI.Wait, 20 | FireDAC.Comp.UI, 21 | Data.DB, 22 | FireDAC.Comp.Client, 23 | intensive.Controller.Interfaces, 24 | intensive.Model.Entity.Cliente, intensive.Services.Generic, 25 | intensive.Controller.DTO.Interfaces, intensive.Controller.DTO.Cliente; 26 | 27 | type 28 | TController = class(TInterfacedObject, iController) 29 | private 30 | FCliente : iClienteDTO; 31 | public 32 | constructor Create; 33 | destructor Destroy; override; 34 | class function New : iController; 35 | function Cliente : iClienteDTO; 36 | end; 37 | 38 | implementation 39 | 40 | constructor TController.Create; 41 | begin 42 | 43 | end; 44 | 45 | destructor TController.Destroy; 46 | begin 47 | 48 | inherited; 49 | end; 50 | 51 | class function TController.New : iController; 52 | begin 53 | Result := Self.Create; 54 | end; 55 | 56 | function TController.Cliente: iClienteDTO; 57 | begin 58 | if not Assigned(FCliente) then 59 | FCliente := TClienteDTO.New; 60 | Result := FCliente; 61 | end; 62 | 63 | end. 64 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/database/Dados.sdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/ActiveRecord_Builder/database/Dados.sdb -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/dto/intensive.Controller.DTO.Cliente.pas: -------------------------------------------------------------------------------- 1 | unit intensive.Controller.DTO.Cliente; 2 | 3 | interface 4 | 5 | uses 6 | FireDAC.Stan.Intf, 7 | FireDAC.Stan.Option, 8 | FireDAC.Stan.Error, 9 | FireDAC.UI.Intf, 10 | FireDAC.Phys.Intf, 11 | FireDAC.Stan.Def, 12 | FireDAC.Stan.Pool, 13 | FireDAC.Stan.Async, 14 | FireDAC.Phys, 15 | FireDAC.Phys.SQLite, 16 | FireDAC.Phys.SQLiteDef, 17 | FireDAC.Stan.ExprFuncs, 18 | FireDAC.Phys.SQLiteWrapper.Stat, 19 | FireDAC.VCLUI.Wait, 20 | FireDAC.Comp.UI, 21 | Data.DB, 22 | FireDAC.Comp.Client, 23 | intensive.Model.Entity.Cliente, 24 | intensive.Controller.DTO.Interfaces, 25 | intensive.Services.Generic; 26 | 27 | type 28 | TClienteDTO = class(TInterfacedObject, iClienteDTO) 29 | private 30 | FEntity : TCliente; 31 | FService : iService; 32 | public 33 | constructor Create; 34 | destructor Destroy; override; 35 | class function New : iClienteDTO; 36 | function Id(Value : Integer) : iClienteDTO; overload; 37 | function Id : Integer; overload; 38 | function Nome(Value : String) : iClienteDTO; overload; 39 | function Nome : String; overload; 40 | function Telefone(Value : String) : iClienteDTO; overload; 41 | function Telefone : String; overload; 42 | function Build : iService; 43 | end; 44 | 45 | implementation 46 | 47 | function TClienteDTO.Build: iService; 48 | begin 49 | Result := FSErvice; 50 | end; 51 | 52 | constructor TClienteDTO.Create; 53 | begin 54 | FEntity := TCliente.Create; 55 | FService := TService.New(FEntity); 56 | end; 57 | 58 | destructor TClienteDTO.Destroy; 59 | begin 60 | FEntity.DisposeOf; 61 | inherited; 62 | end; 63 | 64 | function TClienteDTO.Id: Integer; 65 | begin 66 | Result := FEntity.Id; 67 | end; 68 | 69 | function TClienteDTO.Id(Value: Integer): iClienteDTO; 70 | begin 71 | Result := Self; 72 | FEntity.Id := Value; 73 | end; 74 | 75 | class function TClienteDTO.New : iClienteDTO; 76 | begin 77 | Result := Self.Create; 78 | end; 79 | 80 | function TClienteDTO.Nome: String; 81 | begin 82 | Result := FEntity.Nome; 83 | end; 84 | 85 | function TClienteDTO.Nome(Value: String): iClienteDTO; 86 | begin 87 | Result := Self; 88 | FEntity.Nome := Value; 89 | end; 90 | 91 | function TClienteDTO.Telefone(Value: String): iClienteDTO; 92 | begin 93 | Result := Self; 94 | FEntity.Telefone := Value; 95 | end; 96 | 97 | function TClienteDTO.Telefone: String; 98 | begin 99 | Result := FEntity.Telefone; 100 | end; 101 | 102 | end. 103 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/dto/intensive.Controller.DTO.Interfaces.pas: -------------------------------------------------------------------------------- 1 | unit intensive.Controller.DTO.Interfaces; 2 | 3 | interface 4 | 5 | uses 6 | intensive.Services.Generic, 7 | intensive.Model.Entity.Cliente; 8 | 9 | type 10 | iClienteDTO = interface 11 | function Id(Value : Integer) : iClienteDTO; overload; 12 | function Id : Integer; overload; 13 | function Nome(Value : String) : iClienteDTO; overload; 14 | function Nome : String; overload; 15 | function Telefone(Value : String) : iClienteDTO; overload; 16 | function Telefone : String; overload; 17 | function Build : iService; 18 | end; 19 | 20 | implementation 21 | 22 | end. 23 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/intensive.dpr: -------------------------------------------------------------------------------- 1 | program intensive; 2 | 3 | uses 4 | Vcl.Forms, 5 | intensive.Model.Entity.Cliente in 'model\entity\intensive.Model.Entity.Cliente.pas', 6 | intensive.Resources.Interfaces in 'resources\intensive.Resources.Interfaces.pas', 7 | intensive.Resources.Conexao in 'resources\intensive.Resources.Conexao.pas', 8 | intensive.Services.Generic in 'services\intensive.Services.Generic.pas', 9 | intensive.view.Editar in 'view\intensive.view.Editar.pas' {frmEditar}, 10 | intensive.View.Principal in 'view\intensive.View.Principal.pas' {frmListarClientes}, 11 | intensive.Controller.DTO.Cliente in 'dto\intensive.Controller.DTO.Cliente.pas', 12 | intensive.Controller in 'controller\intensive.Controller.pas', 13 | intensive.Controller.Interfaces in 'controller\intensive.Controller.Interfaces.pas', 14 | intensive.Controller.DTO.Interfaces in 'dto\intensive.Controller.DTO.Interfaces.pas'; 15 | // intensive.Controller.DTO.Endereco in 'dto\intensive.Controller.DTO.Endereco.pas'; 16 | // intensive.Model.Entity.Endereco in 'model\entity\intensive.Model.Entity.Endereco.pas'; 17 | 18 | {$R *.res} 19 | 20 | begin 21 | Application.Initialize; 22 | Application.MainFormOnTaskbar := True; 23 | Application.CreateForm(TfrmListarClientes, frmListarClientes); 24 | Application.CreateForm(TfrmListarClientes, frmListarClientes); 25 | Application.Run; 26 | end. 27 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/intensive.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/ActiveRecord_Builder/intensive.res -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/model/entity/intensive.Model.Entity.Cliente.pas: -------------------------------------------------------------------------------- 1 | unit intensive.Model.Entity.Cliente; 2 | 3 | interface 4 | 5 | uses 6 | SimpleAttributes; 7 | 8 | type 9 | [Tabela('CLIENTE')] 10 | TCliente = class 11 | private 12 | FId: Integer; 13 | FNome: String; 14 | FTelefone: String; 15 | procedure SetId(const Value: Integer); 16 | procedure SetNome(const Value: String); 17 | procedure SetTelefone(const Value: String); 18 | public 19 | [Campo('ID'), PK, AutoInc] 20 | property Id : Integer read FId write SetId; 21 | [Campo('NOME')] 22 | property Nome : String read FNome write SetNome; 23 | [Campo('TELEFONE')] 24 | property Telefone : String read FTelefone write SetTelefone; 25 | end; 26 | 27 | implementation 28 | 29 | 30 | { TCliente } 31 | 32 | procedure TCliente.SetId(const Value: Integer); 33 | begin 34 | FId := Value; 35 | end; 36 | 37 | procedure TCliente.SetNome(const Value: String); 38 | begin 39 | FNome := Value; 40 | end; 41 | 42 | procedure TCliente.SetTelefone(const Value: String); 43 | begin 44 | FTelefone := Value; 45 | end; 46 | 47 | end. 48 | 49 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/resources/intensive.Resources.Conexao.pas: -------------------------------------------------------------------------------- 1 | unit intensive.Resources.Conexao; 2 | 3 | interface 4 | 5 | uses 6 | FireDAC.Stan.Intf, 7 | FireDAC.Stan.Option, 8 | FireDAC.Stan.Error, 9 | FireDAC.UI.Intf, 10 | FireDAC.Phys.Intf, 11 | FireDAC.Stan.Def, 12 | FireDAC.Stan.Pool, 13 | FireDAC.Stan.Async, 14 | FireDAC.Phys, 15 | FireDAC.Phys.SQLite, 16 | FireDAC.Phys.SQLiteDef, 17 | FireDAC.Stan.ExprFuncs, 18 | FireDAC.Phys.SQLiteWrapper.Stat, 19 | FireDAC.VCLUI.Wait, 20 | FireDAC.Comp.UI, 21 | Data.DB, 22 | FireDAC.Comp.Client, 23 | intensive.Resources.Interfaces; 24 | 25 | type 26 | TConexao = class(TInterfacedObject, iConexao) 27 | private 28 | FConn : TFDConnection; 29 | public 30 | constructor Create; 31 | destructor Destroy; override; 32 | class function New : iConexao; 33 | function Connect : TCustomConnection; 34 | end; 35 | 36 | implementation 37 | 38 | function TConexao.Connect: TCustomConnection; 39 | begin 40 | Result := FConn; 41 | end; 42 | 43 | constructor TConexao.Create; 44 | begin 45 | FConn := TFDConnection.Create(nil); 46 | FConn.Params.Clear; 47 | FConn.Params.Add('DriverID=SQLite'); 48 | FConn.Params.Add('DataBase=..\..\database\Dados.sdb'); 49 | FConn.Params.Add('LockingMode=Normal'); 50 | FConn.Connected := True; 51 | end; 52 | 53 | destructor TConexao.Destroy; 54 | begin 55 | FConn.DisposeOf; 56 | inherited; 57 | end; 58 | 59 | class function TConexao.New : iConexao; 60 | begin 61 | Result := Self.Create; 62 | end; 63 | 64 | end. 65 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/resources/intensive.Resources.Interfaces.pas: -------------------------------------------------------------------------------- 1 | unit intensive.Resources.Interfaces; 2 | 3 | interface 4 | 5 | uses 6 | Data.DB; 7 | 8 | type 9 | iConexao = interface 10 | function Connect : TCustomConnection; 11 | end; 12 | 13 | implementation 14 | 15 | end. 16 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/services/intensive.Services.Generic.pas: -------------------------------------------------------------------------------- 1 | unit intensive.Services.Generic; 2 | 3 | interface 4 | 5 | uses 6 | SimpleInterface, 7 | SimpleDAO, 8 | SimpleAttributes, 9 | SimpleQueryFiredac, 10 | FireDAC.Stan.Intf, 11 | FireDAC.Stan.Option, 12 | FireDAC.Stan.Error, 13 | FireDAC.UI.Intf, 14 | FireDAC.Phys.Intf, 15 | FireDAC.Stan.Def, 16 | FireDAC.Stan.Pool, 17 | FireDAC.Stan.Async, 18 | FireDAC.Phys, 19 | FireDAC.Phys.SQLite, 20 | FireDAC.Phys.SQLiteDef, 21 | FireDAC.Stan.ExprFuncs, 22 | FireDAC.Phys.SQLiteWrapper.Stat, 23 | FireDAC.VCLUI.Wait, 24 | FireDAC.Comp.UI, 25 | Data.DB, 26 | FireDAC.Comp.Client, 27 | intensive.Resources.Interfaces, 28 | intensive.Resources.Conexao, 29 | System.Generics.Collections; 30 | 31 | type 32 | iService = interface 33 | function Listar: TDataSet; 34 | function ListarPorId(Id: Integer): TDataSet; 35 | function ListarPorFiltro(Key: String; Value: Variant): TDataSet; 36 | function Inserir: iService; 37 | function Atualizar: iService; 38 | function Excluir: iService; overload; 39 | function Excluir(Field: String; Value: String): iService; overload; 40 | function DataSource(var aDataSource: TDataSource): iService; 41 | function Entity: T; 42 | end; 43 | 44 | TService = class(TInterfacedObject, iService) 45 | private 46 | FParent: T; 47 | FConexao: iConexao; 48 | FConn: iSimpleQuery; 49 | FDAO: iSimpleDAO; 50 | FDataSource: TDataSource; 51 | public 52 | constructor Create(Parent: T); 53 | destructor Destroy; override; 54 | class function New(Parent: T): iService; 55 | function Listar: TDataSet; 56 | function ListarPorId(Id: Integer): TDataSet; 57 | function ListarPorFiltro(Key: String; Value: Variant): TDataSet; 58 | function Inserir: iService; 59 | function Atualizar: iService; 60 | function Excluir: iService; overload; 61 | function Excluir(Field: String; Value: String): iService; overload; 62 | function DataSource(var aDataSource: TDataSource): iService; 63 | function Entity: T; 64 | end; 65 | 66 | implementation 67 | 68 | function TService.Atualizar: iService; 69 | begin 70 | Result := Self; 71 | FDAO.Update(FParent); 72 | end; 73 | 74 | constructor TService.Create(Parent: T); 75 | begin 76 | FParent := Parent; 77 | FDataSource := TDataSource.Create(nil); 78 | FConexao := TConexao.New; 79 | FConn := TSimpleQueryFiredac.New(TFDConnection(FConexao.Connect)); 80 | FDAO := TSimpleDAO.New(FConn).DataSource(FDataSource); 81 | end; 82 | 83 | function TService.DataSource(var aDataSource: TDataSource): iService; 84 | begin 85 | Result := Self; 86 | aDataSource := FDataSource; 87 | end; 88 | 89 | destructor TService.Destroy; 90 | begin 91 | FDataSource.DisposeOf; 92 | inherited; 93 | end; 94 | 95 | function TService.Excluir: iService; 96 | begin 97 | Result := Self; 98 | FDAO.Delete(FParent); 99 | end; 100 | 101 | function TService.Excluir(Field, Value: String): iService; 102 | begin 103 | Result := Self; 104 | FDAO.Delete(Field, Value); 105 | end; 106 | 107 | function TService.Inserir: iService; 108 | begin 109 | Result := Self; 110 | FDAO.Insert(FParent); 111 | end; 112 | 113 | function TService.Listar: TDataSet; 114 | begin 115 | FDAO.Find; 116 | Result := FDataSource.DataSet; 117 | end; 118 | 119 | function TService.ListarPorFiltro(Key: String; Value: Variant): TDataSet; 120 | begin 121 | FDAO.Find(Key, Value); 122 | Result := FDataSource.DataSet; 123 | end; 124 | 125 | function TService.ListarPorId(Id: Integer): TDataSet; 126 | begin 127 | FDAO.Find(Id); 128 | Result := FDataSource.DataSet; 129 | end; 130 | 131 | class function TService.New(Parent: T): iService; 132 | begin 133 | Result := Self.Create(Parent); 134 | end; 135 | 136 | function TService.Entity: T; 137 | begin 138 | Result := FParent; 139 | end; 140 | 141 | end. 142 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/view/intensive.View.Principal.dfm: -------------------------------------------------------------------------------- 1 | object frmListarClientes: TfrmListarClientes 2 | Left = 0 3 | Top = 0 4 | Caption = 'Listar Clientes' 5 | ClientHeight = 287 6 | ClientWidth = 578 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnCreate = FormCreate 15 | PixelsPerInch = 96 16 | TextHeight = 13 17 | object Panel1: TPanel 18 | Left = 0 19 | Top = 0 20 | Width = 578 21 | Height = 247 22 | Align = alClient 23 | BevelOuter = bvNone 24 | Padding.Left = 5 25 | Padding.Top = 5 26 | Padding.Right = 5 27 | Padding.Bottom = 5 28 | TabOrder = 0 29 | object grdPessoa: TDBGrid 30 | Left = 5 31 | Top = 5 32 | Width = 568 33 | Height = 108 34 | Align = alTop 35 | DataSource = dsCliente 36 | Options = [dgTitles, dgColLines, dgRowLines, dgRowSelect] 37 | TabOrder = 0 38 | TitleFont.Charset = DEFAULT_CHARSET 39 | TitleFont.Color = clWindowText 40 | TitleFont.Height = -11 41 | TitleFont.Name = 'Tahoma' 42 | TitleFont.Style = [] 43 | end 44 | object grdEndereco: TDBGrid 45 | Left = 5 46 | Top = 122 47 | Width = 568 48 | Height = 120 49 | Align = alBottom 50 | DataSource = dsEndereco 51 | TabOrder = 1 52 | TitleFont.Charset = DEFAULT_CHARSET 53 | TitleFont.Color = clWindowText 54 | TitleFont.Height = -11 55 | TitleFont.Name = 'Tahoma' 56 | TitleFont.Style = [] 57 | end 58 | object Panel3: TPanel 59 | Left = 5 60 | Top = 113 61 | Width = 568 62 | Height = 9 63 | Align = alClient 64 | BevelOuter = bvNone 65 | TabOrder = 2 66 | end 67 | end 68 | object Panel2: TPanel 69 | Left = 0 70 | Top = 247 71 | Width = 578 72 | Height = 40 73 | Align = alBottom 74 | BevelOuter = bvNone 75 | TabOrder = 1 76 | object btnNovo: TButton 77 | AlignWithMargins = True 78 | Left = 3 79 | Top = 3 80 | Width = 75 81 | Height = 34 82 | Align = alLeft 83 | Caption = 'Novo' 84 | TabOrder = 0 85 | OnClick = btnNovoClick 86 | end 87 | object btnEditar: TButton 88 | AlignWithMargins = True 89 | Left = 84 90 | Top = 3 91 | Width = 75 92 | Height = 34 93 | Align = alLeft 94 | Caption = 'Editar' 95 | TabOrder = 1 96 | OnClick = btnEditarClick 97 | end 98 | object btnExcluir: TButton 99 | AlignWithMargins = True 100 | Left = 419 101 | Top = 3 102 | Width = 75 103 | Height = 34 104 | Align = alRight 105 | Caption = 'Excluir' 106 | TabOrder = 2 107 | end 108 | object btnListar: TButton 109 | AlignWithMargins = True 110 | Left = 500 111 | Top = 3 112 | Width = 75 113 | Height = 34 114 | Align = alRight 115 | Caption = 'Listar' 116 | TabOrder = 3 117 | OnClick = btnListarClick 118 | end 119 | end 120 | object dsCliente: TDataSource 121 | Left = 440 122 | Top = 40 123 | end 124 | object dsEndereco: TDataSource 125 | Left = 432 126 | Top = 152 127 | end 128 | end 129 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/view/intensive.View.Principal.pas: -------------------------------------------------------------------------------- 1 | unit intensive.View.Principal; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, 7 | Winapi.Messages, 8 | System.SysUtils, 9 | System.Variants, 10 | System.Classes, 11 | Vcl.Graphics, 12 | Vcl.Controls, 13 | Vcl.Forms, 14 | Vcl.Dialogs, 15 | Data.DB, 16 | Vcl.Grids, 17 | Vcl.DBGrids, 18 | Vcl.StdCtrls, 19 | Vcl.Buttons, 20 | Datasnap.DBClient, 21 | Vcl.ExtCtrls, 22 | intensive.View.Editar, intensive.Controller.Interfaces, intensive.Controller; 23 | 24 | type 25 | TfrmListarClientes = class(TForm) 26 | dsCliente: TDataSource; 27 | Panel1: TPanel; 28 | grdPessoa: TDBGrid; 29 | Panel2: TPanel; 30 | btnNovo: TButton; 31 | btnEditar: TButton; 32 | btnExcluir: TButton; 33 | btnListar: TButton; 34 | grdEndereco: TDBGrid; 35 | Panel3: TPanel; 36 | dsEndereco: TDataSource; 37 | procedure btnNovoClick(Sender: TObject); 38 | procedure FormCreate(Sender: TObject); 39 | procedure btnListarClick(Sender: TObject); 40 | procedure btnEditarClick(Sender: TObject); 41 | private 42 | FController : iController; 43 | public 44 | { Public declarations } 45 | end; 46 | 47 | var 48 | frmListarClientes: TfrmListarClientes; 49 | 50 | implementation 51 | 52 | {$R *.dfm} 53 | 54 | 55 | procedure TfrmListarClientes.btnEditarClick(Sender: TObject); 56 | begin 57 | // try 58 | // frmEditar := TfrmEditar.Create(self, dsEndereco); 59 | // frmEditar.ShowModal; 60 | // finally 61 | // frmEditar.Destroy; 62 | // end; 63 | end; 64 | 65 | procedure TfrmListarClientes.btnListarClick(Sender: TObject); 66 | begin 67 | dsCliente.DataSet := FController.Cliente.Build.Listar; 68 | // dsEndereco.DataSet := FController.Endereco 69 | // .Build.ListarPorFiltro('ID_CLIENTE',dsCliente.DataSet.FieldByName('ID').AsInteger); 70 | end; 71 | 72 | procedure TfrmListarClientes.btnNovoClick(Sender: TObject); 73 | begin 74 | try 75 | frmEditar := TfrmEditar.Create(self, dsCliente, false); 76 | frmEditar.ShowModal; 77 | finally 78 | frmEditar.Destroy; 79 | end; 80 | end; 81 | 82 | procedure TfrmListarClientes.FormCreate(Sender: TObject); 83 | begin 84 | FController := TController.New; 85 | end; 86 | 87 | end. 88 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/view/intensive.view.Editar.dfm: -------------------------------------------------------------------------------- 1 | object frmEditar: TfrmEditar 2 | Left = 0 3 | Top = 0 4 | Caption = 'Editar Cliente' 5 | ClientHeight = 385 6 | ClientWidth = 487 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnDestroy = FormDestroy 15 | PixelsPerInch = 96 16 | TextHeight = 13 17 | object Panel1: TPanel 18 | Left = 0 19 | Top = 0 20 | Width = 487 21 | Height = 342 22 | Align = alClient 23 | BevelOuter = bvNone 24 | TabOrder = 0 25 | object edtNome: TLabeledEdit 26 | Left = 88 27 | Top = 23 28 | Width = 249 29 | Height = 21 30 | EditLabel.Width = 27 31 | EditLabel.Height = 13 32 | EditLabel.Caption = 'Nome' 33 | TabOrder = 0 34 | end 35 | object edtTelefone: TLabeledEdit 36 | Left = 343 37 | Top = 23 38 | Width = 130 39 | Height = 21 40 | EditLabel.Width = 42 41 | EditLabel.Height = 13 42 | EditLabel.Caption = 'Telefone' 43 | TabOrder = 1 44 | end 45 | object edtLogradouro: TLabeledEdit 46 | Left = 16 47 | Top = 71 48 | Width = 362 49 | Height = 21 50 | EditLabel.Width = 55 51 | EditLabel.Height = 13 52 | EditLabel.Caption = 'Logradouro' 53 | TabOrder = 2 54 | end 55 | object edtCep: TLabeledEdit 56 | Left = 384 57 | Top = 71 58 | Width = 89 59 | Height = 21 60 | EditLabel.Width = 19 61 | EditLabel.Height = 13 62 | EditLabel.Caption = 'Cep' 63 | TabOrder = 3 64 | end 65 | object edtBairro: TLabeledEdit 66 | Left = 16 67 | Top = 118 68 | Width = 105 69 | Height = 21 70 | EditLabel.Width = 28 71 | EditLabel.Height = 13 72 | EditLabel.Caption = 'Bairro' 73 | TabOrder = 4 74 | end 75 | object edtCidade: TLabeledEdit 76 | Left = 127 77 | Top = 118 78 | Width = 276 79 | Height = 21 80 | EditLabel.Width = 33 81 | EditLabel.Height = 13 82 | EditLabel.Caption = 'Cidade' 83 | TabOrder = 5 84 | end 85 | object edtEstado: TLabeledEdit 86 | Left = 409 87 | Top = 118 88 | Width = 64 89 | Height = 21 90 | EditLabel.Width = 33 91 | EditLabel.Height = 13 92 | EditLabel.Caption = 'Estado' 93 | TabOrder = 6 94 | end 95 | object grdEnderecos: TDBGrid 96 | Left = 0 97 | Top = 160 98 | Width = 487 99 | Height = 182 100 | Align = alBottom 101 | BorderStyle = bsNone 102 | DataSource = dsEndereco 103 | Options = [dgTitles, dgColLines, dgRowLines, dgRowSelect] 104 | TabOrder = 7 105 | TitleFont.Charset = DEFAULT_CHARSET 106 | TitleFont.Color = clWindowText 107 | TitleFont.Height = -11 108 | TitleFont.Name = 'Tahoma' 109 | TitleFont.Style = [] 110 | OnCellClick = grdEnderecosCellClick 111 | end 112 | object edtId: TLabeledEdit 113 | Left = 16 114 | Top = 23 115 | Width = 66 116 | Height = 21 117 | EditLabel.Width = 11 118 | EditLabel.Height = 13 119 | EditLabel.Caption = 'ID' 120 | TabOrder = 8 121 | end 122 | end 123 | object Panel3: TPanel 124 | Left = 0 125 | Top = 342 126 | Width = 487 127 | Height = 43 128 | Align = alBottom 129 | BevelOuter = bvNone 130 | TabOrder = 1 131 | object btnSalvar: TButton 132 | AlignWithMargins = True 133 | Left = 328 134 | Top = 3 135 | Width = 75 136 | Height = 37 137 | Align = alRight 138 | Caption = 'Salvar' 139 | TabOrder = 0 140 | OnClick = btnSalvarClick 141 | end 142 | object btnCancelar: TButton 143 | AlignWithMargins = True 144 | Left = 409 145 | Top = 3 146 | Width = 75 147 | Height = 37 148 | Align = alRight 149 | Caption = 'Cancelar' 150 | TabOrder = 1 151 | end 152 | end 153 | object dsEndereco: TDataSource 154 | Left = 408 155 | Top = 216 156 | end 157 | end 158 | -------------------------------------------------------------------------------- /Sample/ActiveRecord_Builder/view/intensive.view.Editar.pas: -------------------------------------------------------------------------------- 1 | unit intensive.view.Editar; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 | Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Data.DB, 8 | Vcl.Grids, Vcl.DBGrids, intensive.Controller.Interfaces, 9 | intensive.Controller; 10 | 11 | type 12 | TfrmEditar = class(TForm) 13 | Panel1: TPanel; 14 | Panel3: TPanel; 15 | btnSalvar: TButton; 16 | btnCancelar: TButton; 17 | edtNome: TLabeledEdit; 18 | edtTelefone: TLabeledEdit; 19 | edtLogradouro: TLabeledEdit; 20 | edtCep: TLabeledEdit; 21 | edtBairro: TLabeledEdit; 22 | edtCidade: TLabeledEdit; 23 | edtEstado: TLabeledEdit; 24 | grdEnderecos: TDBGrid; 25 | dsEndereco: TDataSource; 26 | edtId: TLabeledEdit; 27 | procedure FormDestroy(Sender: TObject); 28 | procedure btnSalvarClick(Sender: TObject); 29 | procedure grdEnderecosCellClick(Column: TColumn); 30 | private 31 | FEditar : Boolean; 32 | FDts : TDataSource; 33 | FController : iController; 34 | 35 | procedure FillFields; 36 | public 37 | constructor Create(AOwner: TComponent; aDataSource: TDataSource; 38 | aEditar: Boolean = true); 39 | end; 40 | 41 | var 42 | frmEditar: TfrmEditar; 43 | 44 | implementation 45 | 46 | {$R *.dfm} 47 | 48 | { TfrmEditar } 49 | 50 | procedure TfrmEditar.btnSalvarClick(Sender: TObject); 51 | begin 52 | FController.Cliente 53 | .Nome(edtNome.Text) 54 | .Telefone(edtTelefone.Text) 55 | .Build.Inserir; 56 | // FController.Endereco 57 | // .IdCliente(FController.Cliente.Id) 58 | // .Logradouro(edtLogradouro.Text) 59 | // .Cep(edtCep.Text) 60 | // .Bairro(edtBairro.Text) 61 | // .Cidade(edtCidade.Text) 62 | // .Estado(edtEstado.Text) 63 | // .Build.Inserir; 64 | FillFields; 65 | end; 66 | 67 | constructor TfrmEditar.Create(AOwner: TComponent; aDataSource: TDataSource; 68 | aEditar: Boolean = true); 69 | begin 70 | inherited Create(AOwner); 71 | FDts := TDataSource.Create(nil); 72 | Fdts := aDataSource; 73 | FEditar := aEditar; 74 | if aEditar then 75 | begin 76 | edtNome.Text := FDts.DataSet.FieldByName('NOME').AsString; 77 | edtTelefone.Text := FDts.DataSet.FieldByName('TELEFONE').AsString; 78 | end; 79 | FController := TController.New; 80 | end; 81 | 82 | procedure TfrmEditar.grdEnderecosCellClick(Column: TColumn); 83 | begin 84 | edtLogradouro.Text := dsEndereco.DataSet.FieldByName('LOGRADOURO').AsString; 85 | edtCep.Text := dsEndereco.DataSet.FieldByName('CEP').AsString; 86 | edtBairro.Text := dsEndereco.DataSet.FieldByName('BAIRRO').AsString; 87 | edtCidade.Text := dsEndereco.DataSet.FieldByName('CIDADE').AsString; 88 | edtEstado.Text := dsEndereco.DataSet.FieldByName('ESTADO').AsString; 89 | end; 90 | 91 | procedure TfrmEditar.FillFields; 92 | begin 93 | edtid.Text := FController.Cliente.Id.ToString; 94 | edtNome.Text := FController.Cliente.Nome; 95 | edtTelefone.Text := FController.Cliente.Telefone; 96 | // edtLogradouro.Text := FController.Endereco.Logradouro; 97 | // edtCep.Text := FController.Endereco.Cep; 98 | // edtBairro.Text := FController.Endereco.Bairro; 99 | // edtCidade.Text := FController.Endereco.Cidade; 100 | // edtEstado.Text := FController.Endereco.Estado; 101 | // 102 | // dsEndereco.DataSet := FController.Endereco.Build.Listar; 103 | end; 104 | 105 | procedure TfrmEditar.FormDestroy(Sender: TObject); 106 | begin 107 | FDts.DisposeOf; 108 | end; 109 | 110 | end. 111 | -------------------------------------------------------------------------------- /Sample/Database/PDVUPDATES.FDB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/Database/PDVUPDATES.FDB -------------------------------------------------------------------------------- /Sample/Database/RTTI.FDB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/Database/RTTI.FDB -------------------------------------------------------------------------------- /Sample/Entidades/Entidade.Pedido.pas: -------------------------------------------------------------------------------- 1 | unit Entidade.Pedido; 2 | 3 | interface 4 | 5 | uses 6 | SimpleAttributes; 7 | 8 | Type 9 | [Tabela('PEDIDO')] 10 | TPEDIDO = class 11 | private 12 | FID: Integer; 13 | FCLIENTE: String; 14 | FDATAPEDIDO: TDatetime; 15 | FVALORTOTAL: Currency; 16 | procedure SetID(const Value: Integer); 17 | procedure SetCLIENTE(const Value: String); 18 | procedure SetDATAPEDIDO(const Value: TDatetime); 19 | procedure SetVALORTOTAL(const Value: Currency); 20 | public 21 | constructor Create; 22 | destructor Destroy; override; 23 | published 24 | [Campo('ID'), Pk, AutoInc] 25 | property ID: Integer read FID write SetID; 26 | [Campo('NOME')] 27 | property CLIENTE: String read FCLIENTE write SetCLIENTE; 28 | [Campo('DATA')] 29 | property DATAPEDIDO: TDatetime read FDATAPEDIDO write SetDATAPEDIDO; 30 | [Campo('VALOR')] 31 | property VALORTOTAL: Currency read FVALORTOTAL write SetVALORTOTAL; 32 | end; 33 | 34 | implementation 35 | 36 | { TPEDIDO } 37 | 38 | constructor TPEDIDO.Create; 39 | begin 40 | 41 | end; 42 | 43 | destructor TPEDIDO.Destroy; 44 | begin 45 | 46 | inherited; 47 | end; 48 | 49 | procedure TPEDIDO.SetDATAPEDIDO(const Value: TDatetime); 50 | begin 51 | FDATAPEDIDO := Value; 52 | end; 53 | 54 | procedure TPEDIDO.SetID(const Value: Integer); 55 | begin 56 | FID := Value; 57 | end; 58 | 59 | procedure TPEDIDO.SetCLIENTE(const Value: String); 60 | begin 61 | FCLIENTE := Value; 62 | end; 63 | 64 | procedure TPEDIDO.SetVALORTOTAL(const Value: Currency); 65 | begin 66 | FVALORTOTAL := Value; 67 | end; 68 | 69 | end. 70 | 71 | -------------------------------------------------------------------------------- /Sample/FMX/Principal.fmx: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form' 5 | ClientHeight = 480 6 | ClientWidth = 809 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | OnCreate = FormCreate 11 | DesignerMasterStyle = 0 12 | object Button1: TButton 13 | Position.X = 16.000000000000000000 14 | Position.Y = 24.000000000000000000 15 | TabOrder = 0 16 | Text = 'Insert Bind' 17 | OnClick = Button1Click 18 | end 19 | object Button2: TButton 20 | Position.X = 112.000000000000000000 21 | Position.Y = 24.000000000000000000 22 | TabOrder = 1 23 | Text = 'Insert Object' 24 | OnClick = Button2Click 25 | end 26 | object Edit2: TEdit 27 | Touch.InteractiveGestures = [LongTap, DoubleTap] 28 | TabOrder = 5 29 | Position.X = 216.000000000000000000 30 | Position.Y = 24.000000000000000000 31 | Size.Width = 73.000000000000000000 32 | Size.Height = 21.000000000000000000 33 | Size.PlatformDefault = False 34 | Left = 192 35 | Top = 14 36 | end 37 | object Edit1: TEdit 38 | Touch.InteractiveGestures = [LongTap, DoubleTap] 39 | TabOrder = 6 40 | Position.X = 216.000000000000000000 41 | Position.Y = 56.000000000000000000 42 | Size.Width = 329.000000000000000000 43 | Size.Height = 21.000000000000000000 44 | Size.PlatformDefault = False 45 | Left = 192 46 | Top = 41 47 | end 48 | object Edit3: TEdit 49 | Touch.InteractiveGestures = [LongTap, DoubleTap] 50 | TabOrder = 9 51 | Position.X = 552.000000000000000000 52 | Position.Y = 56.000000000000000000 53 | Size.Width = 81.000000000000000000 54 | Size.Height = 21.000000000000000000 55 | Size.PlatformDefault = False 56 | Left = 439 57 | Top = 41 58 | end 59 | object btnfind: TButton 60 | Position.X = 16.000000000000000000 61 | Position.Y = 99.000000000000000000 62 | TabOrder = 10 63 | Text = 'Find' 64 | OnClick = btnfindClick 65 | end 66 | object DateEdit1: TDateEdit 67 | Date = 44202.000000000000000000 68 | Position.X = 640.000000000000000000 69 | Position.Y = 56.000000000000000000 70 | TabOrder = 13 71 | end 72 | object Button3: TButton 73 | Position.X = 112.000000000000000000 74 | Position.Y = 73.000000000000000000 75 | TabOrder = 14 76 | Text = 'Delete Object' 77 | OnClick = Button3Click 78 | end 79 | object Button4: TButton 80 | Position.X = 112.000000000000000000 81 | Position.Y = 48.000000000000000000 82 | TabOrder = 15 83 | Text = 'Update Object' 84 | OnClick = Button4Click 85 | end 86 | object StringGridBindSourceDB1: TStringGrid 87 | CanFocus = True 88 | ClipChildren = True 89 | Position.X = 216.000000000000000000 90 | Position.Y = 120.000000000000000000 91 | Size.Width = 521.000000000000000000 92 | Size.Height = 209.000000000000000000 93 | Size.PlatformDefault = False 94 | TabOrder = 17 95 | Viewport.Width = 517.000000000000000000 96 | Viewport.Height = 184.000000000000000000 97 | end 98 | object Button5: TButton 99 | Position.X = 16.000000000000000000 100 | Position.Y = 72.000000000000000000 101 | TabOrder = 19 102 | Text = 'Delete Bind' 103 | OnClick = Button5Click 104 | end 105 | object Button6: TButton 106 | Position.X = 16.000000000000000000 107 | Position.Y = 48.000000000000000000 108 | TabOrder = 20 109 | Text = 'Update Bind' 110 | OnClick = Button6Click 111 | end 112 | object Button7: TButton 113 | Position.X = 16.000000000000000000 114 | Position.Y = 147.000000000000000000 115 | TabOrder = 21 116 | Text = 'Find Object' 117 | OnClick = Button7Click 118 | end 119 | object Button8: TButton 120 | Position.X = 16.000000000000000000 121 | Position.Y = 123.000000000000000000 122 | TabOrder = 22 123 | Text = 'Find Id' 124 | OnClick = Button8Click 125 | end 126 | object Button9: TButton 127 | Position.X = 16.000000000000000000 128 | Position.Y = 171.000000000000000000 129 | TabOrder = 23 130 | Text = 'Find where' 131 | OnClick = Button9Click 132 | end 133 | object Memo1: TMemo 134 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 135 | DataDetectorTypes = [] 136 | Position.X = 216.000000000000000000 137 | Position.Y = 344.000000000000000000 138 | Size.Width = 521.000000000000000000 139 | Size.Height = 81.000000000000000000 140 | Size.PlatformDefault = False 141 | TabOrder = 24 142 | Viewport.Width = 517.000000000000000000 143 | Viewport.Height = 77.000000000000000000 144 | end 145 | object FDConnection1: TFDConnection 146 | Params.Strings = ( 147 | 'Database=C:\Projetos\SimpleORM\Sample\Database\PDVUPDATES.FDB' 148 | 'User_Name=SYSDBA' 149 | 'Password=masterkey' 150 | 'DriverID=FB') 151 | Connected = True 152 | LoginPrompt = False 153 | Left = 424 154 | Top = 136 155 | end 156 | object DataSource1: TDataSource 157 | Left = 700 158 | Top = 88 159 | end 160 | object BindSourceDB1: TBindSourceDB 161 | DataSource = DataSource1 162 | ScopeMappings = <> 163 | Left = 544 164 | Top = 136 165 | end 166 | object BindingsList1: TBindingsList 167 | Methods = <> 168 | OutputConverters = <> 169 | Left = 490 170 | Top = 141 171 | object LinkGridToDataSourceBindSourceDB1: TLinkGridToDataSource 172 | Category = 'Quick Bindings' 173 | DataSource = BindSourceDB1 174 | GridControl = StringGridBindSourceDB1 175 | Columns = <> 176 | end 177 | end 178 | end 179 | -------------------------------------------------------------------------------- /Sample/FMX/Principal.pas: -------------------------------------------------------------------------------- 1 | unit Principal; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, 8 | FMX.Controls.Presentation, FMX.StdCtrls, 9 | Entidade.Pedido, SimpleInterface, FMX.Edit, FireDAC.Stan.Intf, 10 | FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, 11 | FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, 12 | FireDAC.Phys.FB, FireDAC.Phys.FBDef, FireDAC.FMXUI.Wait, Data.DB, 13 | FireDAC.Comp.Client, FMX.DateTimeCtrls, FMX.ListView.Types, 14 | FMX.ListView.Appearances, FMX.ListView.Adapters.Base, System.Rtti, 15 | System.Bindings.Outputs, Fmx.Bind.Editors, Data.Bind.EngExt, 16 | Fmx.Bind.DBEngExt, Data.Bind.Components, Data.Bind.DBScope, Datasnap.DBClient, 17 | FMX.ListView, Datasnap.Provider, FMX.Grid.Style, Fmx.Bind.Grid, 18 | Data.Bind.Controls, FMX.Layouts, Fmx.Bind.Navigator, Data.Bind.Grid, 19 | SimpleAttributes, 20 | FMX.ScrollBox, FMX.Grid, FMX.Memo; 21 | 22 | type 23 | TForm1 = class(TForm) 24 | Button1: TButton; 25 | Button2: TButton; 26 | 27 | [Bind('ID')] 28 | Edit2: TEdit; 29 | [Bind('CLIENTE')] 30 | Edit1: TEdit; 31 | [Bind('VALORTOTAL')] 32 | Edit3: TEdit; 33 | [Bind('DATAPEDIDO')] 34 | DateEdit1: TDateEdit; 35 | 36 | btnfind: TButton; 37 | FDConnection1: TFDConnection; 38 | DataSource1: TDataSource; 39 | Button3: TButton; 40 | Button4: TButton; 41 | BindSourceDB1: TBindSourceDB; 42 | StringGridBindSourceDB1: TStringGrid; 43 | BindingsList1: TBindingsList; 44 | Button5: TButton; 45 | Button6: TButton; 46 | Button7: TButton; 47 | Button8: TButton; 48 | Button9: TButton; 49 | Memo1: TMemo; 50 | LinkGridToDataSourceBindSourceDB1: TLinkGridToDataSource; 51 | procedure Button1Click(Sender: TObject); 52 | procedure Button2Click(Sender: TObject); 53 | procedure btnfindClick(Sender: TObject); 54 | procedure FormCreate(Sender: TObject); 55 | procedure Button4Click(Sender: TObject); 56 | procedure Button3Click(Sender: TObject); 57 | procedure Button6Click(Sender: TObject); 58 | procedure Button5Click(Sender: TObject); 59 | procedure Button7Click(Sender: TObject); 60 | procedure Button8Click(Sender: TObject); 61 | procedure Button9Click(Sender: TObject); 62 | private 63 | DAOPedido : iSimpleDAO; 64 | public 65 | { Public declarations } 66 | end; 67 | 68 | var 69 | Form1: TForm1; 70 | 71 | implementation 72 | 73 | 74 | uses System.Generics.Collections, 75 | SimpleQueryFiredac, SimpleDAO; 76 | 77 | {$R *.fmx} 78 | 79 | procedure TForm1.btnfindClick(Sender: TObject); 80 | begin 81 | DAOPedido 82 | .SQL 83 | .OrderBy('ID') 84 | .&End 85 | .Find; 86 | end; 87 | 88 | procedure TForm1.Button1Click(Sender: TObject); 89 | begin 90 | DAOPedido.Insert; 91 | DAOPedido.SQL.OrderBy('ID').&End.Find; 92 | end; 93 | 94 | procedure TForm1.Button2Click(Sender: TObject); 95 | var 96 | Pedido : TPEDIDO; 97 | begin 98 | Pedido := TPEDIDO.Create; 99 | try 100 | Pedido.ID := StrToInt(Edit2.Text); 101 | Pedido.CLIENTE := Edit1.Text; 102 | Pedido.DATAPEDIDO := now; 103 | Pedido.VALORTOTAL := StrToCurr(Edit3.Text); 104 | DAOPedido.Insert(Pedido); 105 | finally 106 | Pedido.Free; 107 | btnFindClick(nil); 108 | end; 109 | end; 110 | 111 | procedure TForm1.Button3Click(Sender: TObject); 112 | var 113 | Pedido : TPEDIDO; 114 | begin 115 | Pedido := TPEDIDO.Create; 116 | try 117 | Pedido.ID := StrToInt(Edit2.Text); 118 | DAOPedido.Delete(Pedido); 119 | finally 120 | Pedido.Free; 121 | btnFindClick(nil); 122 | end; 123 | end; 124 | 125 | procedure TForm1.Button4Click(Sender: TObject); 126 | var 127 | Pedido : TPEDIDO; 128 | begin 129 | Pedido := TPEDIDO.Create; 130 | try 131 | Pedido.ID := StrToInt(Edit2.Text); 132 | Pedido.CLIENTE := Edit1.Text; 133 | Pedido.DATAPEDIDO := now; 134 | Pedido.VALORTOTAL := StrToCurr(Edit3.Text); 135 | DAOPedido.Update(Pedido); 136 | finally 137 | Pedido.Free; 138 | btnFindClick(nil); 139 | end; 140 | end; 141 | 142 | procedure TForm1.Button5Click(Sender: TObject); 143 | begin 144 | DAOPedido.Delete; 145 | DAOPedido.SQL.OrderBy('ID').&End.Find; 146 | end; 147 | 148 | procedure TForm1.Button6Click(Sender: TObject); 149 | begin 150 | DAOPedido.Update; 151 | DAOPedido.SQL.OrderBy('ID').&End.Find; 152 | end; 153 | 154 | procedure TForm1.Button7Click(Sender: TObject); 155 | var 156 | Pedidos : TObjectList; 157 | Pedido : TPEDIDO; 158 | begin 159 | Pedidos := TObjectList.Create; 160 | 161 | DAOPedido 162 | .SQL 163 | .OrderBy('ID') 164 | .&End 165 | .Find(Pedidos); 166 | 167 | try 168 | for Pedido in Pedidos do 169 | begin 170 | Memo1.Lines.Add(Pedido.CLIENTE + DateToStr(Pedido.DATAPEDIDO)); 171 | end; 172 | finally 173 | Pedidos.Free; 174 | end; 175 | 176 | end; 177 | 178 | procedure TForm1.Button8Click(Sender: TObject); 179 | var 180 | Pedido : TPEDIDO; 181 | begin 182 | Pedido := DAOPedido.Find(StrToInt(Edit2.Text)); 183 | try 184 | Memo1.Lines.Add(Pedido.CLIENTE + DateToStr(Pedido.DATAPEDIDO)); 185 | finally 186 | Pedido.Free; 187 | end; 188 | 189 | end; 190 | 191 | procedure TForm1.Button9Click(Sender: TObject); 192 | begin 193 | DAOPedido 194 | .SQL 195 | .Where(' Nome = ' + QuotedStr(Edit1.Text)) 196 | .&End 197 | .Find; 198 | end; 199 | 200 | procedure TForm1.FormCreate(Sender: TObject); 201 | var 202 | Conn : iSimpleQuery; 203 | begin 204 | ReportMemoryLeaksOnShutdown := true; 205 | 206 | Conn := TSimpleQueryFiredac.New(FDConnection1); 207 | 208 | 209 | DAOPedido := TSimpleDAO 210 | .New(Conn) 211 | .DataSource(DataSource1) 212 | .BindForm(Self); 213 | 214 | end; 215 | 216 | end. 217 | -------------------------------------------------------------------------------- /Sample/FMX/Principal.vlb: -------------------------------------------------------------------------------- 1 | [Edit1] 2 | Coordinates=181,10,40,51 3 | 4 | [FDConnection1] 5 | Coordinates=380,78,90,33 6 | 7 | [Edit2] 8 | Coordinates=221,188,40,51 9 | 10 | [Edit3] 11 | Coordinates=127,10,40,51 12 | 13 | [Button3] 14 | Coordinates=442,10,53,51 15 | 16 | [DateEdit1] 17 | Coordinates=10,188,115,51 18 | 19 | [DataSource1] 20 | Coordinates=726,138,77,33 21 | Visible=True 22 | 23 | [btnfind] 24 | Coordinates=158,188,49,51 25 | 26 | [Button1] 27 | Coordinates=373,10,53,51 28 | 29 | [Button2] 30 | Coordinates=304,10,53,51 31 | 32 | [Button4] 33 | Coordinates=235,10,53,51 34 | 35 | [] 36 | Coordinates=510,50,140,51 37 | Visible=True 38 | 39 | [BindSourceDB1] 40 | Coordinates=639,128,77,33 41 | 42 | [StringGridBindSourceDB1] 43 | Coordinates=320,300,143,51 44 | Visible=True 45 | 46 | [BindingsList1] 47 | Coordinates=326,80,82,33 48 | 49 | [Button5] 50 | Coordinates=163,80,53,51 51 | 52 | [Button8] 53 | Coordinates=72,1,53,51 54 | 55 | [Button9] 56 | Coordinates=53,70,53,51 57 | 58 | [Button6] 59 | Coordinates=0,0,53,51 60 | 61 | [Button7] 62 | Coordinates=289,176,53,51 63 | 64 | [Memo1] 65 | Coordinates=259,258,49,51 66 | 67 | -------------------------------------------------------------------------------- /Sample/FMX/SimpleOrmFmx.dpr: -------------------------------------------------------------------------------- 1 | program SimpleOrmFmx; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | Principal in 'Principal.pas' {Form1}, 7 | Entidade.Pedido in '..\Entidades\Entidade.Pedido.pas'; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /Sample/FMX/SimpleOrmFmx.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/FMX/SimpleOrmFmx.res -------------------------------------------------------------------------------- /Sample/FMX/SimpleOrmFmx.skincfg: -------------------------------------------------------------------------------- 1 | [ExpressSkins] 2 | Default=1 3 | ShowNotifications=1 4 | Enabled=1 5 | dxSkinBlack=1 6 | dxSkinBlue=1 7 | dxSkinBlueprint=1 8 | dxSkinCaramel=1 9 | dxSkinCoffee=1 10 | dxSkinDarkroom=1 11 | dxSkinDarkSide=1 12 | dxSkinDevExpressDarkStyle=1 13 | dxSkinDevExpressStyle=1 14 | dxSkinFoggy=1 15 | dxSkinGlassOceans=1 16 | dxSkinHighContrast=1 17 | dxSkinLilian=1 18 | dxSkinLiquidSky=1 19 | dxSkinLondonLiquidSky=1 20 | dxSkinMcSkin=1 21 | dxSkinMetropolis=1 22 | dxSkinMetropolisDark=1 23 | dxSkinMoneyTwins=1 24 | dxSkinOffice2007Black=1 25 | dxSkinOffice2007Blue=1 26 | dxSkinOffice2007Green=1 27 | dxSkinOffice2007Pink=1 28 | dxSkinOffice2007Silver=1 29 | dxSkinOffice2010Black=1 30 | dxSkinOffice2010Blue=1 31 | dxSkinOffice2010Silver=1 32 | dxSkinOffice2013DarkGray=1 33 | dxSkinOffice2013LightGray=1 34 | dxSkinOffice2013White=1 35 | dxSkinOffice2016Colorful=1 36 | dxSkinOffice2016Dark=1 37 | dxSkinPumpkin=1 38 | dxSkinSeven=1 39 | dxSkinSevenClassic=1 40 | dxSkinSharp=1 41 | dxSkinSharpPlus=1 42 | dxSkinSilver=1 43 | dxSkinSpringtime=1 44 | dxSkinStardust=1 45 | dxSkinSummer2008=1 46 | dxSkinTheAsphaltWorld=1 47 | dxSkinTheBezier=1 48 | dxSkinsDefaultPainters=1 49 | dxSkinValentine=1 50 | dxSkinVisualStudio2013Blue=1 51 | dxSkinVisualStudio2013Dark=1 52 | dxSkinVisualStudio2013Light=1 53 | dxSkinVS2010=1 54 | dxSkinWhiteprint=1 55 | dxSkinXmas2008Blue=1 56 | -------------------------------------------------------------------------------- /Sample/Firedac/Principal.dfm: -------------------------------------------------------------------------------- 1 | object Form9: TForm9 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form9' 5 | ClientHeight = 438 6 | ClientWidth = 758 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnCreate = FormCreate 15 | DesignSize = ( 16 | 758 17 | 438) 18 | PixelsPerInch = 96 19 | TextHeight = 13 20 | object Button3: TButton 21 | Left = 8 22 | Top = 8 23 | Width = 75 24 | Height = 25 25 | Caption = 'Insert Bind' 26 | TabOrder = 0 27 | OnClick = Button3Click 28 | end 29 | object Button1: TButton 30 | Left = 89 31 | Top = 39 32 | Width = 97 33 | Height = 25 34 | Caption = 'Update Object' 35 | TabOrder = 1 36 | OnClick = Button1Click 37 | end 38 | object Button4: TButton 39 | Left = 89 40 | Top = 70 41 | Width = 97 42 | Height = 25 43 | Caption = 'Delete Object' 44 | TabOrder = 2 45 | OnClick = Button4Click 46 | end 47 | object btnFind: TButton 48 | Left = 8 49 | Top = 101 50 | Width = 75 51 | Height = 25 52 | Caption = 'Find' 53 | TabOrder = 3 54 | OnClick = btnFindClick 55 | end 56 | object Button6: TButton 57 | Left = 8 58 | Top = 163 59 | Width = 75 60 | Height = 25 61 | Caption = 'FindID' 62 | TabOrder = 4 63 | OnClick = Button6Click 64 | end 65 | object Button7: TButton 66 | Left = 8 67 | Top = 194 68 | Width = 75 69 | Height = 25 70 | Caption = 'FindWhere' 71 | TabOrder = 5 72 | OnClick = Button7Click 73 | end 74 | object Edit2: TEdit 75 | Left = 192 76 | Top = 14 77 | Width = 59 78 | Height = 21 79 | TabOrder = 6 80 | end 81 | object Edit1: TEdit 82 | Left = 192 83 | Top = 41 84 | Width = 241 85 | Height = 21 86 | TabOrder = 7 87 | end 88 | object DBGrid1: TDBGrid 89 | Left = 192 90 | Top = 68 91 | Width = 549 92 | Height = 273 93 | Anchors = [akLeft, akTop, akRight, akBottom] 94 | DataSource = DataSource1 95 | TabOrder = 8 96 | TitleFont.Charset = DEFAULT_CHARSET 97 | TitleFont.Color = clWindowText 98 | TitleFont.Height = -11 99 | TitleFont.Name = 'Tahoma' 100 | TitleFont.Style = [] 101 | end 102 | object Memo1: TMemo 103 | Left = 192 104 | Top = 356 105 | Width = 549 106 | Height = 66 107 | Anchors = [akLeft, akRight, akBottom] 108 | Lines.Strings = ( 109 | 'Memo1') 110 | TabOrder = 9 111 | end 112 | object Edit3: TEdit 113 | Left = 439 114 | Top = 41 115 | Width = 121 116 | Height = 21 117 | TabOrder = 10 118 | end 119 | object Button2: TButton 120 | Left = 8 121 | Top = 132 122 | Width = 75 123 | Height = 25 124 | Caption = 'FindObject' 125 | TabOrder = 11 126 | OnClick = Button2Click 127 | end 128 | object DateTimePicker1: TDateTimePicker 129 | Left = 566 130 | Top = 41 131 | Width = 175 132 | Height = 21 133 | Date = 43549.000000000000000000 134 | Time = 0.636917974537937000 135 | TabOrder = 12 136 | end 137 | object Button5: TButton 138 | Left = 89 139 | Top = 8 140 | Width = 97 141 | Height = 25 142 | Caption = 'Insert Object' 143 | TabOrder = 13 144 | OnClick = Button5Click 145 | end 146 | object Button8: TButton 147 | Left = 8 148 | Top = 39 149 | Width = 75 150 | Height = 25 151 | Caption = 'Update Bind' 152 | TabOrder = 14 153 | OnClick = Button8Click 154 | end 155 | object Button9: TButton 156 | Left = 8 157 | Top = 70 158 | Width = 75 159 | Height = 25 160 | Caption = 'Delete Bind' 161 | TabOrder = 15 162 | OnClick = Button9Click 163 | end 164 | object DataSource1: TDataSource 165 | Left = 696 166 | Top = 88 167 | end 168 | object FDConnection1: TFDConnection 169 | Params.Strings = ( 170 | 'Database=C:\lixo\PDVUPDATES.FDB' 171 | 'User_Name=SYSDBA' 172 | 'Password=masterkey' 173 | 'DriverID=FB') 174 | LoginPrompt = False 175 | Left = 552 176 | Top = 88 177 | end 178 | end 179 | -------------------------------------------------------------------------------- /Sample/Firedac/Principal.pas: -------------------------------------------------------------------------------- 1 | unit Principal; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 | Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, FireDAC.Stan.Intf, 8 | FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, 9 | FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, 10 | FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys, 11 | FireDAC.Phys.FB, FireDAC.Phys.FBDef, FireDAC.VCLUI.Wait, FireDAC.Comp.Client, 12 | FireDAC.Comp.DataSet, Vcl.StdCtrls, Vcl.Grids, Vcl.DBGrids, SimpleInterface, SimpleDAO, Entidade.Pedido, System.Generics.Collections, SimpleQueryFiredac, 13 | {Entidade.DoublePK,} 14 | SimpleAttributes, Vcl.ExtCtrls, Vcl.ComCtrls; 15 | 16 | type 17 | TForm9 = class(TForm) 18 | Button3: TButton; 19 | Button1: TButton; 20 | Button4: TButton; 21 | btnFind: TButton; 22 | Button6: TButton; 23 | Button7: TButton; 24 | DBGrid1: TDBGrid; 25 | DataSource1: TDataSource; 26 | Memo1: TMemo; 27 | FDConnection1: TFDConnection; 28 | 29 | [Bind('CLIENTE')] 30 | Edit1: TEdit; 31 | [Bind('ID')] 32 | Edit2: TEdit; 33 | [Bind('VALORTOTAL')] 34 | Edit3: TEdit; 35 | Button2: TButton; 36 | [Bind('DATAPEDIDO')] 37 | DateTimePicker1: TDateTimePicker; 38 | Button5: TButton; 39 | Button8: TButton; 40 | Button9: TButton; 41 | 42 | procedure Button3Click(Sender: TObject); 43 | procedure Button1Click(Sender: TObject); 44 | procedure Button4Click(Sender: TObject); 45 | procedure btnFindClick(Sender: TObject); 46 | procedure Button6Click(Sender: TObject); 47 | procedure Button7Click(Sender: TObject); 48 | procedure FormCreate(Sender: TObject); 49 | procedure Button2Click(Sender: TObject); 50 | procedure Button5Click(Sender: TObject); 51 | procedure Button8Click(Sender: TObject); 52 | procedure Button9Click(Sender: TObject); 53 | private 54 | { Private declarations } 55 | DAOPedido : iSimpleDAO; 56 | public 57 | { Public declarations } 58 | end; 59 | 60 | var 61 | Form9: TForm9; 62 | 63 | implementation 64 | 65 | {$R *.dfm} 66 | 67 | procedure TForm9.Button1Click(Sender: TObject); 68 | var 69 | Pedido : TPEDIDO; 70 | begin 71 | Pedido := TPEDIDO.Create; 72 | try 73 | Pedido.ID := StrToInt(Edit2.Text); 74 | Pedido.CLIENTE := Edit1.Text; 75 | Pedido.DATAPEDIDO := now; 76 | Pedido.VALORTOTAL := StrToCurr(Edit3.Text); 77 | DAOPedido.Update(Pedido); 78 | finally 79 | Pedido.Free; 80 | btnFindClick(nil); 81 | end; 82 | end; 83 | 84 | procedure TForm9.Button2Click(Sender: TObject); 85 | var 86 | Pedidos : TObjectList; 87 | Pedido : TPEDIDO; 88 | begin 89 | Pedidos := TObjectList.Create; 90 | 91 | DAOPedido 92 | .SQL 93 | .OrderBy('ID') 94 | .&End 95 | .Find(Pedidos); 96 | 97 | try 98 | for Pedido in Pedidos do 99 | begin 100 | Memo1.Lines.Add(Pedido.CLIENTE + DateToStr(Pedido.DATAPEDIDO)); 101 | end; 102 | finally 103 | Pedidos.Free; 104 | end; 105 | end; 106 | 107 | procedure TForm9.Button3Click(Sender: TObject); 108 | begin 109 | DAOPedido.Insert; 110 | DAOPedido.SQL.OrderBy('ID').&End.Find; 111 | end; 112 | 113 | procedure TForm9.Button4Click(Sender: TObject); 114 | var 115 | Pedido : TPEDIDO; 116 | begin 117 | Pedido := TPEDIDO.Create; 118 | try 119 | Pedido.ID := StrToInt(Edit2.Text); 120 | DAOPedido.Delete(Pedido); 121 | finally 122 | Pedido.Free; 123 | btnFindClick(nil); 124 | end; 125 | end; 126 | 127 | procedure TForm9.Button5Click(Sender: TObject); 128 | var 129 | Pedido : TPEDIDO; 130 | begin 131 | Pedido := TPEDIDO.Create; 132 | try 133 | Pedido.ID := StrToInt(Edit2.Text); 134 | Pedido.CLIENTE := Edit1.Text; 135 | Pedido.DATAPEDIDO := now; 136 | Pedido.VALORTOTAL := StrToCurr(Edit3.Text); 137 | DAOPedido.Insert(Pedido); 138 | finally 139 | Pedido.Free; 140 | btnFindClick(nil); 141 | end; 142 | end; 143 | 144 | procedure TForm9.btnFindClick(Sender: TObject); 145 | begin 146 | DAOPedido 147 | .SQL 148 | .OrderBy('ID') 149 | .&End 150 | .Find; 151 | end; 152 | 153 | 154 | procedure TForm9.Button6Click(Sender: TObject); 155 | var 156 | Pedido : TPEDIDO; 157 | begin 158 | Pedido := DAOPedido.Find(StrToInt(Edit2.Text)); 159 | try 160 | Memo1.Lines.Add(Pedido.CLIENTE + DateToStr(Pedido.DATAPEDIDO)); 161 | finally 162 | Pedido.Free; 163 | end; 164 | end; 165 | 166 | procedure TForm9.Button7Click(Sender: TObject); 167 | begin 168 | DAOPedido 169 | .SQL 170 | .Where(' Nome = ' + QuotedStr(Edit1.Text)) 171 | .&End 172 | .Find; 173 | end; 174 | 175 | procedure TForm9.Button8Click(Sender: TObject); 176 | begin 177 | DAOPedido.Update; 178 | DAOPedido.SQL.OrderBy('ID').&End.Find; 179 | end; 180 | 181 | procedure TForm9.Button9Click(Sender: TObject); 182 | begin 183 | DAOPedido.Delete; 184 | DAOPedido.SQL.OrderBy('ID').&End.Find; 185 | end; 186 | 187 | procedure TForm9.FormCreate(Sender: TObject); 188 | var 189 | Conn : iSimpleQuery; 190 | begin 191 | ReportMemoryLeaksOnShutdown := true; 192 | 193 | Conn := TSimpleQueryFiredac.New(FDConnection1); 194 | 195 | 196 | DAOPedido := TSimpleDAO 197 | .New(Conn) 198 | .DataSource(DataSource1) 199 | .BindForm(Self); 200 | end; 201 | 202 | end. 203 | -------------------------------------------------------------------------------- /Sample/Firedac/SimpleORMFiredac.dpr: -------------------------------------------------------------------------------- 1 | program SimpleORMFiredac; 2 | 3 | uses 4 | Vcl.Forms, 5 | Principal in 'Principal.pas' {Form9}, 6 | Entidade.Pedido in '..\Entidades\Entidade.Pedido.pas'; 7 | // Entidade.DoublePK in '..\Entidades\Entidade.DoublePK.pas'; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.MainFormOnTaskbar := True; 14 | Application.CreateForm(TForm9, Form9); 15 | Application.Run; 16 | end. 17 | -------------------------------------------------------------------------------- /Sample/Firedac/SimpleORMFiredac.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/Firedac/SimpleORMFiredac.res -------------------------------------------------------------------------------- /Sample/Firedac/pessoa.interfaces.pas: -------------------------------------------------------------------------------- 1 | unit pessoa.interfaces; 2 | 3 | interface 4 | 5 | type 6 | iPessoa = interface 7 | function Nome(Value:String):iPessoa; overload; 8 | function Nome:String; overload; 9 | function SobreNome(Value:String):iPessoa; overload; 10 | function SobreNome:String; overload; 11 | end; 12 | 13 | implementation 14 | 15 | end. 16 | -------------------------------------------------------------------------------- /Sample/Firedac/pessoa.pas: -------------------------------------------------------------------------------- 1 | unit pessoa; 2 | 3 | interface 4 | 5 | uses 6 | pessoa.interfaces; 7 | 8 | type 9 | TPessoa = class(TInterfacedObject, iPessoa) 10 | private 11 | public 12 | constructor Create; 13 | destructor Destroy; override; 14 | class function New : iPessoa; 15 | function Nome(Value:String):iPessoa; overload; 16 | function Nome:String; overload; 17 | function SobreNome(Value:String):iPessoa; overload; 18 | function SobreNome:String; overload; 19 | end; 20 | 21 | implementation 22 | 23 | constructor TPessoa.Create; 24 | begin 25 | 26 | end; 27 | 28 | destructor TPessoa.Destroy; 29 | begin 30 | 31 | inherited; 32 | end; 33 | 34 | class function TPessoa.New : iPessoa; 35 | begin 36 | Result := Self.Create; 37 | end; 38 | 39 | end. 40 | -------------------------------------------------------------------------------- /Sample/RestDW/SimpleORM_RestDW.dpr: -------------------------------------------------------------------------------- 1 | program SimpleORM_RestDW; 2 | 3 | uses 4 | Vcl.Forms, 5 | Unit8 in 'Unit8.pas' {Form8}, 6 | Entidade.Pedido in '..\Entidades\Entidade.Pedido.pas', 7 | SimpleAttributes in '..\..\SimpleAttributes.pas', 8 | SimpleDAO in '..\..\SimpleDAO.pas', 9 | SimpleDAOSQLAttribute in '..\..\SimpleDAOSQLAttribute.pas', 10 | SimpleEntity in '..\..\SimpleEntity.pas', 11 | SimpleInterface in '..\..\SimpleInterface.pas', 12 | SimpleQueryFiredac in '..\..\SimpleQueryFiredac.pas', 13 | SimpleQueryRestDW in '..\..\SimpleQueryRestDW.pas', 14 | SimpleQueryZeos in '..\..\SimpleQueryZeos.pas', 15 | SimpleRTTI in '..\..\SimpleRTTI.pas', 16 | SimpleRTTIHelper in '..\..\SimpleRTTIHelper.pas', 17 | SimpleSQL in '..\..\SimpleSQL.pas', 18 | SimpleUtil in '..\..\SimpleUtil.pas', 19 | SimpleValidator in '..\..\SimpleValidator.pas'; 20 | 21 | {$R *.res} 22 | 23 | begin 24 | Application.Initialize; 25 | ReportMemoryLeaksOnShutdown := True; 26 | Application.MainFormOnTaskbar := True; 27 | Application.CreateForm(TForm8, Form8); 28 | Application.Run; 29 | end. 30 | -------------------------------------------------------------------------------- /Sample/RestDW/SimpleORM_RestDW.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/RestDW/SimpleORM_RestDW.res -------------------------------------------------------------------------------- /Sample/RestDW/Unit8.dfm: -------------------------------------------------------------------------------- 1 | object Form8: TForm8 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form8' 5 | ClientHeight = 489 6 | ClientWidth = 573 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnCreate = FormCreate 15 | PixelsPerInch = 96 16 | TextHeight = 13 17 | object DBGrid1: TDBGrid 18 | Left = 105 19 | Top = 95 20 | Width = 457 21 | Height = 201 22 | DataSource = DataSource1 23 | TabOrder = 0 24 | TitleFont.Charset = DEFAULT_CHARSET 25 | TitleFont.Color = clWindowText 26 | TitleFont.Height = -11 27 | TitleFont.Name = 'Tahoma' 28 | TitleFont.Style = [] 29 | OnDblClick = DBGrid1DblClick 30 | end 31 | object btnFind: TButton 32 | Left = 8 33 | Top = 101 34 | Width = 75 35 | Height = 25 36 | Caption = 'Find' 37 | TabOrder = 1 38 | OnClick = btnFindClick 39 | end 40 | object Memo1: TMemo 41 | Left = 105 42 | Top = 302 43 | Width = 457 44 | Height = 169 45 | Lines.Strings = ( 46 | 'Memo1') 47 | TabOrder = 2 48 | end 49 | object Button2: TButton 50 | Left = 8 51 | Top = 8 52 | Width = 75 53 | Height = 25 54 | Caption = 'Insert' 55 | TabOrder = 3 56 | OnClick = Button2Click 57 | end 58 | object Edit1: TEdit 59 | Left = 105 60 | Top = 56 61 | Width = 280 62 | Height = 21 63 | TabOrder = 4 64 | Text = 'Edit1' 65 | end 66 | object Edit2: TEdit 67 | Left = 105 68 | Top = 29 69 | Width = 121 70 | Height = 21 71 | TabOrder = 5 72 | Text = '1' 73 | end 74 | object Button3: TButton 75 | Left = 8 76 | Top = 39 77 | Width = 75 78 | Height = 25 79 | Caption = 'Update' 80 | TabOrder = 6 81 | OnClick = Button3Click 82 | end 83 | object Button4: TButton 84 | Left = 8 85 | Top = 70 86 | Width = 75 87 | Height = 25 88 | Caption = 'Delete' 89 | TabOrder = 7 90 | OnClick = Button4Click 91 | end 92 | object Button5: TButton 93 | Left = 8 94 | Top = 132 95 | Width = 75 96 | Height = 25 97 | Caption = 'FindID' 98 | TabOrder = 8 99 | OnClick = Button5Click 100 | end 101 | object Button6: TButton 102 | Left = 8 103 | Top = 163 104 | Width = 75 105 | Height = 25 106 | Caption = 'FindWhere' 107 | TabOrder = 9 108 | OnClick = Button6Click 109 | end 110 | object RESTDWDataBase1: TRESTDWDataBase 111 | Active = True 112 | Compression = True 113 | CriptOptions.Use = False 114 | CriptOptions.Key = 'RDWBASEKEY256' 115 | MyIP = '127.0.0.1' 116 | AuthenticationOptions.AuthorizationOption = rdwAONone 117 | Proxy = False 118 | ProxyOptions.Port = 8888 119 | PoolerService = '127.0.0.1' 120 | PoolerPort = 8082 121 | PoolerName = 'TdmService.RESTDWPoolerFD' 122 | StateConnection.AutoCheck = False 123 | StateConnection.InTime = 1000 124 | RequestTimeOut = 10000 125 | EncodeStrings = True 126 | Encoding = esUtf8 127 | StrsTrim = False 128 | StrsEmpty2Null = False 129 | StrsTrim2Len = True 130 | HandleRedirects = False 131 | RedirectMaximum = 0 132 | ParamCreate = True 133 | FailOver = False 134 | FailOverConnections = <> 135 | FailOverReplaceDefaults = False 136 | ClientConnectionDefs.Active = False 137 | UserAgent = 138 | 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, l' + 139 | 'ike Gecko) Chrome/41.0.2227.0 Safari/537.36' 140 | Left = 472 141 | Top = 320 142 | end 143 | object DataSource1: TDataSource 144 | Left = 504 145 | Top = 104 146 | end 147 | end 148 | -------------------------------------------------------------------------------- /Sample/RestDW/Unit8.pas: -------------------------------------------------------------------------------- 1 | unit Unit8; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 | Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option, 8 | FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, 9 | FireDAC.DApt.Intf, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client, 10 | uDWConstsData, uRESTDWPoolerDB, uDWAbout, Vcl.StdCtrls, Vcl.Grids, Vcl.DBGrids, 11 | System.Generics.Collections, Entidade.Pedido, SimpleInterface, SimpleDAO, SimpleQueryRestDW; 12 | 13 | type 14 | TForm8 = class(TForm) 15 | RESTDWDataBase1: TRESTDWDataBase; 16 | DBGrid1: TDBGrid; 17 | DataSource1: TDataSource; 18 | 19 | [Campo('ID')] 20 | Edit1: TEdit; 21 | [Campo('NOME')] 22 | Edit2: TEdit; 23 | 24 | btnFind: TButton; 25 | Memo1: TMemo; 26 | Button2: TButton; 27 | Button3: TButton; 28 | Button4: TButton; 29 | Button5: TButton; 30 | Button6: TButton; 31 | procedure btnFindClick(Sender: TObject); 32 | procedure Button2Click(Sender: TObject); 33 | procedure Button3Click(Sender: TObject); 34 | procedure Button4Click(Sender: TObject); 35 | procedure Button5Click(Sender: TObject); 36 | procedure Button6Click(Sender: TObject); 37 | procedure FormCreate(Sender: TObject); 38 | procedure Button1Click(Sender: TObject); 39 | procedure DBGrid1DblClick(Sender: TObject); 40 | private 41 | { Private declarations } 42 | DAOPedido : iSimpleDAO; 43 | public 44 | { Public declarations } 45 | end; 46 | 47 | var 48 | Form8: TForm8; 49 | 50 | implementation 51 | 52 | {$R *.dfm} 53 | 54 | procedure TForm8.btnFindClick(Sender: TObject); 55 | var 56 | Pedidos : TObjectList; 57 | Pedido : TPEDIDO; 58 | begin 59 | Pedidos := TObjectList.Create(); 60 | DAOPedido 61 | .SQL 62 | .OrderBy('ID') 63 | .&End 64 | .Find(Pedidos); 65 | try 66 | for Pedido in Pedidos do 67 | begin 68 | Memo1.Lines.Add(Pedido.NOME + DateToStr(Pedido.DATA)); 69 | end; 70 | finally 71 | Pedidos.free; 72 | end; 73 | 74 | end; 75 | 76 | procedure TForm8.Button1Click(Sender: TObject); 77 | begin 78 | DAOPedido 79 | .SQL 80 | .Fields('MAX(ID)') 81 | .&End 82 | .Find; 83 | end; 84 | 85 | procedure TForm8.Button2Click(Sender: TObject); 86 | var 87 | Pedido : TPEDIDO; 88 | begin 89 | Pedido := TPEDIDO.Create; 90 | try 91 | Pedido.ID := StrToInt(Edit2.Text); 92 | Pedido.NOME := Edit1.Text; 93 | Pedido.DATA := now; 94 | DAOPedido.Insert(Pedido); 95 | finally 96 | Pedido.Free; 97 | btnFindClick(nil); 98 | end; 99 | 100 | end; 101 | 102 | procedure TForm8.Button3Click(Sender: TObject); 103 | var 104 | Pedido : TPEDIDO; 105 | begin 106 | Pedido := TPEDIDO.Create; 107 | try 108 | Pedido.ID := StrToInt(Edit2.Text); 109 | Pedido.NOME := Edit1.Text; 110 | Pedido.DATA := now; 111 | DAOPedido.Update(Pedido); 112 | finally 113 | Pedido.Free; 114 | btnFindClick(nil); 115 | end; 116 | 117 | end; 118 | 119 | procedure TForm8.Button4Click(Sender: TObject); 120 | var 121 | Pedido : TPEDIDO; 122 | begin 123 | Pedido := TPEDIDO.Create; 124 | try 125 | Pedido.ID := StrToInt(Edit2.Text); 126 | DAOPedido.Delete(Pedido); 127 | finally 128 | Pedido.Free; 129 | btnFindClick(nil); 130 | end; 131 | end; 132 | 133 | procedure TForm8.Button5Click(Sender: TObject); 134 | var 135 | Pedido : TPEDIDO; 136 | begin 137 | Pedido := DAOPedido.Find(StrToInt(Edit2.Text)); 138 | try 139 | Memo1.Lines.Add(Pedido.NOME + DateToStr(Pedido.DATA)); 140 | finally 141 | Pedido.Free; 142 | end; 143 | end; 144 | 145 | procedure TForm8.Button6Click(Sender: TObject); 146 | var 147 | Pedidos : TList; 148 | Pedido : TPEDIDO; 149 | begin 150 | Pedidos := TObjectList.Create(); 151 | DAOPedido 152 | .SQL 153 | .Where(' Nome = ' + QuotedStr(Edit1.Text)) 154 | .&End 155 | .Find; 156 | try 157 | for Pedido in Pedidos do 158 | begin 159 | Memo1.Lines.Add(Pedido.NOME + DateToStr(Pedido.DATA)); 160 | end; 161 | finally 162 | Pedidos.Free; 163 | end; 164 | end; 165 | 166 | procedure TForm8.DBGrid1DblClick(Sender: TObject); 167 | begin 168 | Edit1.Text := DataSource1.DataSet.FieldByName('NOME').AsString; 169 | Edit2.Text := DataSource1.DataSet.FieldByName('ID').AsString; 170 | end; 171 | 172 | Procedure TForm8.FormCreate(Sender: TObject); 173 | begin 174 | DAOPedido := TSimpleDAO 175 | .New(TSimpleQueryRestDW.New(RESTDWDataBase1)) 176 | .DataSource(DataSource1) 177 | .BindForm(Self); 178 | end; 179 | 180 | end. 181 | -------------------------------------------------------------------------------- /Sample/Unidac/Principal.dfm: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 591 6 | ClientWidth = 969 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnCreate = FormCreate 15 | DesignSize = ( 16 | 969 17 | 591) 18 | PixelsPerInch = 96 19 | TextHeight = 13 20 | object Button3: TButton 21 | Left = 8 22 | Top = 8 23 | Width = 75 24 | Height = 25 25 | Caption = 'Insert Bind' 26 | TabOrder = 0 27 | OnClick = Button3Click 28 | end 29 | object Button1: TButton 30 | Left = 89 31 | Top = 39 32 | Width = 97 33 | Height = 25 34 | Caption = 'Update Object' 35 | TabOrder = 1 36 | OnClick = Button1Click 37 | end 38 | object Button4: TButton 39 | Left = 89 40 | Top = 70 41 | Width = 97 42 | Height = 25 43 | Caption = 'Delete Object' 44 | TabOrder = 2 45 | OnClick = Button4Click 46 | end 47 | object btnFind: TButton 48 | Left = 8 49 | Top = 101 50 | Width = 75 51 | Height = 25 52 | Caption = 'Find' 53 | TabOrder = 3 54 | OnClick = btnFindClick 55 | end 56 | object Button6: TButton 57 | Left = 8 58 | Top = 163 59 | Width = 75 60 | Height = 25 61 | Caption = 'FindID' 62 | TabOrder = 4 63 | OnClick = Button6Click 64 | end 65 | object Button7: TButton 66 | Left = 8 67 | Top = 194 68 | Width = 75 69 | Height = 25 70 | Caption = 'FindWhere' 71 | TabOrder = 5 72 | OnClick = Button7Click 73 | end 74 | object Edit2: TEdit 75 | Left = 192 76 | Top = 14 77 | Width = 59 78 | Height = 21 79 | TabOrder = 6 80 | end 81 | object Edit1: TEdit 82 | Left = 192 83 | Top = 41 84 | Width = 241 85 | Height = 21 86 | TabOrder = 7 87 | end 88 | object DBGrid1: TDBGrid 89 | Left = 192 90 | Top = 68 91 | Width = 549 92 | Height = 273 93 | Anchors = [akLeft, akTop, akRight, akBottom] 94 | DataSource = UniDataSource1 95 | TabOrder = 8 96 | TitleFont.Charset = DEFAULT_CHARSET 97 | TitleFont.Color = clWindowText 98 | TitleFont.Height = -11 99 | TitleFont.Name = 'Tahoma' 100 | TitleFont.Style = [] 101 | end 102 | object Memo1: TMemo 103 | Left = 192 104 | Top = 356 105 | Width = 549 106 | Height = 66 107 | Anchors = [akLeft, akRight, akBottom] 108 | Lines.Strings = ( 109 | 'Memo1') 110 | TabOrder = 9 111 | end 112 | object Edit3: TEdit 113 | Left = 439 114 | Top = 41 115 | Width = 121 116 | Height = 21 117 | TabOrder = 10 118 | end 119 | object Button2: TButton 120 | Left = 8 121 | Top = 132 122 | Width = 75 123 | Height = 25 124 | Caption = 'FindObject' 125 | TabOrder = 11 126 | OnClick = Button2Click 127 | end 128 | object DateTimePicker1: TDateTimePicker 129 | Left = 566 130 | Top = 41 131 | Width = 175 132 | Height = 21 133 | Date = 43549.000000000000000000 134 | Time = 0.636917974537937000 135 | TabOrder = 12 136 | end 137 | object Button5: TButton 138 | Left = 89 139 | Top = 8 140 | Width = 97 141 | Height = 25 142 | Caption = 'Insert Object' 143 | TabOrder = 13 144 | OnClick = Button5Click 145 | end 146 | object Button8: TButton 147 | Left = 8 148 | Top = 39 149 | Width = 75 150 | Height = 25 151 | Caption = 'Update Bind' 152 | TabOrder = 14 153 | OnClick = Button8Click 154 | end 155 | object Button9: TButton 156 | Left = 8 157 | Top = 70 158 | Width = 75 159 | Height = 25 160 | Caption = 'Delete Bind' 161 | TabOrder = 15 162 | OnClick = Button9Click 163 | end 164 | object UniDataSource1: TUniDataSource 165 | Left = 688 166 | Top = 88 167 | end 168 | object UniConnection1: TUniConnection 169 | ProviderName = 'InterBase' 170 | Port = 3051 171 | Database = '/firebird/data/PDVUPDATES.FDB' 172 | Username = 'SYSDBA' 173 | Server = 'localhost' 174 | Connected = True 175 | LoginPrompt = False 176 | Left = 616 177 | Top = 88 178 | EncryptedPassword = 179 | 'CEFFC7FFCBFF9CFFC6FFC9FF9BFFC8FF9DFFCDFFC8FF9CFFC9FF99FFC8FF9BFF' + 180 | 'C9FF9DFF9EFF9EFF' 181 | end 182 | object InterBaseUniProvider1: TInterBaseUniProvider 183 | Left = 784 184 | Top = 88 185 | end 186 | end 187 | -------------------------------------------------------------------------------- /Sample/Unidac/Principal.pas: -------------------------------------------------------------------------------- 1 | unit Principal; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, 7 | Winapi.Messages, 8 | System.SysUtils, 9 | System.Variants, 10 | System.Classes, 11 | Vcl.Graphics, 12 | Vcl.Controls, 13 | Vcl.Forms, 14 | Vcl.Dialogs, 15 | Data.DB, 16 | UniProvider, 17 | InterBaseUniProvider, 18 | DBAccess, 19 | Uni, 20 | Vcl.ComCtrls, 21 | Vcl.StdCtrls, 22 | Vcl.Grids, 23 | Vcl.DBGrids, 24 | SimpleInterface, 25 | SimpleDAO, 26 | SimpleQueryUniDac, 27 | Entidade.Pedido; 28 | 29 | type 30 | TForm1 = class(TForm) 31 | Button3: TButton; 32 | Button1: TButton; 33 | Button4: TButton; 34 | btnFind: TButton; 35 | Button6: TButton; 36 | Button7: TButton; 37 | DBGrid1: TDBGrid; 38 | Memo1: TMemo; 39 | Button2: TButton; 40 | Button5: TButton; 41 | Button8: TButton; 42 | Button9: TButton; 43 | 44 | [Bind('CLIENTE')] 45 | Edit1: TEdit; 46 | [Bind('ID')] 47 | Edit2: TEdit; 48 | [Bind('VALORTOTAL')] 49 | Edit3: TEdit; 50 | [Bind('DATAPEDIDO')] 51 | DateTimePicker1: TDateTimePicker; 52 | 53 | UniDataSource1: TUniDataSource; 54 | UniConnection1: TUniConnection; 55 | InterBaseUniProvider1: TInterBaseUniProvider; 56 | procedure FormCreate(Sender: TObject); 57 | procedure btnFindClick(Sender: TObject); 58 | procedure Button2Click(Sender: TObject); 59 | procedure Button6Click(Sender: TObject); 60 | procedure Button7Click(Sender: TObject); 61 | procedure Button3Click(Sender: TObject); 62 | procedure Button5Click(Sender: TObject); 63 | procedure Button8Click(Sender: TObject); 64 | procedure Button1Click(Sender: TObject); 65 | procedure Button9Click(Sender: TObject); 66 | procedure Button4Click(Sender: TObject); 67 | private 68 | DAOPedido : iSimpleDAO; 69 | public 70 | end; 71 | 72 | var 73 | Form1: TForm1; 74 | 75 | implementation 76 | 77 | uses 78 | System.Generics.Collections; 79 | 80 | {$R *.dfm} 81 | 82 | procedure TForm1.btnFindClick(Sender: TObject); 83 | begin 84 | DAOPedido 85 | .SQL 86 | .OrderBy('ID') 87 | .&End 88 | .Find; 89 | end; 90 | 91 | procedure TForm1.Button1Click(Sender: TObject); 92 | var 93 | Pedido : TPEDIDO; 94 | begin 95 | Pedido := TPEDIDO.Create; 96 | try 97 | Pedido.ID := StrToInt(Edit2.Text); 98 | Pedido.CLIENTE := Edit1.Text; 99 | Pedido.DATAPEDIDO := now; 100 | Pedido.VALORTOTAL := StrToCurr(Edit3.Text); 101 | DAOPedido.Update(Pedido); 102 | finally 103 | Pedido.Free; 104 | btnFindClick(nil); 105 | end; 106 | end; 107 | 108 | procedure TForm1.Button2Click(Sender: TObject); 109 | var 110 | Pedidos : TObjectList; 111 | Pedido : TPEDIDO; 112 | begin 113 | Pedidos := TObjectList.Create; 114 | 115 | DAOPedido 116 | .SQL 117 | .OrderBy('ID') 118 | .&End 119 | .Find(Pedidos); 120 | 121 | try 122 | for Pedido in Pedidos do 123 | begin 124 | Memo1.Lines.Add(Pedido.CLIENTE + DateToStr(Pedido.DATAPEDIDO)); 125 | end; 126 | finally 127 | Pedidos.Free; 128 | end; 129 | end; 130 | 131 | procedure TForm1.Button3Click(Sender: TObject); 132 | begin 133 | DAOPedido.Insert; 134 | DAOPedido.SQL.OrderBy('ID').&End.Find; 135 | end; 136 | 137 | procedure TForm1.Button4Click(Sender: TObject); 138 | var 139 | Pedido : TPEDIDO; 140 | begin 141 | Pedido := TPEDIDO.Create; 142 | try 143 | Pedido.ID := StrToInt(Edit2.Text); 144 | DAOPedido.Delete(Pedido); 145 | finally 146 | Pedido.Free; 147 | btnFindClick(nil); 148 | end; 149 | end; 150 | 151 | procedure TForm1.Button5Click(Sender: TObject); 152 | var 153 | Pedido : TPEDIDO; 154 | begin 155 | Pedido := TPEDIDO.Create; 156 | try 157 | Pedido.ID := StrToInt(Edit2.Text); 158 | Pedido.CLIENTE := Edit1.Text; 159 | Pedido.DATAPEDIDO := now; 160 | Pedido.VALORTOTAL := StrToCurr(Edit3.Text); 161 | DAOPedido.Insert(Pedido); 162 | finally 163 | Pedido.Free; 164 | btnFindClick(nil); 165 | end; 166 | end; 167 | 168 | procedure TForm1.Button6Click(Sender: TObject); 169 | var 170 | Pedido : TPEDIDO; 171 | begin 172 | Pedido := DAOPedido.Find(StrToInt(Edit2.Text)); 173 | try 174 | Memo1.Lines.Add(Pedido.CLIENTE + DateToStr(Pedido.DATAPEDIDO)); 175 | finally 176 | Pedido.Free; 177 | end; 178 | end; 179 | 180 | procedure TForm1.Button7Click(Sender: TObject); 181 | begin 182 | DAOPedido 183 | .SQL 184 | .Where(' Nome = ' + QuotedStr(Edit1.Text)) 185 | .&End 186 | .Find; 187 | end; 188 | 189 | procedure TForm1.Button8Click(Sender: TObject); 190 | begin 191 | DAOPedido.Update; 192 | DAOPedido.SQL.OrderBy('ID').&End.Find; 193 | end; 194 | 195 | procedure TForm1.Button9Click(Sender: TObject); 196 | begin 197 | DAOPedido.Delete; 198 | DAOPedido.SQL.OrderBy('ID').&End.Find; 199 | end; 200 | 201 | procedure TForm1.FormCreate(Sender: TObject); 202 | var 203 | Conn : iSimpleQuery; 204 | begin 205 | ReportMemoryLeaksOnShutdown := true; 206 | 207 | Conn := TSimpleQueryUniDac.New(UniConnection1); 208 | 209 | 210 | DAOPedido := TSimpleDAO 211 | .New(Conn) 212 | .DataSource(UniDataSource1) 213 | .BindForm(Self); 214 | end; 215 | 216 | end. 217 | -------------------------------------------------------------------------------- /Sample/Unidac/SimpleORMUnidac.dpr: -------------------------------------------------------------------------------- 1 | program SimpleORMUnidac; 2 | 3 | uses 4 | Vcl.Forms, 5 | Principal in 'Principal.pas' {Form1}, 6 | Entidade.Pedido in '..\Entidades\Entidade.Pedido.pas'; 7 | 8 | {$R *.res} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.MainFormOnTaskbar := True; 13 | Application.CreateForm(TForm1, Form1); 14 | Application.Run; 15 | end. 16 | -------------------------------------------------------------------------------- /Sample/Unidac/SimpleORMUnidac.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/Unidac/SimpleORMUnidac.res -------------------------------------------------------------------------------- /Sample/Unidac/SimpleORMUnidac.skincfg: -------------------------------------------------------------------------------- 1 | [ExpressSkins] 2 | Default=1 3 | ShowNotifications=1 4 | Enabled=0 5 | dxSkinBlack=1 6 | dxSkinBlue=1 7 | dxSkinBlueprint=1 8 | dxSkinCaramel=1 9 | dxSkinCoffee=1 10 | dxSkinDarkroom=1 11 | dxSkinDarkSide=1 12 | dxSkinDevExpressDarkStyle=1 13 | dxSkinDevExpressStyle=1 14 | dxSkinFoggy=1 15 | dxSkinGlassOceans=1 16 | dxSkinHighContrast=1 17 | dxSkinLilian=1 18 | dxSkinLiquidSky=1 19 | dxSkinLondonLiquidSky=1 20 | dxSkinMcSkin=1 21 | dxSkinMetropolis=1 22 | dxSkinMetropolisDark=1 23 | dxSkinMoneyTwins=1 24 | dxSkinOffice2007Black=1 25 | dxSkinOffice2007Blue=1 26 | dxSkinOffice2007Green=1 27 | dxSkinOffice2007Pink=1 28 | dxSkinOffice2007Silver=1 29 | dxSkinOffice2010Black=1 30 | dxSkinOffice2010Blue=1 31 | dxSkinOffice2010Silver=1 32 | dxSkinOffice2013DarkGray=1 33 | dxSkinOffice2013LightGray=1 34 | dxSkinOffice2013White=1 35 | dxSkinOffice2016Colorful=1 36 | dxSkinOffice2016Dark=1 37 | dxSkinPumpkin=1 38 | dxSkinSeven=1 39 | dxSkinSevenClassic=1 40 | dxSkinSharp=1 41 | dxSkinSharpPlus=1 42 | dxSkinSilver=1 43 | dxSkinSpringtime=1 44 | dxSkinStardust=1 45 | dxSkinSummer2008=1 46 | dxSkinTheAsphaltWorld=1 47 | dxSkinTheBezier=1 48 | dxSkinsDefaultPainters=1 49 | dxSkinValentine=1 50 | dxSkinVisualStudio2013Blue=1 51 | dxSkinVisualStudio2013Dark=1 52 | dxSkinVisualStudio2013Light=1 53 | dxSkinVS2010=1 54 | dxSkinWhiteprint=1 55 | dxSkinXmas2008Blue=1 56 | -------------------------------------------------------------------------------- /Sample/Validation/Base/View/ufBase.dfm: -------------------------------------------------------------------------------- 1 | object fBase: TfBase 2 | Left = 0 3 | Top = 0 4 | Caption = 'fBase' 5 | ClientHeight = 511 6 | ClientWidth = 446 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnCreate = FormCreate 15 | DesignSize = ( 16 | 446 17 | 511) 18 | PixelsPerInch = 96 19 | TextHeight = 13 20 | object Label9: TLabel 21 | AlignWithMargins = True 22 | Left = 3 23 | Top = 3 24 | Width = 440 25 | Height = 19 26 | Align = alTop 27 | Caption = 'Busca: Tabela Base' 28 | Font.Charset = DEFAULT_CHARSET 29 | Font.Color = clWindowText 30 | Font.Height = -16 31 | Font.Name = 'Tahoma' 32 | Font.Style = [] 33 | ParentFont = False 34 | ExplicitWidth = 135 35 | end 36 | object btnCancelar: TButton 37 | Left = 358 38 | Top = 330 39 | Width = 80 40 | Height = 25 41 | Anchors = [akLeft, akBottom] 42 | Caption = ':: Cancelar ::' 43 | TabOrder = 0 44 | OnClick = btnCancelarClick 45 | end 46 | object btnNovo: TButton 47 | Left = 8 48 | Top = 330 49 | Width = 80 50 | Height = 25 51 | Anchors = [akLeft, akBottom] 52 | Caption = ':: Novo ::' 53 | TabOrder = 1 54 | OnClick = btnNovoClick 55 | end 56 | object pnlErros: TPanel 57 | Left = 0 58 | Top = 361 59 | Width = 446 60 | Height = 150 61 | Align = alBottom 62 | TabOrder = 2 63 | object lstSaidas: TListBox 64 | AlignWithMargins = True 65 | Left = 9 66 | Top = 9 67 | Width = 428 68 | Height = 132 69 | Margins.Left = 8 70 | Margins.Top = 8 71 | Margins.Right = 8 72 | Margins.Bottom = 8 73 | Align = alClient 74 | Font.Charset = DEFAULT_CHARSET 75 | Font.Color = 221 76 | Font.Height = -11 77 | Font.Name = 'Verdana' 78 | Font.Style = [fsBold] 79 | ItemHeight = 13 80 | ParentFont = False 81 | TabOrder = 0 82 | end 83 | end 84 | object btnSalvar: TButton 85 | Left = 270 86 | Top = 330 87 | Width = 80 88 | Height = 25 89 | Anchors = [akLeft, akBottom] 90 | Caption = ':: Salvar ::' 91 | TabOrder = 3 92 | OnClick = btnSalvarClick 93 | end 94 | object btnExcluir: TButton 95 | Left = 183 96 | Top = 330 97 | Width = 80 98 | Height = 25 99 | Anchors = [akLeft, akBottom] 100 | Caption = ':: Excluir ::' 101 | TabOrder = 4 102 | OnClick = btnExcluirClick 103 | end 104 | object btnEditar: TButton 105 | Left = 95 106 | Top = 330 107 | Width = 80 108 | Height = 25 109 | Anchors = [akLeft, akBottom] 110 | Caption = ':: Editar ::' 111 | TabOrder = 5 112 | OnClick = btnEditarClick 113 | end 114 | object grdDados: TDBGrid 115 | Left = 0 116 | Top = 55 117 | Width = 446 118 | Height = 120 119 | Align = alTop 120 | DataSource = dtsDados 121 | Options = [dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect, dgConfirmDelete, dgCancelOnExit, dgTitleClick, dgTitleHotTrack] 122 | TabOrder = 6 123 | TitleFont.Charset = DEFAULT_CHARSET 124 | TitleFont.Color = clWindowText 125 | TitleFont.Height = -11 126 | TitleFont.Name = 'Tahoma' 127 | TitleFont.Style = [] 128 | end 129 | object edtPesquisar: TEdit 130 | AlignWithMargins = True 131 | Left = 3 132 | Top = 28 133 | Width = 440 134 | Height = 24 135 | Align = alTop 136 | Font.Charset = DEFAULT_CHARSET 137 | Font.Color = clRed 138 | Font.Height = -13 139 | Font.Name = 'Courier New' 140 | Font.Style = [fsBold] 141 | ParentFont = False 142 | TabOrder = 7 143 | end 144 | object conFireDac: TFDConnection 145 | Params.Strings = ( 146 | 'Database=C:\LIXO\RTTI.FDB' 147 | 'User_Name=SYSDBA' 148 | 'Password=masterkey' 149 | 'DriverID=FB') 150 | LoginPrompt = False 151 | Left = 178 152 | Top = 72 153 | end 154 | object dtsDados: TDataSource 155 | Left = 258 156 | Top = 72 157 | end 158 | end 159 | -------------------------------------------------------------------------------- /Sample/Validation/Base/View/ufBase.pas: -------------------------------------------------------------------------------- 1 | unit ufBase; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, 7 | System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, 8 | Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ComCtrls, FireDAC.Stan.Intf, 9 | FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, 10 | FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, 11 | FireDAC.Phys.FB, FireDAC.Phys.FBDef, FireDAC.VCLUI.Wait, Data.DB, Vcl.DBGrids, 12 | FireDAC.Comp.Client; 13 | 14 | type 15 | TStatus = (stInsercao, stEdicao, stNenhum); 16 | 17 | TfBase = class(TForm) 18 | btnCancelar: TButton; 19 | btnNovo: TButton; 20 | pnlErros: TPanel; 21 | lstSaidas: TListBox; 22 | btnSalvar: TButton; 23 | btnExcluir: TButton; 24 | btnEditar: TButton; 25 | conFireDac: TFDConnection; 26 | dtsDados: TDataSource; 27 | grdDados: TDBGrid; 28 | Label9: TLabel; 29 | edtPesquisar: TEdit; 30 | procedure FormCreate(Sender: TObject); 31 | procedure btnCancelarClick(Sender: TObject); 32 | procedure btnEditarClick(Sender: TObject); 33 | procedure btnExcluirClick(Sender: TObject); 34 | procedure btnNovoClick(Sender: TObject); 35 | procedure btnSalvarClick(Sender: TObject); 36 | private 37 | procedure Limpar; 38 | procedure SetStatus(const poStatus: TStatus); 39 | function EstaEmModoEdicao: boolean; 40 | protected 41 | FStatus: TStatus; 42 | public 43 | { Public declarations } 44 | end; 45 | 46 | implementation 47 | 48 | {$R *.dfm} 49 | 50 | procedure TfBase.btnCancelarClick(Sender: TObject); 51 | begin 52 | SetStatus(stNenhum); 53 | end; 54 | 55 | procedure TfBase.btnEditarClick(Sender: TObject); 56 | begin 57 | SetStatus(stEdicao); 58 | end; 59 | 60 | procedure TfBase.btnExcluirClick(Sender: TObject); 61 | begin 62 | SetStatus(stNenhum); 63 | end; 64 | 65 | procedure TfBase.btnNovoClick(Sender: TObject); 66 | begin 67 | SetStatus(stInsercao); 68 | Limpar; 69 | end; 70 | 71 | procedure TfBase.btnSalvarClick(Sender: TObject); 72 | begin 73 | SetStatus(stNenhum); 74 | end; 75 | 76 | procedure TfBase.Limpar; 77 | var 78 | nIndex: Integer; 79 | begin 80 | for nIndex := 0 to Self.ComponentCount-1 do 81 | begin 82 | if Components[nIndex] is TCustomEdit then 83 | (Components[nIndex] as TCustomEdit).Clear; 84 | 85 | if Components[nIndex] is TComboBox then 86 | (Components[nIndex] as TComboBox).ItemIndex := -1; 87 | 88 | if Components[nIndex] is TDateTimePicker then 89 | (Components[nIndex] as TDateTimePicker).Date := 0; 90 | end; 91 | end; 92 | 93 | procedure TfBase.FormCreate(Sender: TObject); 94 | begin 95 | Constraints.MinHeight := Height; 96 | Constraints.MinWidth := Width; 97 | 98 | SetStatus(stNenhum); 99 | end; 100 | 101 | function TfBase.EstaEmModoEdicao: boolean; 102 | begin 103 | Result := FStatus in [stInsercao, stEdicao]; 104 | end; 105 | 106 | procedure TfBase.SetStatus(const poStatus: TStatus); 107 | begin 108 | FStatus := poStatus; 109 | 110 | btnNovo.Enabled := not EstaEmModoEdicao; 111 | btnEditar.Enabled := not EstaEmModoEdicao; 112 | btnExcluir.Enabled := not EstaEmModoEdicao; 113 | btnSalvar.Enabled := EstaEmModoEdicao; 114 | btnCancelar.Enabled := EstaEmModoEdicao; 115 | end; 116 | 117 | end. 118 | -------------------------------------------------------------------------------- /Sample/Validation/Entidade/Entidade.Cliente.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/Validation/Entidade/Entidade.Cliente.pas -------------------------------------------------------------------------------- /Sample/Validation/Export/uExport.pas: -------------------------------------------------------------------------------- 1 | unit uExport; 2 | 3 | interface 4 | 5 | uses 6 | RTTI, SysUtils, generics.collections, Classes, System.IOUtils, SimpleRTTIHelper, 7 | SimpleAttributes; 8 | 9 | type 10 | TExport = class 11 | public 12 | class procedure TextReport(Lista: TObjectList); 13 | end; 14 | 15 | implementation 16 | 17 | uses 18 | System.TypInfo; 19 | 20 | { TExport } 21 | 22 | class procedure TExport.TextReport(Lista: TObjectList); 23 | var 24 | oObjeto: TObject; 25 | oTipo: TRttiType; 26 | oPropriedade: TRttiProperty; 27 | oFormat: Format; 28 | oValue: TValue; 29 | oRelatorio: TStringList; 30 | oLines: TStringBuilder; 31 | sPastaRelatorio: string; 32 | begin 33 | oRelatorio := TStringList.Create; 34 | oLines := TStringBuilder.Create; 35 | oObjeto := T.create; 36 | try 37 | oTipo := TRttiContext.Create.GetType(oObjeto.classType); 38 | finally 39 | FreeAndNil(oObjeto); 40 | end; 41 | 42 | try 43 | for oObjeto in Lista do 44 | begin 45 | oLines.Clear; 46 | for oPropriedade in oTipo.GetProperties do 47 | begin 48 | oFormat := oPropriedade.GetAttribute; 49 | oValue := oPropriedade.GetValue(oObjeto); 50 | 51 | case oValue.Kind of 52 | tkString, tkWChar, tkLString, tkWString, tkVariant, tkUString: 53 | oLines.Append(oValue.ToString.PadRight(oFormat.MaxSize)); 54 | tkInteger, tkInt64: 55 | oLines.Append(oValue.ToString.PadLeft(oFormat.MaxSize, '0')); 56 | tkFloat: 57 | begin 58 | if oValue.TypeInfo = TypeInfo(Real) then 59 | oLines.Append(FormatFloat(oFormat.GetNumericMask, oValue.AsExtended)); 60 | 61 | if (oValue.TypeInfo = TypeInfo(TDate)) 62 | or (oValue.TypeInfo = TypeInfo(TTime)) 63 | or (oValue.TypeInfo = TypeInfo(TDateTime)) then 64 | oLines.Append(FormatDateTime(oFormat.Mask, oValue.AsExtended)); 65 | end; 66 | end; 67 | end; 68 | oRelatorio.Add(oLines.ToString); 69 | end; 70 | sPastaRelatorio := ExtractFilePath(ParamStr(0)) + '\report'; 71 | ForceDirectories(sPastaRelatorio); 72 | oRelatorio.SaveToFile(sPastaRelatorio + '\rel.txt'); 73 | finally 74 | FreeAndNil(oLines); 75 | FreeAndNil(oRelatorio); 76 | end; 77 | end; 78 | 79 | end. 80 | -------------------------------------------------------------------------------- /Sample/Validation/SimpleORMValidation.dpr: -------------------------------------------------------------------------------- 1 | program SimpleORMValidation; 2 | 3 | uses 4 | Vcl.Forms, 5 | Winapi.Windows, 6 | ufCliente in 'View\ufCliente.pas' {fCliente}, 7 | Entidade.Cliente in 'Entidade\Entidade.Cliente.pas', 8 | ufBase in 'Base\View\ufBase.pas' {fBase}, 9 | uExport in 'Export\uExport.pas'; 10 | 11 | {$R *.res} 12 | 13 | begin 14 | ReportMemoryLeaksOnShutdown := IsDebuggerPresent; 15 | 16 | Application.Initialize; 17 | Application.MainFormOnTaskbar := True; 18 | Application.CreateForm(TfCliente, fCliente); 19 | Application.Run; 20 | end. 21 | -------------------------------------------------------------------------------- /Sample/Validation/SimpleORMValidation.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/Validation/SimpleORMValidation.res -------------------------------------------------------------------------------- /Sample/Validation/View/ufCliente.dfm: -------------------------------------------------------------------------------- 1 | inherited fCliente: TfCliente 2 | Caption = 'Cadastro de Clientes' 3 | ClientHeight = 526 4 | OnShow = FormShow 5 | ExplicitHeight = 565 6 | PixelsPerInch = 96 7 | TextHeight = 13 8 | object Label1: TLabel [0] 9 | Left = 8 10 | Top = 260 11 | Width = 24 12 | Height = 13 13 | Anchors = [akLeft, akBottom] 14 | Caption = 'Sexo' 15 | FocusControl = cbxSexo 16 | end 17 | object Label2: TLabel [1] 18 | Left = 138 19 | Top = 260 20 | Width = 55 21 | Height = 13 22 | Anchors = [akLeft, akBottom] 23 | Caption = 'Nascimento' 24 | FocusControl = dtpNascimento 25 | end 26 | object Label3: TLabel [2] 27 | Left = 250 28 | Top = 260 29 | Width = 44 30 | Height = 13 31 | Anchors = [akLeft, akBottom] 32 | Caption = 'Cadastro' 33 | FocusControl = dtpCadastro 34 | end 35 | object Label4: TLabel [3] 36 | Left = 360 37 | Top = 260 38 | Width = 35 39 | Height = 13 40 | Anchors = [akLeft, akBottom] 41 | Caption = 'Cr'#233'dito' 42 | FocusControl = edtCredito 43 | end 44 | object Label5: TLabel [4] 45 | Left = 8 46 | Top = 212 47 | Width = 45 48 | Height = 13 49 | Anchors = [akLeft, akBottom] 50 | Caption = 'Endere'#231'o' 51 | FocusControl = edtEndereco 52 | end 53 | object Label6: TLabel [5] 54 | Left = 8 55 | Top = 165 56 | Width = 33 57 | Height = 13 58 | Anchors = [akLeft, akBottom] 59 | Caption = 'C'#243'digo' 60 | FocusControl = edtCodigo 61 | end 62 | object Label7: TLabel [6] 63 | Left = 87 64 | Top = 165 65 | Width = 27 66 | Height = 13 67 | Anchors = [akLeft, akBottom] 68 | Caption = 'Nome' 69 | FocusControl = edtNome 70 | end 71 | object Label8: TLabel [7] 72 | Left = 323 73 | Top = 165 74 | Width = 54 75 | Height = 13 76 | Anchors = [akLeft, akBottom] 77 | Caption = 'Documento' 78 | FocusControl = edtDocumento 79 | end 80 | inherited Label9: TLabel 81 | Caption = 'Busca: Tabela Clientes' 82 | ExplicitWidth = 158 83 | end 84 | inherited btnCancelar: TButton 85 | Top = 307 86 | TabOrder = 12 87 | ExplicitTop = 307 88 | end 89 | inherited btnNovo: TButton 90 | Top = 307 91 | TabOrder = 8 92 | ExplicitTop = 307 93 | end 94 | inherited pnlErros: TPanel 95 | Top = 376 96 | TabOrder = 14 97 | ExplicitTop = 376 98 | end 99 | inherited btnSalvar: TButton 100 | Top = 307 101 | TabOrder = 11 102 | ExplicitTop = 307 103 | end 104 | inherited btnExcluir: TButton 105 | Top = 307 106 | TabOrder = 10 107 | ExplicitTop = 307 108 | end 109 | inherited btnEditar: TButton 110 | Top = 307 111 | TabOrder = 9 112 | ExplicitTop = 307 113 | end 114 | inherited grdDados: TDBGrid 115 | Height = 104 116 | Anchors = [akLeft, akTop, akRight, akBottom] 117 | TabOrder = 15 118 | end 119 | object edtCodigo: TEdit [16] 120 | Left = 8 121 | Top = 184 122 | Width = 73 123 | Height = 21 124 | Anchors = [akLeft, akBottom] 125 | NumbersOnly = True 126 | TabOrder = 0 127 | end 128 | object edtNome: TEdit [17] 129 | Left = 87 130 | Top = 184 131 | Width = 230 132 | Height = 21 133 | Anchors = [akLeft, akBottom] 134 | TabOrder = 1 135 | end 136 | object edtDocumento: TEdit [18] 137 | Left = 323 138 | Top = 184 139 | Width = 115 140 | Height = 21 141 | Anchors = [akLeft, akBottom] 142 | TabOrder = 2 143 | end 144 | object edtEndereco: TEdit [19] 145 | Left = 8 146 | Top = 231 147 | Width = 430 148 | Height = 21 149 | Anchors = [akLeft, akBottom] 150 | TabOrder = 3 151 | end 152 | object edtCredito: TEdit [20] 153 | Left = 360 154 | Top = 279 155 | Width = 78 156 | Height = 21 157 | Anchors = [akLeft, akBottom] 158 | NumbersOnly = True 159 | TabOrder = 7 160 | end 161 | object cbxSexo: TComboBox [21] 162 | Left = 8 163 | Top = 279 164 | Width = 124 165 | Height = 21 166 | Anchors = [akLeft, akBottom] 167 | TabOrder = 4 168 | Items.Strings = ( 169 | 'Masculino' 170 | 'Feminino') 171 | end 172 | object btnGerarRelatorio: TButton [22] 173 | Left = 8 174 | Top = 338 175 | Width = 210 176 | Height = 25 177 | Anchors = [akLeft, akBottom] 178 | Caption = 'Gerar Relat'#243'rio' 179 | TabOrder = 13 180 | OnClick = btnGerarRelatorioClick 181 | end 182 | object dtpNascimento: TDateTimePicker [23] 183 | Left = 138 184 | Top = 280 185 | Width = 100 186 | Height = 21 187 | Anchors = [akLeft, akBottom] 188 | Date = 44082.000000000000000000 189 | Time = 0.466106226849660700 190 | TabOrder = 5 191 | end 192 | object dtpCadastro: TDateTimePicker [24] 193 | Left = 250 194 | Top = 280 195 | Width = 100 196 | Height = 21 197 | Anchors = [akLeft, akBottom] 198 | Date = 44082.000000000000000000 199 | Time = 0.466106226849660700 200 | TabOrder = 6 201 | end 202 | inherited edtPesquisar: TEdit 203 | TabOrder = 16 204 | OnKeyUp = edtPesquisarKeyUp 205 | end 206 | object btnGerarJson: TButton [26] 207 | Left = 228 208 | Top = 338 209 | Width = 210 210 | Height = 25 211 | Anchors = [akLeft, akBottom] 212 | Caption = 'Gerar JSON' 213 | TabOrder = 17 214 | OnClick = btnGerarJsonClick 215 | end 216 | end 217 | -------------------------------------------------------------------------------- /Sample/Validation/View/ufCliente.pas: -------------------------------------------------------------------------------- 1 | unit ufCliente; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, 7 | System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, 8 | ufBase, Vcl.Grids, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ComCtrls, Entidade.Cliente, 9 | SimpleInterface, SimpleDAO, SimpleAttributes, SimpleQueryFiredac, Data.DB, 10 | FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, 11 | FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, 12 | FireDAC.Phys, FireDAC.Phys.FB, FireDAC.Phys.FBDef, FireDAC.VCLUI.Wait, 13 | FireDAC.Comp.Client, Vcl.DBGrids; 14 | 15 | type 16 | TfCliente = class(TfBase) 17 | btnGerarRelatorio: TButton; 18 | Label1: TLabel; 19 | Label2: TLabel; 20 | Label3: TLabel; 21 | Label4: TLabel; 22 | Label5: TLabel; 23 | Label6: TLabel; 24 | Label7: TLabel; 25 | Label8: TLabel; 26 | 27 | [Bind('CODIGO')] 28 | edtCodigo: TEdit; 29 | [Bind('nome')] 30 | edtNome: TEdit; 31 | [Bind('documento')] 32 | edtDocumento: TEdit; 33 | [Bind('Endereco')] 34 | edtEndereco: TEdit; 35 | [Bind('CREDITO')] 36 | edtCredito: TEdit; 37 | [Bind('SEXO')] 38 | cbxSexo: TComboBox; 39 | [Bind('DTNASC')] // Pode usar o nome da propriedade quanto pelo nome do campo no banco de dados 40 | dtpNascimento: TDateTimePicker; 41 | [Bind('DataCadastro')] 42 | dtpCadastro: TDateTimePicker; 43 | btnGerarJson: TButton; 44 | procedure FormCreate(Sender: TObject); 45 | procedure FormShow(Sender: TObject); 46 | procedure btnNovoClick(Sender: TObject); 47 | procedure btnEditarClick(Sender: TObject); 48 | procedure btnExcluirClick(Sender: TObject); 49 | procedure btnSalvarClick(Sender: TObject); 50 | procedure btnCancelarClick(Sender: TObject); 51 | procedure btnGerarRelatorioClick(Sender: TObject); 52 | procedure edtPesquisarKeyUp(Sender: TObject; var Key: Word; 53 | Shift: TShiftState); 54 | procedure btnGerarJsonClick(Sender: TObject); 55 | private 56 | DAOCliente: iSimpleDAO; 57 | procedure BuscarTodosClientes; 58 | end; 59 | 60 | var 61 | fCliente: TfCliente; 62 | 63 | implementation 64 | 65 | uses 66 | SimpleValidator, uExport, System.Generics.Collections; 67 | 68 | {$R *.dfm} 69 | 70 | procedure TfCliente.btnCancelarClick(Sender: TObject); 71 | begin 72 | inherited; 73 | BuscarTodosClientes; 74 | end; 75 | 76 | procedure TfCliente.btnEditarClick(Sender: TObject); 77 | begin 78 | inherited; 79 | edtNome.SetFocus; 80 | edtNome.SelectAll; 81 | end; 82 | 83 | procedure TfCliente.btnExcluirClick(Sender: TObject); 84 | begin 85 | inherited; 86 | DAOCliente.Delete; 87 | BuscarTodosClientes; 88 | end; 89 | 90 | procedure TfCliente.btnNovoClick(Sender: TObject); 91 | begin 92 | inherited; 93 | edtCodigo.Text := '0'; 94 | edtCredito.Text := '0'; 95 | edtCodigo.SetFocus; 96 | edtCodigo.SelectAll; 97 | end; 98 | 99 | procedure TfCliente.btnSalvarClick(Sender: TObject); 100 | var 101 | oCliente: TCliente; 102 | begin 103 | lstSaidas.Clear; 104 | oCliente := TCliente.Create; 105 | try 106 | oCliente.Parse(Self); 107 | TSimpleValidator.Validate(oCliente, lstSaidas.Items); 108 | 109 | if lstSaidas.Items.Count > 0 then 110 | raise Exception.Create('Encontrado Erros de preenchimento!'); 111 | 112 | case FStatus of 113 | stInsercao: 114 | DAOCliente.Insert(oCliente); 115 | stEdicao: 116 | DAOCliente.Update(oCliente); 117 | end; 118 | BuscarTodosClientes; 119 | 120 | inherited; 121 | finally 122 | FreeAndNil(oCliente); 123 | end; 124 | end; 125 | 126 | procedure TfCliente.btnGerarJsonClick(Sender: TObject); 127 | var 128 | oClientes: TClientes; 129 | begin 130 | inherited; 131 | lstSaidas.Items.Clear; 132 | 133 | oClientes := TClientes.Create; 134 | try 135 | oClientes.Parse(dtsDados.DataSet); 136 | lstSaidas.Items.Add(oClientes.ToJSON); 137 | lstSaidas.Items.Add(oClientes.ToJSONRefletion); 138 | finally 139 | FreeAndNil(oClientes); 140 | end; 141 | end; 142 | 143 | procedure TfCliente.btnGerarRelatorioClick(Sender: TObject); 144 | var 145 | oClientes: TClientes; 146 | begin 147 | inherited; 148 | oClientes := TClientes.Create; 149 | try 150 | oClientes.Parse(dtsDados.DataSet); 151 | TExport.TextReport(oClientes); 152 | finally 153 | FreeAndNil(oClientes); 154 | end; 155 | end; 156 | 157 | procedure TfCliente.edtPesquisarKeyUp(Sender: TObject; var Key: Word; 158 | Shift: TShiftState); 159 | begin 160 | inherited; 161 | if Key = VK_RETURN then 162 | begin 163 | DAOCliente 164 | .SQL 165 | .Where(' NOME LIKE '+ QuotedStr('%' + edtPesquisar.Text + '%')) 166 | .OrderBy('ID') 167 | .&End 168 | .Find; 169 | end; 170 | end; 171 | 172 | procedure TfCliente.FormCreate(Sender: TObject); 173 | var 174 | Conn : iSimpleQuery; 175 | begin 176 | inherited; 177 | 178 | Conn := TSimpleQueryFiredac.New(conFireDac); 179 | 180 | 181 | DAOCliente := TSimpleDAO 182 | .New(Conn) 183 | .DataSource(dtsDados) 184 | .BindForm(Self); 185 | end; 186 | 187 | procedure TfCliente.BuscarTodosClientes; 188 | begin 189 | DAOCliente 190 | .SQL 191 | .OrderBy('ID') 192 | .&End 193 | .Find; 194 | end; 195 | 196 | procedure TfCliente.FormShow(Sender: TObject); 197 | begin 198 | inherited; 199 | 200 | BuscarTodosClientes; 201 | end; 202 | 203 | end. 204 | -------------------------------------------------------------------------------- /Sample/horse/Controller/Controller.Produto.pas: -------------------------------------------------------------------------------- 1 | unit Controller.Produto; 2 | 3 | interface 4 | 5 | uses 6 | Horse, 7 | System.JSON, 8 | IdHashMessageDigest; 9 | 10 | procedure Registry(App : THorse); 11 | procedure Get(Req: THorseRequest; Res: THorseResponse; Next: TProc); 12 | procedure GetID(Req: THorseRequest; Res: THorseResponse; Next: TProc); 13 | procedure Insert(Req: THorseRequest; Res: THorseResponse; Next: TProc); 14 | procedure Update(Req: THorseRequest; Res: THorseResponse; Next: TProc); 15 | procedure Delete(Req: THorseRequest; Res: THorseResponse; Next: TProc); 16 | 17 | implementation 18 | 19 | uses Model.DaoGeneric, Model.Entity.Produto; 20 | 21 | 22 | 23 | procedure Registry(App : THorse); 24 | begin 25 | App.Get('/produto', Get); 26 | App.Get('/produto/:id', GetID); 27 | App.Post('/produto', Insert); 28 | App.Put('/produto/:id', Update); 29 | App.Delete('/produto/:id', Delete); 30 | end; 31 | 32 | procedure Get(Req: THorseRequest; Res: THorseResponse; Next: TProc); 33 | var 34 | FDAO : iDAOGeneric; 35 | begin 36 | FDAO := TDAOGeneric.New; 37 | Res.Send(FDAO.Find); 38 | end; 39 | 40 | procedure GetID(Req: THorseRequest; Res: THorseResponse; Next: TProc); 41 | var 42 | FDAO : iDAOGeneric; 43 | begin 44 | FDAO := TDAOGeneric.New; 45 | Res.Send(FDAO.Find(Req.Params.Items['id'])); 46 | end; 47 | 48 | procedure Insert(Req: THorseRequest; Res: THorseResponse; Next: TProc); 49 | begin 50 | 51 | end; 52 | 53 | procedure Update(Req: THorseRequest; Res: THorseResponse; Next: TProc); 54 | begin 55 | 56 | end; 57 | 58 | procedure Delete(Req: THorseRequest; Res: THorseResponse; Next: TProc); 59 | begin 60 | 61 | end; 62 | 63 | 64 | end. 65 | -------------------------------------------------------------------------------- /Sample/horse/DataSetConverter4D.Helper.pas: -------------------------------------------------------------------------------- 1 | unit DataSetConverter4D.Helper; 2 | 3 | interface 4 | 5 | uses 6 | System.JSON, 7 | Data.DB, 8 | DataSetConverter4D, 9 | DataSetConverter4D.Impl; 10 | 11 | type 12 | 13 | TDataSetConverterHelper = class helper for TDataSet 14 | public 15 | function AsJSONObject: TJSONObject; 16 | function AsJSONArray(const AKeysInLowerCase: Boolean = False): TJSONArray; 17 | 18 | function AsJSONObjectString: string; 19 | function AsJSONArrayString: string; 20 | 21 | procedure FromJSONObject(json: TJSONObject); 22 | procedure FromJSONArray(json: TJSONArray); 23 | 24 | procedure RecordFromJSONObject(json: TJSONObject); 25 | end; 26 | 27 | implementation 28 | 29 | { TDataSetConverterHelper } 30 | 31 | function TDataSetConverterHelper.AsJSONArray(const AKeysInLowerCase: Boolean): TJSONArray; 32 | begin 33 | Result := TConverter.New.DataSet(Self).AsJSONArray(AKeysInLowerCase); 34 | end; 35 | 36 | function TDataSetConverterHelper.AsJSONArrayString: string; 37 | var 38 | ja: TJSONArray; 39 | begin 40 | ja := Self.AsJSONArray; 41 | try 42 | Result := ja.ToString; 43 | finally 44 | ja.Free; 45 | end; 46 | end; 47 | 48 | function TDataSetConverterHelper.AsJSONObject: TJSONObject; 49 | begin 50 | Result := TConverter.New.DataSet(Self).AsJSONObject; 51 | end; 52 | 53 | function TDataSetConverterHelper.AsJSONObjectString: string; 54 | var 55 | jo: TJSONObject; 56 | begin 57 | jo := Self.AsJSONObject; 58 | try 59 | Result := jo.ToString; 60 | finally 61 | jo.Free; 62 | end; 63 | end; 64 | 65 | procedure TDataSetConverterHelper.FromJSONArray(json: TJSONArray); 66 | begin 67 | TConverter.New.JSON(json).ToDataSet(Self); 68 | end; 69 | 70 | procedure TDataSetConverterHelper.FromJSONObject(json: TJSONObject); 71 | begin 72 | TConverter.New.JSON(json).ToDataSet(Self); 73 | end; 74 | 75 | procedure TDataSetConverterHelper.RecordFromJSONObject(json: TJSONObject); 76 | begin 77 | TConverter.New.JSON(json).ToRecord(Self); 78 | end; 79 | 80 | end. 81 | -------------------------------------------------------------------------------- /Sample/horse/DataSetConverter4D.Util.pas: -------------------------------------------------------------------------------- 1 | unit DataSetConverter4D.Util; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, 7 | System.DateUtils, 8 | System.JSON, 9 | Data.DB, 10 | DataSetConverter4D; 11 | 12 | function DateTimeToISOTimeStamp(const dateTime: TDateTime): string; 13 | function DateToISODate(const date: TDateTime): string; 14 | function TimeToISOTime(const time: TTime): string; 15 | 16 | function ISOTimeStampToDateTime(const dateTime: string): TDateTime; 17 | function ISODateToDate(const date: string): TDate; 18 | function ISOTimeToTime(const time: string): TTime; 19 | 20 | function NewDataSetField(dataSet: TDataSet; const fieldType: TFieldType; const fieldName: string; 21 | const size: Integer = 0; const origin: string = ''): TField; 22 | 23 | function BooleanToJSON(const value: Boolean): TJSONValue; 24 | function BooleanFieldToType(const booleanField: TBooleanField): TBooleanFieldType; 25 | function DataSetFieldToType(const dataSetField: TDataSetField): TDataSetFieldType; 26 | 27 | implementation 28 | 29 | function DateTimeToISOTimeStamp(const dateTime: TDateTime): string; 30 | var 31 | fs: TFormatSettings; 32 | begin 33 | fs.TimeSeparator := ':'; 34 | Result := FormatDateTime('yyyy-mm-dd hh:nn:ss', dateTime, fs); 35 | end; 36 | 37 | function DateToISODate(const date: TDateTime): string; 38 | begin 39 | Result := FormatDateTime('YYYY-MM-DD', date); 40 | end; 41 | 42 | function TimeToISOTime(const time: TTime): string; 43 | var 44 | fs: TFormatSettings; 45 | begin 46 | fs.TimeSeparator := ':'; 47 | Result := FormatDateTime('hh:nn:ss', time, fs); 48 | end; 49 | 50 | function ISOTimeStampToDateTime(const dateTime: string): TDateTime; 51 | begin 52 | Result := EncodeDateTime(StrToInt(Copy(dateTime, 1, 4)), StrToInt(Copy(dateTime, 6, 2)), StrToInt(Copy(dateTime, 9, 2)), 53 | StrToInt(Copy(dateTime, 12, 2)), StrToInt(Copy(dateTime, 15, 2)), StrToInt(Copy(dateTime, 18, 2)), 0); 54 | end; 55 | 56 | function ISODateToDate(const date: string): TDate; 57 | begin 58 | Result := EncodeDate(StrToInt(Copy(date, 1, 4)), StrToInt(Copy(date, 6, 2)), StrToInt(Copy(date, 9, 2))); 59 | end; 60 | 61 | function ISOTimeToTime(const time: string): TTime; 62 | begin 63 | Result := EncodeTime(StrToInt(Copy(time, 1, 2)), StrToInt(Copy(time, 4, 2)), StrToInt(Copy(time, 7, 2)), 0); 64 | end; 65 | 66 | function NewDataSetField(dataSet: TDataSet; const fieldType: TFieldType; const fieldName: string; 67 | const size: Integer = 0; const origin: string = ''): TField; 68 | begin 69 | Result := DefaultFieldClasses[fieldType].Create(dataSet); 70 | Result.FieldName := fieldName; 71 | 72 | if (Result.FieldName = '') then 73 | Result.FieldName := 'Field' + IntToStr(dataSet.FieldCount + 1); 74 | 75 | Result.FieldKind := fkData; 76 | Result.DataSet := dataSet; 77 | Result.Name := dataSet.Name + Result.FieldName; 78 | Result.Size := size; 79 | Result.Origin := origin; 80 | 81 | if (fieldType in [ftString, ftWideString]) and (size <= 0) then 82 | raise EDataSetConverterException.CreateFmt('Size not defined for field "%s".', [fieldName]); 83 | end; 84 | 85 | function BooleanToJSON(const value: Boolean): TJSONValue; 86 | begin 87 | if value then 88 | Result := TJSONTrue.Create 89 | else 90 | Result := TJSONFalse.Create; 91 | end; 92 | 93 | function BooleanFieldToType(const booleanField: TBooleanField): TBooleanFieldType; 94 | const 95 | DESC_BOOLEAN_FIELD_TYPE: array [TBooleanFieldType] of string = ('Unknown', 'Boolean', 'Integer'); 96 | var 97 | index: Integer; 98 | origin: string; 99 | begin 100 | Result := bfUnknown; 101 | origin := Trim(booleanField.Origin); 102 | for index := Ord(Low(TBooleanFieldType)) to Ord(High(TBooleanFieldType)) do 103 | if (LowerCase(DESC_BOOLEAN_FIELD_TYPE[TBooleanFieldType(index)]) = LowerCase(origin)) then 104 | Exit(TBooleanFieldType(index)); 105 | end; 106 | 107 | function DataSetFieldToType(const dataSetField: TDataSetField): TDataSetFieldType; 108 | const 109 | DESC_DATASET_FIELD_TYPE: array [TDataSetFieldType] of string = ('Unknown', 'JSONObject', 'JSONArray'); 110 | var 111 | index: Integer; 112 | origin: string; 113 | begin 114 | Result := dfUnknown; 115 | origin := Trim(dataSetField.Origin); 116 | for index := Ord(Low(TDataSetFieldType)) to Ord(High(TDataSetFieldType)) do 117 | if (LowerCase(DESC_DATASET_FIELD_TYPE[TDataSetFieldType(index)]) = LowerCase(origin)) then 118 | Exit(TDataSetFieldType(index)); 119 | end; 120 | 121 | end. 122 | -------------------------------------------------------------------------------- /Sample/horse/DataSetConverter4D.pas: -------------------------------------------------------------------------------- 1 | unit DataSetConverter4D; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, 7 | System.JSON, 8 | Data.DB; 9 | 10 | type 11 | 12 | EDataSetConverterException = class(Exception); 13 | 14 | TBooleanFieldType = (bfUnknown, bfBoolean, bfInteger); 15 | TDataSetFieldType = (dfUnknown, dfJSONObject, dfJSONArray); 16 | 17 | IDataSetConverter = interface 18 | ['{8D995E50-A1DC-4426-A603-762E1387E691}'] 19 | function Source(dataSet: TDataSet): IDataSetConverter; overload; 20 | function Source(dataSet: TDataSet; const owns: Boolean): IDataSetConverter; overload; 21 | 22 | function AsJSONObject: TJSONObject; 23 | function AsJSONArray(const AKeysInLowerCase: Boolean = False): TJSONArray; 24 | end; 25 | 26 | IJSONConverter = interface 27 | ['{1B020937-438E-483F-ACB1-44B8B2707500}'] 28 | function Source(json: TJSONObject): IJSONConverter; overload; 29 | function Source(json: TJSONObject; const owns: Boolean): IJSONConverter; overload; 30 | 31 | function Source(json: TJSONArray): IJSONConverter; overload; 32 | function Source(json: TJSONArray; const owns: Boolean): IJSONConverter; overload; 33 | 34 | procedure ToDataSet(dataSet: TDataSet); 35 | procedure ToRecord(dataSet: TDataSet); 36 | end; 37 | 38 | IConverter = interface 39 | ['{52A3BE1E-5116-4A9A-A7B6-3AF0FCEB1D8E}'] 40 | function DataSet: IDataSetConverter; overload; 41 | function DataSet(dataSet: TDataSet): IDataSetConverter; overload; 42 | function DataSet(dataSet: TDataSet; const owns: Boolean): IDataSetConverter; overload; 43 | 44 | function JSON: IJSONConverter; overload; 45 | function JSON(json: TJSONObject): IJSONConverter; overload; 46 | function JSON(json: TJSONObject; const owns: Boolean): IJSONConverter; overload; 47 | 48 | function JSON(json: TJSONArray): IJSONConverter; overload; 49 | function JSON(json: TJSONArray; const owns: Boolean): IJSONConverter; overload; 50 | end; 51 | 52 | implementation 53 | 54 | end. 55 | -------------------------------------------------------------------------------- /Sample/horse/Model/Connection/Model.Connection.pas: -------------------------------------------------------------------------------- 1 | unit Model.Connection; 2 | 3 | interface 4 | 5 | uses 6 | System.JSON, 7 | FireDAC.Stan.Intf, 8 | FireDAC.Stan.Option, 9 | FireDAC.Stan.Error, 10 | FireDAC.UI.Intf, 11 | FireDAC.Phys.Intf, 12 | FireDAC.Stan.Def, 13 | FireDAC.Stan.Pool, 14 | FireDAC.Stan.Async, 15 | FireDAC.Phys, 16 | Data.DB, 17 | FireDAC.Comp.Client, 18 | Firedac.DApt, 19 | FireDAC.Phys.FB, 20 | FireDAC.Phys.FBDef, 21 | System.Generics.Collections; 22 | 23 | var 24 | FDriver : TFDPhysFBDriverLink; 25 | FConnList : TObjectList; 26 | 27 | function Connected : Integer; 28 | procedure Disconnected(Index : Integer); 29 | 30 | implementation 31 | 32 | function Connected : Integer; 33 | begin 34 | if not Assigned(FConnList) then 35 | FConnList := TObjectList.Create; 36 | 37 | FConnList.Add(TFDConnection.Create(nil)); 38 | Result := Pred(FConnList.Count); 39 | FConnList.Items[Result].Params.DriverID := 'FB'; 40 | FConnList.Items[Result].Params.Database := 'D:\Projetos\Componentes\SimpleORM\SimpleORM.git\trunk\Sample\Database\PDVUPDATES.FDB'; 41 | FConnList.Items[Result].Params.UserName := 'SYSDBA'; 42 | FConnList.Items[Result].Params.Password := 'masterkey'; 43 | FConnList.Items[Result].Connected; 44 | end; 45 | 46 | procedure Disconnected(Index : Integer); 47 | begin 48 | FConnList.Items[Index].Connected := False; 49 | FConnList.Items[Index].Free; 50 | FConnList.TrimExcess; 51 | end; 52 | 53 | end. 54 | -------------------------------------------------------------------------------- /Sample/horse/Model/Connection/Model.DaoGeneric.pas: -------------------------------------------------------------------------------- 1 | unit Model.DaoGeneric; 2 | 3 | interface 4 | 5 | uses 6 | System.JSON, 7 | REST.Json, 8 | SimpleInterface, 9 | SimpleDAO, 10 | SimpleAttributes, 11 | SimpleQueryFiredac, 12 | Data.DB, 13 | DataSetConverter4D, 14 | DataSetConverter4D.Impl, 15 | DataSetConverter4D.Helper, 16 | DataSetConverter4D.Util; 17 | 18 | type 19 | 20 | iDAOGeneric = interface 21 | ['{2A6C6ED9-40BC-4AF5-A635-26615D8DD321}'] 22 | function Find : TJsonArray; overload; 23 | function Find (const aID : String; var aObject : T ) : iDAOGeneric; overload; 24 | function Find (const aID : String ) : TJsonObject; overload; 25 | function Insert (const aJsonObject : TJsonObject) : TJsonObject; 26 | function Update (const aJsonObject : TJsonObject) : TJsonObject; overload; 27 | function Update (const aObject : T) : iDAOGeneric; overload; 28 | function Delete (aField : String; aValue : String) : TJsonObject; 29 | function DAO : ISimpleDAO; 30 | function DataSetAsJsonArray : TJsonArray; 31 | function DataSetAsJsonObject : TJsonObject; 32 | function DataSet : TDataSet; 33 | end; 34 | 35 | TDAOGeneric = class(TInterfacedObject, iDAOGeneric) 36 | private 37 | FIndexConn : Integer; 38 | FConn : iSimpleQuery; 39 | FDAO : iSimpleDAO; 40 | FDataSource : TDataSource; 41 | public 42 | constructor Create; 43 | destructor Destroy; override; 44 | class function New : iDAOGeneric; 45 | function Find : TJsonArray; overload; 46 | function Find (const aID : String; var aObject : T ) : iDAOGeneric; overload; 47 | function Find (const aID : String ) : TJsonObject; overload; 48 | function Insert (const aJsonObject : TJsonObject) : TJsonObject; 49 | function Update (const aJsonObject : TJsonObject) : TJsonObject; overload; 50 | function Update (const aObject : T) : iDAOGeneric; overload; 51 | function Delete (aField : String; aValue : String) : TJsonObject; 52 | function DAO : ISimpleDAO; 53 | function DataSetAsJsonArray : TJsonArray; 54 | function DataSetAsJsonObject : TJsonObject; 55 | function DataSet : TDataSet; 56 | end; 57 | 58 | implementation 59 | 60 | { TDAOGeneric } 61 | 62 | uses Model.Connection, System.SysUtils; 63 | 64 | constructor TDAOGeneric.Create; 65 | begin 66 | FDataSource := TDataSource.Create(nil); 67 | FIndexConn := Model.Connection.Connected; 68 | FConn := TSimpleQueryFiredac.New(Model.Connection.FConnList.Items[FIndexConn]); 69 | FDAO := TSimpleDAO.New(FConn).DataSource(FDataSource); 70 | end; 71 | 72 | function TDAOGeneric.DAO: ISimpleDAO; 73 | begin 74 | Result := FDAO; 75 | end; 76 | 77 | function TDAOGeneric.DataSet: TDataSet; 78 | begin 79 | Result := FDataSource.DataSet; 80 | end; 81 | 82 | function TDAOGeneric.DataSetAsJsonArray: TJsonArray; 83 | begin 84 | Result := FDataSource.DataSet.AsJSONArray; 85 | end; 86 | 87 | function TDAOGeneric.DataSetAsJsonObject: TJsonObject; 88 | begin 89 | Result := FDataSource.DataSet.AsJSONObject; 90 | end; 91 | 92 | function TDAOGeneric.Delete(aField, aValue: String): TJsonObject; 93 | begin 94 | FDAO.Delete(aField, aValue); 95 | Result := FDataSource.DataSet.AsJSONObject; 96 | end; 97 | 98 | destructor TDAOGeneric.Destroy; 99 | begin 100 | FDataSource.Free; 101 | Model.Connection.Disconnected(FIndexConn); 102 | inherited; 103 | end; 104 | 105 | function TDAOGeneric.Find(const aID: String; var aObject: T): iDAOGeneric; 106 | begin 107 | Result := Self; 108 | aObject := FDAO.Find(StrToInt(aID)); 109 | end; 110 | 111 | function TDAOGeneric.Find(const aID: String): TJsonObject; 112 | begin 113 | FDAO.Find(StrToInt(aID)); 114 | Result := FDataSource.DataSet.AsJSONObject; 115 | end; 116 | 117 | function TDAOGeneric.Find: TJsonArray; 118 | begin 119 | FDAO.Find; 120 | Result := FDataSource.DataSet.AsJSONArray; 121 | end; 122 | 123 | function TDAOGeneric.Insert(const aJsonObject: TJsonObject): TJsonObject; 124 | begin 125 | FDAO.Insert(TJson.JsonToObject(aJsonObject)); 126 | Result := FDataSource.DataSet.AsJSONObject; 127 | end; 128 | 129 | class function TDAOGeneric.New: iDAOGeneric; 130 | begin 131 | Result := Self.Create; 132 | end; 133 | 134 | function TDAOGeneric.Update(const aJsonObject: TJsonObject): TJsonObject; 135 | begin 136 | FDAO.Update(TJson.JsonToObject(aJsonObject)); 137 | Result := FDataSource.DataSet.AsJSONObject; 138 | end; 139 | 140 | function TDAOGeneric.Update(const aObject: T): iDAOGeneric; 141 | begin 142 | FDAO.Update(aObject); 143 | Result := Self; 144 | end; 145 | 146 | end. 147 | -------------------------------------------------------------------------------- /Sample/horse/Model/Entity/Model.Entity.Produto.pas: -------------------------------------------------------------------------------- 1 | unit Model.Entity.Produto; 2 | 3 | interface 4 | 5 | uses 6 | SimpleAttributes; 7 | 8 | type 9 | [Tabela('PRODUTO')] 10 | TPRODUTO = class 11 | private 12 | FGUUID :String; 13 | FCODIGO :String; 14 | FDESCRICAO :String; 15 | FPRECO :Currency; 16 | FNCM :Integer; 17 | FALIQUOTA :Currency; 18 | FST :Integer; 19 | FSTATUS :Integer; 20 | FDATAALTERACAO :TDateTime; 21 | 22 | procedure SetGUUID (const Value :String); 23 | function GetGUUID :String; 24 | 25 | procedure SetCODIGO (const Value :String); 26 | function GetCODIGO :String; 27 | 28 | procedure SetDESCRICAO (const Value :String); 29 | function GetDESCRICAO :String; 30 | 31 | procedure SetPRECO (const Value :Currency); 32 | function GetPRECO :Currency; 33 | 34 | procedure SetNCM (const Value :Integer); 35 | function GetNCM :Integer; 36 | 37 | procedure SetALIQUOTA (const Value :Currency); 38 | function GetALIQUOTA :Currency; 39 | 40 | procedure SetST (const Value :Integer); 41 | function GetST :Integer; 42 | 43 | procedure SetSTATUS (const Value :Integer); 44 | function GetSTATUS :Integer; 45 | 46 | procedure SetDATAALTERACAO (const Value :TDateTime); 47 | function GetDATAALTERACAO :TDateTime; 48 | 49 | 50 | public 51 | constructor Create; 52 | destructor Destroy; override; 53 | procedure Limpar; 54 | [Campo('GUUID'), PK] 55 | property GUUID :String read GetGUUID write SetGUUID; 56 | [Campo('CODIGO')] 57 | property CODIGO :String read GetCODIGO write SetCODIGO; 58 | [Campo('DESCRICAO')] 59 | property DESCRICAO :String read GetDESCRICAO write SetDESCRICAO; 60 | [Campo('PRECO')] 61 | property PRECO :Currency read GetPRECO write SetPRECO; 62 | [Campo('NCM')] 63 | property NCM :Integer read GetNCM write SetNCM; 64 | [Campo('ALIQUOTA')] 65 | property ALIQUOTA :Currency read GetALIQUOTA write SetALIQUOTA; 66 | [Campo('ST')] 67 | property ST :Integer read GetST write SetST; 68 | [Campo('STATUS')] 69 | property STATUS :Integer read GetSTATUS write SetSTATUS; 70 | [Campo('DATAALTERACAO')] 71 | property DATAALTERACAO :TDateTime read GetDATAALTERACAO write SetDATAALTERACAO; 72 | 73 | end; 74 | 75 | implementation 76 | 77 | constructor TPRODUTO.Create; 78 | begin 79 | Limpar; 80 | end; 81 | 82 | destructor TPRODUTO.Destroy; 83 | begin 84 | 85 | inherited; 86 | end; 87 | 88 | procedure TPRODUTO.SetGUUID (const Value :String); 89 | begin 90 | FGUUID := Value; 91 | end; 92 | 93 | function TPRODUTO.GetGUUID :String; 94 | begin 95 | Result := FGUUID; 96 | end; 97 | 98 | procedure TPRODUTO.SetCODIGO (const Value :String); 99 | begin 100 | FCODIGO := Value; 101 | end; 102 | 103 | function TPRODUTO.GetCODIGO :String; 104 | begin 105 | Result := FCODIGO; 106 | end; 107 | 108 | procedure TPRODUTO.SetDESCRICAO (const Value :String); 109 | begin 110 | FDESCRICAO := Value; 111 | end; 112 | 113 | function TPRODUTO.GetDESCRICAO :String; 114 | begin 115 | Result := FDESCRICAO; 116 | end; 117 | 118 | procedure TPRODUTO.SetPRECO (const Value :Currency); 119 | begin 120 | FPRECO := Value; 121 | end; 122 | 123 | function TPRODUTO.GetPRECO :Currency; 124 | begin 125 | Result := FPRECO; 126 | end; 127 | 128 | procedure TPRODUTO.SetNCM (const Value :Integer); 129 | begin 130 | FNCM := Value; 131 | end; 132 | 133 | function TPRODUTO.GetNCM :Integer; 134 | begin 135 | Result := FNCM; 136 | end; 137 | 138 | procedure TPRODUTO.SetALIQUOTA (const Value :Currency); 139 | begin 140 | FALIQUOTA := Value; 141 | end; 142 | 143 | function TPRODUTO.GetALIQUOTA :Currency; 144 | begin 145 | Result := FALIQUOTA; 146 | end; 147 | 148 | procedure TPRODUTO.SetST (const Value :Integer); 149 | begin 150 | FST := Value; 151 | end; 152 | 153 | function TPRODUTO.GetST :Integer; 154 | begin 155 | Result := FST; 156 | end; 157 | 158 | procedure TPRODUTO.SetSTATUS (const Value :Integer); 159 | begin 160 | FSTATUS := Value; 161 | end; 162 | 163 | function TPRODUTO.GetSTATUS :Integer; 164 | begin 165 | Result := FSTATUS; 166 | end; 167 | 168 | procedure TPRODUTO.SetDATAALTERACAO (const Value :TDateTime); 169 | begin 170 | FDATAALTERACAO := Value; 171 | end; 172 | 173 | function TPRODUTO.GetDATAALTERACAO :TDateTime; 174 | begin 175 | Result := FDATAALTERACAO; 176 | end; 177 | 178 | 179 | procedure TPRODUTO.Limpar; 180 | begin 181 | 182 | Self.GUUID := ''; 183 | Self.CODIGO := ''; 184 | Self.DESCRICAO := ''; 185 | Self.PRECO := 0; 186 | Self.NCM := 0; 187 | Self.ALIQUOTA := 0; 188 | Self.ST := 0; 189 | Self.STATUS := 0; 190 | Self.DATAALTERACAO := 0; 191 | 192 | end; 193 | 194 | end. 195 | 196 | -------------------------------------------------------------------------------- /Sample/horse/Model/Model.DaoGeneric.pas: -------------------------------------------------------------------------------- 1 | unit Model.DaoGeneric; 2 | 3 | interface 4 | 5 | uses 6 | System.JSON, 7 | REST.Json, 8 | SimpleInterface, 9 | SimpleDAO, 10 | SimpleAttributes, 11 | SimpleQueryFiredac, 12 | Data.DB, 13 | DataSetConverter4D, 14 | DataSetConverter4D.Impl, 15 | DataSetConverter4D.Helper, 16 | DataSetConverter4D.Util; 17 | 18 | type 19 | 20 | iDAOGeneric = interface 21 | ['{2A6C6ED9-40BC-4AF5-A635-26615D8DD321}'] 22 | function Find : TJsonArray; overload; 23 | function Find (const aID : String; var aObject : T ) : iDAOGeneric; overload; 24 | function Find (const aID : String ) : TJsonObject; overload; 25 | function Insert (const aJsonObject : TJsonObject) : TJsonObject; 26 | function Update (const aJsonObject : TJsonObject) : TJsonObject; overload; 27 | function Update (const aObject : T) : iDAOGeneric; overload; 28 | function Delete (aField : String; aValue : String) : TJsonObject; 29 | function DAO : ISimpleDAO; 30 | function DataSetAsJsonArray : TJsonArray; 31 | function DataSetAsJsonObject : TJsonObject; 32 | function DataSet : TDataSet; 33 | end; 34 | 35 | TDAOGeneric = class(TInterfacedObject, iDAOGeneric) 36 | private 37 | FIndexConn : Integer; 38 | FConn : iSimpleQuery; 39 | FDAO : iSimpleDAO; 40 | FDataSource : TDataSource; 41 | public 42 | constructor Create; 43 | destructor Destroy; override; 44 | class function New : iDAOGeneric; 45 | function Find : TJsonArray; overload; 46 | function Find (const aID : String; var aObject : T ) : iDAOGeneric; overload; 47 | function Find (const aID : String ) : TJsonObject; overload; 48 | function Insert (const aJsonObject : TJsonObject) : TJsonObject; 49 | function Update (const aJsonObject : TJsonObject) : TJsonObject; overload; 50 | function Update (const aObject : T) : iDAOGeneric; overload; 51 | function Delete (aField : String; aValue : String) : TJsonObject; 52 | function DAO : ISimpleDAO; 53 | function DataSetAsJsonArray : TJsonArray; 54 | function DataSetAsJsonObject : TJsonObject; 55 | function DataSet : TDataSet; 56 | end; 57 | 58 | implementation 59 | 60 | { TDAOGeneric } 61 | 62 | uses Model.Connection, System.SysUtils; 63 | 64 | constructor TDAOGeneric.Create; 65 | begin 66 | FDataSource := TDataSource.Create(nil); 67 | FIndexConn := Model.Connection.Connected; 68 | FConn := TSimpleQueryFiredac.New(Model.Connection.FConnList.Items[FIndexConn]); 69 | FDAO := TSimpleDAO.New(FConn).DataSource(FDataSource); 70 | end; 71 | 72 | function TDAOGeneric.DAO: ISimpleDAO; 73 | begin 74 | Result := FDAO; 75 | end; 76 | 77 | function TDAOGeneric.DataSet: TDataSet; 78 | begin 79 | Result := FDataSource.DataSet; 80 | end; 81 | 82 | function TDAOGeneric.DataSetAsJsonArray: TJsonArray; 83 | begin 84 | Result := FDataSource.DataSet.AsJSONArray; 85 | end; 86 | 87 | function TDAOGeneric.DataSetAsJsonObject: TJsonObject; 88 | begin 89 | Result := FDataSource.DataSet.AsJSONObject; 90 | end; 91 | 92 | function TDAOGeneric.Delete(aField, aValue: String): TJsonObject; 93 | begin 94 | FDAO.Delete(aField, aValue); 95 | Result := FDataSource.DataSet.AsJSONObject; 96 | end; 97 | 98 | destructor TDAOGeneric.Destroy; 99 | begin 100 | FDataSource.Free; 101 | Model.Connection.Disconnected(FIndexConn); 102 | inherited; 103 | end; 104 | 105 | function TDAOGeneric.Find(const aID: String; var aObject: T): iDAOGeneric; 106 | begin 107 | Result := Self; 108 | aObject := FDAO.Find(StrToInt(aID)); 109 | end; 110 | 111 | function TDAOGeneric.Find(const aID: String): TJsonObject; 112 | begin 113 | FDAO.Find(StrToInt(aID)); 114 | Result := FDataSource.DataSet.AsJSONObject; 115 | end; 116 | 117 | function TDAOGeneric.Find: TJsonArray; 118 | begin 119 | FDAO.Find; 120 | Result := FDataSource.DataSet.AsJSONArray; 121 | end; 122 | 123 | function TDAOGeneric.Insert(const aJsonObject: TJsonObject): TJsonObject; 124 | begin 125 | FDAO.Insert(TJson.JsonToObject(aJsonObject)); 126 | Result := FDataSource.DataSet.AsJSONObject; 127 | end; 128 | 129 | class function TDAOGeneric.New: iDAOGeneric; 130 | begin 131 | Result := Self.Create; 132 | end; 133 | 134 | function TDAOGeneric.Update(const aJsonObject: TJsonObject): TJsonObject; 135 | begin 136 | FDAO.Update(TJson.JsonToObject(aJsonObject)); 137 | Result := FDataSource.DataSet.AsJSONObject; 138 | end; 139 | 140 | function TDAOGeneric.Update(const aObject: T): iDAOGeneric; 141 | begin 142 | FDAO.Update(aObject); 143 | Result := Self; 144 | end; 145 | 146 | end. 147 | -------------------------------------------------------------------------------- /Sample/horse/Project1.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/horse/Project1.res -------------------------------------------------------------------------------- /Sample/horse/SimpleORMHorse.dpr: -------------------------------------------------------------------------------- 1 | program SimpleORMHorse; 2 | 3 | {$APPTYPE CONSOLE} 4 | 5 | {$R *.res} 6 | 7 | uses 8 | Horse, 9 | Horse.Jhonson, 10 | Horse.CORS, 11 | Model.Connection in 'Model\Connection\Model.Connection.pas', 12 | DataSetConverter4D.Helper in 'DataSetConverter4D.Helper.pas', 13 | DataSetConverter4D.Impl in 'DataSetConverter4D.Impl.pas', 14 | DataSetConverter4D in 'DataSetConverter4D.pas', 15 | DataSetConverter4D.Util in 'DataSetConverter4D.Util.pas', 16 | Controller.Produto in 'Controller\Controller.Produto.pas', 17 | Model.Entity.Produto in 'Model\Entity\Model.Entity.Produto.pas', 18 | Model.DaoGeneric in 'Model\Connection\Model.DaoGeneric.pas'; 19 | 20 | var 21 | App : THorse; 22 | 23 | begin 24 | App := THorse.Create(9000); 25 | App.Use(JHonson); 26 | App.Use(CORS); 27 | 28 | Controller.Produto.Registry(App); 29 | 30 | App.Start; 31 | end. 32 | -------------------------------------------------------------------------------- /Sample/horse/SimpleORMHorse.dproj.local: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /Sample/horse/SimpleORMHorse.identcache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/horse/SimpleORMHorse.identcache -------------------------------------------------------------------------------- /Sample/horse/SimpleORMHorse.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/Sample/horse/SimpleORMHorse.res -------------------------------------------------------------------------------- /Sample/horse/boss-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "hash": "d41d8cd98f00b204e9800998ecf8427e", 3 | "updated": "2020-08-28T14:32:10.0686541-03:00", 4 | "installedModules": { 5 | "github.com/hashload/horse": { 6 | "name": "horse", 7 | "version": "1.7.8", 8 | "hash": "533f53d4f7f3f64544271a4dda9c227c", 9 | "artifacts": {}, 10 | "failed": false, 11 | "changed": true 12 | }, 13 | "https://github.com/bittencourtthulio/simpleorm": { 14 | "name": "simpleorm", 15 | "version": "master", 16 | "hash": "d6f21ea61cbbb8aebf2ca83b9f7a9835", 17 | "artifacts": {}, 18 | "failed": false, 19 | "changed": false 20 | }, 21 | "https://github.com/ezequieljuliano/datasetconverter4delphi": { 22 | "name": "datasetconverter4delphi", 23 | "version": "master", 24 | "hash": "5d030308c84a928e3767ae9d9f8a317f", 25 | "artifacts": {}, 26 | "failed": false, 27 | "changed": false 28 | }, 29 | "https://github.com/hashload/horse": { 30 | "name": "horse", 31 | "version": "v2.0-alpha.1", 32 | "hash": "533f53d4f7f3f64544271a4dda9c227c", 33 | "artifacts": {}, 34 | "failed": false, 35 | "changed": false 36 | }, 37 | "https://github.com/hashload/horse-cors": { 38 | "name": "horse-cors", 39 | "version": "1.0.2", 40 | "hash": "f1fd91acb4d43c9a778249d447027f16", 41 | "artifacts": {}, 42 | "failed": false, 43 | "changed": false 44 | }, 45 | "https://github.com/hashload/jhonson": { 46 | "name": "jhonson", 47 | "version": "1.0.5", 48 | "hash": "34d01183ef1b6af802c7e132adedeae5", 49 | "artifacts": {}, 50 | "failed": false, 51 | "changed": false 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /Sample/horse/boss.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "horse", 3 | "description": "", 4 | "version": "1.0.0", 5 | "homepage": "", 6 | "mainsrc": "./", 7 | "projects": [], 8 | "dependencies": { 9 | "https://github.com/bittencourtthulio/simpleorm": ">0.0.0", 10 | "https://github.com/ezequieljuliano/datasetconverter4delphi": ">0.0.0", 11 | "https://github.com/hashload/horse": "^v2.0-alpha.1", 12 | "https://github.com/hashload/horse-cors": "^1.0.2", 13 | "https://github.com/hashload/jhonson": "^1.0.5" 14 | } 15 | } -------------------------------------------------------------------------------- /SimpleAttributes.pas: -------------------------------------------------------------------------------- 1 | unit SimpleAttributes; 2 | 3 | interface 4 | 5 | uses 6 | System.RTTI, System.Variants, System.Classes; 7 | 8 | type 9 | Tabela = class(TCustomAttribute) 10 | private 11 | FName: string; 12 | public 13 | constructor Create(aName: string); 14 | property Name: string read FName; 15 | end; 16 | 17 | Campo = class(TCustomAttribute) 18 | private 19 | FName: string; 20 | public 21 | Constructor Create(aName: string); 22 | property Name: string read FName; 23 | end; 24 | 25 | PK = class(TCustomAttribute) 26 | end; 27 | 28 | FK = class(TCustomAttribute) 29 | end; 30 | 31 | NotNull = class(TCustomAttribute) 32 | end; 33 | 34 | Ignore = class(TCustomAttribute) 35 | end; 36 | 37 | AutoInc = class(TCustomAttribute) 38 | end; 39 | 40 | NumberOnly = class(TCustomAttribute) 41 | end; 42 | 43 | Bind = class(TCustomAttribute) 44 | private 45 | FField: String; 46 | procedure SetField(const Value: String); 47 | public 48 | constructor Create (aField : String); 49 | property Field : String read FField write SetField; 50 | end; 51 | 52 | Display = class(TCustomAttribute) 53 | private 54 | FName: string; 55 | public 56 | constructor Create(const aName: string); 57 | property Name: string read FName write FName; 58 | end; 59 | 60 | Format = class(TCustomAttribute) 61 | private 62 | FMaxSize: integer; 63 | FPrecision: integer; 64 | FMask: string; 65 | FMinSize: integer; 66 | public 67 | property MaxSize: integer read FMaxSize write FMaxSize; 68 | property MinSize: integer read FMinSize write FMinSize; 69 | property Precision: integer read FPrecision write FPrecision; 70 | property Mask: string read FMask write FMask; 71 | function GetNumericMask: string; 72 | constructor Create(const aSize: Integer; const aPrecision: integer = 0); overload; 73 | constructor Create(const aMask: string); overload; 74 | constructor Create(const aRange: array of Integer); overload; 75 | end; 76 | 77 | Relationship = class abstract(TCustomAttribute) 78 | private 79 | FEntityName: string; 80 | public 81 | constructor Create(const aEntityName: string); 82 | property EntityName: string read FEntityName write FEntityName; 83 | end; 84 | 85 | HasOne = class(Relationship) 86 | end; 87 | 88 | BelongsTo = class(Relationship) 89 | end; 90 | 91 | HasMany = class(Relationship) 92 | end; 93 | 94 | BelongsToMany = class(Relationship) 95 | end; 96 | 97 | Enumerator = class(TCustomAttribute) 98 | private 99 | FTipo: string; 100 | public 101 | Constructor Create(aTipo: string); 102 | property Tipo: string read FTipo; 103 | end; 104 | 105 | implementation 106 | 107 | 108 | { Bind } 109 | 110 | constructor Bind.Create(aField: String); 111 | begin 112 | FField := aField; 113 | end; 114 | 115 | procedure Bind.SetField(const Value: String); 116 | begin 117 | FField := Value; 118 | end; 119 | 120 | { Tabela } 121 | 122 | constructor Tabela.Create(aName: string); 123 | begin 124 | FName := aName; 125 | end; 126 | 127 | { Campo } 128 | 129 | constructor Campo.Create(aName: string); 130 | begin 131 | FName := aName; 132 | end; 133 | 134 | { Display } 135 | 136 | constructor Display.Create(const aName: string); 137 | begin 138 | FName := aName; 139 | end; 140 | 141 | { Formato } 142 | 143 | constructor Format.Create(const aSize, aPrecision: integer); 144 | begin 145 | FMaxSize := aSize; 146 | FPrecision := aPrecision; 147 | end; 148 | 149 | constructor Format.Create(const aMask: string); 150 | begin 151 | FMask := aMask; 152 | end; 153 | 154 | constructor Format.Create(const aRange: array of Integer); 155 | begin 156 | FMinSize := aRange[0]; 157 | FMaxSize := aRange[High(aRange)]; 158 | end; 159 | 160 | function Format.GetNumericMask: string; 161 | var 162 | sTamanho, sPrecisao: string; 163 | begin 164 | sTamanho := StringOfChar('0', FMaxSize - FPrecision); 165 | sPrecisao := StringOfChar('0', FPrecision); 166 | 167 | Result := sTamanho + '.' + sPrecisao; 168 | end; 169 | 170 | { Relationship } 171 | 172 | constructor Relationship.Create(const aEntityName: string); 173 | begin 174 | FEntityName := aEntityName; 175 | end; 176 | 177 | { Enumerator } 178 | 179 | constructor Enumerator.Create(aTipo: string); 180 | begin 181 | FTipo := aTipo; 182 | end; 183 | 184 | end. 185 | -------------------------------------------------------------------------------- /SimpleDAOSQLAttribute.pas: -------------------------------------------------------------------------------- 1 | unit SimpleDAOSQLAttribute; 2 | 3 | interface 4 | 5 | uses 6 | SimpleInterface; 7 | 8 | Type 9 | TSimpleDAOSQLAttribute = class(TInterfacedObject, 10 | iSimpleDAOSQLAttribute) 11 | private 12 | [weak] 13 | FParent: iSimpleDAO; 14 | FFields: String; 15 | FWhere: String; 16 | FOrderBy: String; 17 | FGroupBy: String; 18 | FJoin: String; 19 | public 20 | constructor Create(Parent: iSimpleDAO); 21 | destructor Destroy; override; 22 | class function New(Parent: iSimpleDAO): iSimpleDAOSQLAttribute; 23 | function Fields(aSQL: String): iSimpleDAOSQLAttribute; overload; 24 | function Where(aSQL: String): iSimpleDAOSQLAttribute; overload; 25 | function OrderBy(aSQL: String): iSimpleDAOSQLAttribute; overload; 26 | function GroupBy(aSQL: String): iSimpleDAOSQLAttribute; overload; 27 | function Join(aSQL: String): iSimpleDAOSQLAttribute; overload; 28 | function Join: String; overload; 29 | function Clear: iSimpleDAOSQLAttribute; 30 | function Fields: String; overload; 31 | function Where: String; overload; 32 | function OrderBy: String; overload; 33 | function GroupBy: String; overload; 34 | function &End: iSimpleDAO; 35 | end; 36 | 37 | implementation 38 | 39 | uses 40 | System.SysUtils; 41 | 42 | { TSimpleDAOSQLAttribute } 43 | function TSimpleDAOSQLAttribute.&End: iSimpleDAO; 44 | begin 45 | Result := FParent; 46 | end; 47 | 48 | function TSimpleDAOSQLAttribute.Fields: String; 49 | begin 50 | Result := FFields; 51 | end; 52 | 53 | function TSimpleDAOSQLAttribute.GroupBy: String; 54 | begin 55 | Result := FGroupBy; 56 | end; 57 | 58 | function TSimpleDAOSQLAttribute.Join: String; 59 | begin 60 | Result := FJoin; 61 | end; 62 | 63 | function TSimpleDAOSQLAttribute.Join(aSQL: String) 64 | : iSimpleDAOSQLAttribute; 65 | begin 66 | Result := Self; 67 | if Trim(aSQL) <> '' then 68 | FJoin := FJoin + ' ' + aSQL; 69 | end; 70 | 71 | function TSimpleDAOSQLAttribute.GroupBy(aSQL: String) 72 | : iSimpleDAOSQLAttribute; 73 | begin 74 | Result := Self; 75 | if Trim(aSQL) <> '' then 76 | FGroupBy := FGroupBy + ' ' + aSQL; 77 | end; 78 | 79 | function TSimpleDAOSQLAttribute.Clear: iSimpleDAOSQLAttribute; 80 | begin 81 | Result := Self; 82 | FFields := ''; 83 | FWhere := ''; 84 | FOrderBy := ''; 85 | FGroupBy := ''; 86 | FJoin := ''; 87 | end; 88 | 89 | constructor TSimpleDAOSQLAttribute.Create(Parent: iSimpleDAO); 90 | begin 91 | FParent := Parent; 92 | end; 93 | 94 | destructor TSimpleDAOSQLAttribute.Destroy; 95 | begin 96 | inherited; 97 | end; 98 | 99 | function TSimpleDAOSQLAttribute.Fields(aSQL: String) 100 | : iSimpleDAOSQLAttribute; 101 | begin 102 | Result := Self; 103 | if Trim(aSQL) <> '' then 104 | FFields := FFields + ' ' + aSQL; 105 | end; 106 | 107 | class function TSimpleDAOSQLAttribute.New(Parent: iSimpleDAO) 108 | : iSimpleDAOSQLAttribute; 109 | begin 110 | Result := Self.Create(Parent); 111 | end; 112 | 113 | function TSimpleDAOSQLAttribute.OrderBy: String; 114 | begin 115 | Result := FOrderBy; 116 | end; 117 | 118 | function TSimpleDAOSQLAttribute.OrderBy(aSQL: String) 119 | : iSimpleDAOSQLAttribute; 120 | begin 121 | Result := Self; 122 | if Trim(aSQL) <> '' then 123 | FOrderBy := FOrderBy + ' ' + aSQL; 124 | end; 125 | 126 | function TSimpleDAOSQLAttribute.Where(aSQL: String) 127 | : iSimpleDAOSQLAttribute; 128 | begin 129 | Result := Self; 130 | if Trim(aSQL) <> '' then 131 | FWhere := FWhere + ' ' + aSQL; 132 | end; 133 | 134 | function TSimpleDAOSQLAttribute.Where: String; 135 | begin 136 | Result := FWhere; 137 | end; 138 | 139 | end. 140 | -------------------------------------------------------------------------------- /SimpleEntity.pas: -------------------------------------------------------------------------------- 1 | unit SimpleEntity; 2 | 3 | interface 4 | 5 | uses 6 | {$IFNDEF CONSOLE} 7 | {$IFDEF FMX} 8 | FMX.Forms, 9 | {$ELSE} 10 | Vcl.Forms, 11 | {$ENDIF} 12 | {$ENDIF} 13 | Data.DB, System.Generics.Collections, System.SysUtils; 14 | 15 | type 16 | TSimpleEntity = class 17 | public 18 | {$IFNDEF CONSOLE} 19 | function Parse(const aForm: TForm): TSimpleEntity; overload; virtual; 20 | {$ENDIF} 21 | function Parse(const aDataSet: TDataSet): TSimpleEntity; overload; virtual; 22 | procedure Parse(const psJSON: string); overload; 23 | procedure SaveToFileJSON(const poFileName: TFileName); overload; virtual; 24 | procedure SaveToFileJSON(const poFileName: TFileName; poEncoding: TEncoding); overload; virtual; 25 | function ToJSON: string; 26 | function ToJSONRefletion: string; 27 | end; 28 | 29 | TSimpleEntityList = class(TObjectList) 30 | public 31 | function Parse(const aDataSet: TDataSet): TSimpleEntityList; virtual; 32 | function ToJSON: string; 33 | function ToJSONRefletion: string; 34 | end; 35 | 36 | implementation 37 | 38 | uses 39 | SimpleUtil, SimpleJSONUtil, System.Classes, System.JSON, System.StrUtils; 40 | 41 | { TSimpleEntity } 42 | 43 | function TSimpleEntity.Parse(const aDataSet: TDataSet): TSimpleEntity; 44 | begin 45 | Result := Self; 46 | TSimpleUtil.GetValuesFromDataset(aDataSet, Self); 47 | end; 48 | 49 | procedure TSimpleEntity.SaveToFileJSON(const poFileName: TFileName); 50 | begin 51 | SaveToFileJSON(poFileName, TEncoding.Default); 52 | end; 53 | 54 | procedure TSimpleEntity.Parse(const psJSON: string); 55 | begin 56 | TSimpleJsonUtil.JSONStringToObject(psJSON, Self); 57 | end; 58 | 59 | procedure TSimpleEntity.SaveToFileJSON(const poFileName: TFileName; 60 | poEncoding: TEncoding); 61 | var 62 | oConteudo: TStringList; 63 | begin 64 | oConteudo := TStringList.Create; 65 | try 66 | oConteudo.Text := ToJSON; 67 | if ForceDirectories(ExtractFilePath(poFileName)) then 68 | oConteudo.SaveToFile(poFileName, poEncoding); 69 | finally 70 | FreeAndNil(oConteudo); 71 | end; 72 | end; 73 | 74 | function DecodeUnicodeEscapes(psEscaped: string): string; 75 | var 76 | FoundPos: LongInt; 77 | HexCode: String; 78 | DecodedChars: String; 79 | begin 80 | Result := psEscaped; 81 | FoundPos := Pos('\u', Result); 82 | while (FoundPos <> 0) and (FoundPos < Length(Result) - 4) do 83 | begin 84 | HexCode := Copy(Result, FoundPos + 2, 4); 85 | DecodedChars := WideChar(StrToInt('$' + HexCode)); 86 | Result := AnsiReplaceStr(Result, '\u' + HexCode, 87 | Utf8ToAnsi(UTF8Encode(DecodedChars))); 88 | FoundPos := Pos('\u', Result); 89 | end; 90 | Result := StringReplace(Result, '\/', '/', [rfReplaceAll]) 91 | end; 92 | 93 | function TSimpleEntity.ToJSON: string; 94 | begin 95 | Result := TSimpleJsonUtil.ObjectToJSONString(Self); 96 | end; 97 | 98 | function TSimpleEntity.ToJSONRefletion: string; 99 | var 100 | oJSONValue: TJSONValue; 101 | begin 102 | oJSONValue := TSimpleJsonUtil.ObjectToJSON(Self); 103 | try 104 | Result := DecodeUnicodeEscapes(oJSONValue.ToJSON); 105 | finally 106 | FreeAndNil(oJSONValue); 107 | end; 108 | end; 109 | 110 | { TSimpleEntityList } 111 | 112 | function TSimpleEntityList.Parse(const aDataSet: TDataSet): TSimpleEntityList; 113 | begin 114 | Result := Self; 115 | Self.Clear; 116 | TSimpleUtil.DataSetToObjectList(aDataSet, Self); 117 | end; 118 | 119 | {$IFNDEF CONSOLE} 120 | 121 | function TSimpleEntity.Parse(const aForm: TForm): TSimpleEntity; 122 | begin 123 | Result := Self; 124 | TSimpleUtil.GetObjectFromForm(aForm, Self); 125 | end; 126 | 127 | {$ENDIF} 128 | 129 | function TSimpleEntityList.ToJSON: string; 130 | begin 131 | Result := TSimpleJsonUtil.ListToJSONArrayString(Self, [jfFormat]); 132 | end; 133 | 134 | function TSimpleEntityList.ToJSONRefletion: string; 135 | var 136 | oJSONArray: TJSONArray; 137 | begin 138 | oJSONArray := TSimpleJsonUtil.ListToJSONArray(Self); 139 | try 140 | Result := oJSONArray.ToJSON; 141 | finally 142 | FreeAndNil(oJSONArray); 143 | end; 144 | end; 145 | 146 | end. 147 | -------------------------------------------------------------------------------- /SimpleInterface.pas: -------------------------------------------------------------------------------- 1 | unit SimpleInterface; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, 7 | System.Generics.Collections, 8 | Data.DB, 9 | System.TypInfo, 10 | {$IFNDEF CONSOLE} 11 | {$IFDEF FMX} 12 | FMX.Forms, 13 | {$ELSE} 14 | Vcl.Forms, 15 | {$ENDIF} 16 | {$ENDIF} 17 | System.SysUtils; 18 | type 19 | iSimpleDAOSQLAttribute = interface; 20 | 21 | iSimpleDAO = interface 22 | ['{19261B52-6122-4C41-9DDE-D3A1247CC461}'] 23 | {$IFNDEF CONSOLE} 24 | function Insert: iSimpleDAO; overload; 25 | function Update : iSimpleDAO; overload; 26 | function Delete : iSimpleDAO; overload; 27 | {$ENDIF} 28 | function Insert(aValue : T) : iSimpleDAO; overload; 29 | function Update(aValue : T) : iSimpleDAO; overload; 30 | function Delete(aValue : T) : iSimpleDAO; overload; 31 | function LastID : iSimpleDAO; 32 | function LastRecord : iSimpleDAO; 33 | function Delete(aField : String; aValue : String) : iSimpleDAO; overload; 34 | function DataSource( aDataSource : TDataSource) : iSimpleDAO; 35 | function Find(aBindList : Boolean = True) : iSimpleDAO; overload; 36 | function Find(var aList : TObjectList) : iSimpleDAO ; overload; 37 | function Find(aId : Integer) : T; overload; 38 | function Find(aKey : String; aValue : Variant) : iSimpleDAO; overload; 39 | function SQL : iSimpleDAOSQLAttribute; 40 | {$IFNDEF CONSOLE} 41 | function BindForm(aForm : TForm) : iSimpleDAO; 42 | {$ENDIF} 43 | end; 44 | 45 | iSimpleDAOSQLAttribute = interface 46 | ['{5DE6F977-336B-4142-ABD1-EB0173FFF71F}'] 47 | function Fields (aSQL : String) : iSimpleDAOSQLAttribute; overload; 48 | function Where (aSQL : String) : iSimpleDAOSQLAttribute; overload; 49 | function OrderBy (aSQL : String) : iSimpleDAOSQLAttribute; overload; 50 | function GroupBy (aSQL : String) : iSimpleDAOSQLAttribute; overload; 51 | function Join (aSQL : String) : iSimpleDAOSQLAttribute; overload; 52 | function Join : String; overload; 53 | function Fields : String; overload; 54 | function Where : String; overload; 55 | function OrderBy : String; overload; 56 | function GroupBy : String; overload; 57 | function Clear : iSimpleDAOSQLAttribute; 58 | function &End : iSimpleDAO; 59 | end; 60 | 61 | iSimpleRTTI = interface 62 | ['{EEC49F47-24AC-4D82-9BEE-C259330A8993}'] 63 | function TableName(var aTableName: String): ISimpleRTTI; 64 | function ClassName (var aClassName : String) : iSimpleRTTI; 65 | function DictionaryFields(var aDictionary : TDictionary) : iSimpleRTTI; 66 | function DictionaryTypeFields(var aDictionary: TDictionary): iSimpleRTTI; 67 | function ListFields (var List : TList) : iSimpleRTTI; 68 | function Update (var aUpdate : String) : iSimpleRTTI; 69 | function Where (var aWhere : String) : iSimpleRTTI; 70 | function Fields (var aFields : String) : iSimpleRTTI; 71 | function FieldsInsert (var aFields : String) : iSimpleRTTI; 72 | function Param (var aParam : String) : iSimpleRTTI; 73 | function DataSetToEntityList (aDataSet : TDataSet; var aList : TObjectList) : iSimpleRTTI; 74 | function DataSetToEntity (aDataSet : TDataSet; var aEntity : T) : iSimpleRTTI; 75 | function PrimaryKey(var aPK : String) : iSimpleRTTI; 76 | {$IFNDEF CONSOLE} 77 | function BindClassToForm (aForm : TForm; const aEntity : T) : iSimpleRTTI; 78 | function BindFormToClass (aForm : TForm; var aEntity : T) : iSimpleRTTI; 79 | {$ENDIF} 80 | end; 81 | 82 | iSimpleSQL = interface 83 | ['{1590A7C6-6E32-4579-9E60-38C966C1EB49}'] 84 | function Insert (var aSQL : String) : iSimpleSQL; 85 | function Update (var aSQL : String) : iSimpleSQL; 86 | function Delete (var aSQL : String) : iSimpleSQL; 87 | function Select (var aSQL : String) : iSimpleSQL; 88 | function SelectId(var aSQL: String): iSimpleSQL; 89 | function Fields (aSQL : String) : iSimpleSQL; 90 | function Where (aSQL : String) : iSimpleSQL; 91 | function OrderBy (aSQL : String) : iSimpleSQL; 92 | function GroupBy (aSQL : String) : iSimpleSQL; 93 | function Join (aSQL : String) : iSimpleSQL; 94 | function LastID (var aSQL : String) : iSimpleSQL; 95 | function LastRecord (var aSQL : String) : iSimpleSQL; 96 | end; 97 | 98 | iSimpleQuery = interface 99 | ['{6DCCA942-736D-4C66-AC9B-94151F14853A}'] 100 | function SQL : TStrings; 101 | function Params : TParams; 102 | function ExecSQL : iSimpleQuery; 103 | function DataSet : TDataSet; 104 | function Open(aSQL : String) : iSimpleQuery; overload; 105 | function Open : iSimpleQuery; overload; 106 | end; 107 | 108 | 109 | 110 | implementation 111 | 112 | end. 113 | -------------------------------------------------------------------------------- /SimpleJSONUtil.pas: -------------------------------------------------------------------------------- 1 | unit SimpleJSONUtil; 2 | 3 | interface 4 | 5 | uses 6 | Data.DBXJSON, Data.DBXJSONReflect, System.Generics.Collections, System.JSON, 7 | REST.JSON, REST.Response.Adapter, Data.DB, System.SysUtils, System.Classes; 8 | 9 | type 10 | TJsonFlags = set of (jfFormat); 11 | 12 | TSimpleJsonUtil = class 13 | private 14 | class var 15 | JSONMarshal: TJSONMarshal; 16 | class var 17 | JSONUnMarshal: TJSONUnMarshal; 18 | public 19 | class function ObjectToJSON(poObject: TObject): TJSONValue; 20 | class function ObjectToJSONString(poObject: TObject): string; 21 | 22 | class function JSONToObject(const psJSON: string): T; overload; 23 | class function JSONToObject(const poJSON: TJSONValue): T; overload; 24 | 25 | class procedure JSONStringToObject(const psJSON: string; poObject: TObject); 26 | class function ListToJSONArray(poList: TObjectList): TJSONArray; 27 | 28 | class function ListToJSONArrayString(poList: TObjectList; 29 | const paJsonFlags: TJsonFlags = []): string; overload; 30 | class function ListToJSONArrayString(poList: TStringList; 31 | const paJsonFlags: TJsonFlags = []): string; overload; 32 | class function ListToJSONArrayString(poList: TObject; 33 | const paJsonFlags: TJsonFlags = []): string; overload; 34 | 35 | class function JSONArrayToList(const psJSONArray: string): 36 | TObjectList; overload; 37 | class function JSONArrayToList(poJSONArray: TJSONArray): 38 | TObjectList; overload; 39 | 40 | class procedure JSONToDataset(const poDataset: TDataSet; const poJSON: string); 41 | end; 42 | 43 | implementation 44 | 45 | uses 46 | System.Rtti, SimpleJSON, SimpleRTTIHelper; 47 | 48 | { TJsonUtil } 49 | 50 | class function TSimpleJsonUtil.JSONArrayToList(poJSONArray: TJSONArray): TObjectList; 51 | var 52 | i: Integer; 53 | begin 54 | Result := TObjectList.Create; 55 | for i := 0 to poJSONArray.Count - 1 do 56 | Result.Add(Self.JSONToObject(poJSONArray.Items[i])); 57 | end; 58 | 59 | class procedure TSimpleJsonUtil.JSONToDataset(const poDataset: TDataSet; const 60 | poJSON: string); 61 | var 62 | JObj: TJSONArray; 63 | vConv: TCustomJSONDataSetAdapter; 64 | begin 65 | if (poJSON = EmptyStr) then 66 | Exit; 67 | 68 | JObj := TJSONObject.ParseJSONValue(poJSON) as TJSONArray; 69 | vConv := TCustomJSONDataSetAdapter.Create(Nil); 70 | 71 | try 72 | vConv.Dataset := poDataset; 73 | vConv.UpdateDataSet(JObj); 74 | finally 75 | FreeAndNil(vConv); 76 | FreeAndNil(JObj); 77 | end; 78 | end; 79 | 80 | class function TSimpleJsonUtil.JSONArrayToList(const psJSONArray: string): TObjectList; 81 | var 82 | OJSONArray: TJSONArray; 83 | begin 84 | OJSONArray := TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(psJSONArray), 85 | 0) as TJSONArray; 86 | try 87 | Result := JSONArrayToList(OJSONArray); 88 | finally 89 | FreeAndNil(OJSONArray); 90 | end; 91 | end; 92 | 93 | class function TSimpleJsonUtil.JSONToObject(const poJSON: TJSONValue): T; 94 | begin 95 | if (not Assigned(poJSON)) or (poJSON is TJSONNull) then 96 | Exit(nil); 97 | 98 | JSONUnMarshal := TJSONUnMarshal.Create; 99 | try 100 | Result := T(JSONUnMarshal.UnMarshal(poJSON)); 101 | finally 102 | FreeAndNil(JSONUnMarshal); 103 | end; 104 | end; 105 | 106 | class function TSimpleJsonUtil.JSONToObject(const psJSON: string): T; 107 | var 108 | OJSONValue: TJSONValue; 109 | begin 110 | OJSONValue := TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(psJSON), 0); 111 | try 112 | Result := JSONToObject(OJSONValue); 113 | finally 114 | FreeAndNil(OJSONValue); 115 | end; 116 | end; 117 | 118 | class function TSimpleJsonUtil.ListToJSONArray(poList: TObjectList): TJSONArray; 119 | var 120 | i: Integer; 121 | begin 122 | Result := TJSONArray.Create; 123 | for i := 0 to poList.Count - 1 do 124 | Result.AddElement(Self.ObjectToJSON(poList[i])); 125 | end; 126 | 127 | class function TSimpleJsonUtil.ListToJSONArrayString(poList: TObject; 128 | const paJsonFlags: TJsonFlags): string; 129 | begin 130 | Result := ''; 131 | if poList.ClassNameIs('TStringList') then 132 | Result := ListToJSONArrayString(TStringList(poList)) 133 | else 134 | if poList.ClassName.Contains('TSimpleEntityList<') or 135 | poList.ClassName.Contains('TObjectList<') then 136 | Result := ListToJSONArrayString(TObjectList(poList)); 137 | end; 138 | 139 | class function TSimpleJsonUtil.ListToJSONArrayString(poList: TStringList; 140 | const paJsonFlags: TJsonFlags): string; 141 | var 142 | sMyElem: string; 143 | begin 144 | Result := ''; 145 | for sMyElem in poList do 146 | Result := Result + ',' + sMyElem; 147 | 148 | Result := Copy(Result, 2, Length(Result)); 149 | Result := '[' + Result + ']'; 150 | end; 151 | 152 | class function TSimpleJsonUtil.ListToJSONArrayString(poList: TObjectList; 153 | const paJsonFlags: TJsonFlags): string; 154 | var 155 | i: Integer; 156 | oArrayJson: TStringList; 157 | begin 158 | oArrayJson := TStringList.Create; 159 | try 160 | for i := 0 to poList.Count - 1 do 161 | oArrayJson.Add(Self.ObjectToJSONString(poList[i]) + ','); 162 | 163 | Result := oArrayJson.Text; 164 | Result := '[' + Copy(Result, 1, Length(Result)-3) + ']'; 165 | 166 | if not (jfFormat in paJsonFlags) then 167 | Result := StringReplace(Result, sLineBreak, EmptyStr, [rfReplaceAll]); 168 | finally 169 | FreeAndNil(oArrayJson); 170 | end; 171 | end; 172 | 173 | class function TSimpleJsonUtil.ObjectToJSON(poObject: TObject): TJSONValue; 174 | begin 175 | try 176 | if not Assigned(poObject) then 177 | Exit(TJSONNull.Create); 178 | 179 | JSONMarshal := TJSONMarshal.Create(TJSONConverter.Create); 180 | Result := JSONMarshal.Marshal(poObject); 181 | finally 182 | FreeAndNil(JSONMarshal); 183 | end; 184 | end; 185 | 186 | class function TSimpleJsonUtil.ObjectToJSONString(poObject: TObject): string; 187 | var 188 | oRttiContexto: TRttiContext; 189 | oRttiProp: TRttiProperty; 190 | oRttiTipo: TRttiType; 191 | oValue: TValue; 192 | oJson: TSimpleJson; 193 | sArrayTemp: string; 194 | begin 195 | sArrayTemp := ''; 196 | oJson := TSimpleJson.Create; 197 | try 198 | oRttiTipo := oRttiContexto.GetType(poObject.ClassType); 199 | for oRttiProp in oRttiTipo.GetProperties do 200 | begin 201 | oValue := oRttiProp.GetValue(poObject); 202 | if oRttiProp.Name = 'RefCount' then 203 | Continue; 204 | 205 | case oValue.Kind of 206 | tkUString: 207 | begin 208 | if oRttiProp.EhSomenteNumeros then 209 | oJson.Put(oRttiProp.Name, oValue.AsStringNumberOnly) 210 | else 211 | oJson.Put(oRttiProp.Name, oValue.AsString); 212 | end; 213 | tkInteger, tkInt64: 214 | oJson.Put(oRttiProp.Name, oValue.AsInteger); 215 | tkFloat: 216 | begin 217 | if (oValue.TypeInfo = TypeInfo(Real)) 218 | or (oValue.TypeInfo = TypeInfo(Double)) 219 | or (oValue.TypeInfo = TypeInfo(Currency)) then 220 | oJson.Put(oRttiProp.Name, oValue.AsExtended); 221 | 222 | if oValue.TypeInfo = TypeInfo(TDate) then 223 | oJson.Put(oRttiProp.Name, FormatDateTime('dd/MM/yyyy', oValue.AsExtended)); 224 | 225 | if oValue.TypeInfo = TypeInfo(TTime) then 226 | oJson.Put(oRttiProp.Name, FormatDateTime('tt', oValue.AsExtended)); 227 | 228 | if oValue.TypeInfo = TypeInfo(TDateTime) then 229 | oJson.Put(oRttiProp.Name, FormatDateTime('c', oValue.AsExtended)); 230 | end; 231 | tkClass: 232 | begin 233 | if oValue.AsObject.ClassName.Contains('TSimpleEntityList<') 234 | or oValue.AsObject.ClassName.Contains('TObjectList<') 235 | or oValue.AsObject.ClassNameIs('TStringList') then 236 | begin 237 | sArrayTemp := ListToJSONArrayString(oValue.AsObject); 238 | oJson[oRttiProp.Name].AsArray.Parse(sArrayTemp); 239 | end 240 | else 241 | oJson[oRttiProp.Name].AsObject.Parse(ObjectToJSONString(oValue.AsObject)); 242 | end; 243 | end; 244 | end; 245 | Result := oJson.Stringify; 246 | finally 247 | FreeAndNil(oJson); 248 | end; 249 | end; 250 | 251 | class procedure TSimpleJsonUtil.JSONStringToObject(const psJSON: string; poObject: TObject); 252 | var 253 | oRttiContexto: TRttiContext; 254 | oRttiProp: TRttiProperty; 255 | oRttiTipo: TRttiType; 256 | oValue: TValue; 257 | oJson: TSimpleJson; 258 | I: Integer; 259 | sArrayTemp: string; 260 | begin 261 | sArrayTemp := ''; 262 | oJson := TSimpleJson.Create; 263 | try 264 | oJson.Parse(psJSON); 265 | oRttiTipo := oRttiContexto.GetType(poObject.ClassType); 266 | for oRttiProp in oRttiTipo.GetProperties do 267 | begin 268 | if oRttiProp.Name = 'RefCount' then 269 | Continue; 270 | 271 | oValue := oRttiProp.GetValue(poObject); 272 | case oValue.Kind of 273 | tkUString: 274 | oValue := oJson[oRttiProp.Name].AsString; 275 | tkInteger: 276 | oValue := oJson[oRttiProp.Name].AsInteger; 277 | tkFloat: 278 | begin 279 | if (oValue.TypeInfo = TypeInfo(Real)) or (oValue.TypeInfo = TypeInfo(Double)) then 280 | oValue := oJson[oRttiProp.Name].AsNumber; 281 | 282 | if oValue.TypeInfo = TypeInfo(TDate) then 283 | oValue := StrToDateDef(oJson[oRttiProp.Name].AsString, 0); 284 | 285 | if oValue.TypeInfo = TypeInfo(TTime) then 286 | oValue := StrToTimeDef(oJson[oRttiProp.Name].AsString, 0); 287 | 288 | if oValue.TypeInfo = TypeInfo(TDateTime) then 289 | oValue := StrToDateTimeDef(oJson[oRttiProp.Name].AsString, 0); 290 | end; 291 | tkClass: 292 | begin 293 | if not oValue.AsObject.ClassNameIs('TStringList') then 294 | Continue; 295 | 296 | for I := 0 to oJson[oRttiProp.Name].AsArray.Count - 1 do 297 | begin 298 | (oValue.AsObject as TStringList).Add(oJson[oRttiProp.Name].AsArray 299 | [I].Stringify); 300 | end; 301 | 302 | Continue; 303 | end; 304 | end; 305 | oRttiProp.SetValue(poObject, oValue); 306 | end; 307 | finally 308 | FreeAndNil(oJson); 309 | end; 310 | end; 311 | 312 | end. 313 | 314 | 315 | -------------------------------------------------------------------------------- /SimpleORM.dpk: -------------------------------------------------------------------------------- 1 | package SimpleORM; 2 | 3 | {$R *.res} 4 | {$IFDEF IMPLICITBUILDING This IFDEF should not be used by users} 5 | {$ALIGN 8} 6 | {$ASSERTIONS ON} 7 | {$BOOLEVAL OFF} 8 | {$DEBUGINFO OFF} 9 | {$EXTENDEDSYNTAX ON} 10 | {$IMPORTEDDATA ON} 11 | {$IOCHECKS ON} 12 | {$LOCALSYMBOLS ON} 13 | {$LONGSTRINGS ON} 14 | {$OPENSTRINGS ON} 15 | {$OPTIMIZATION OFF} 16 | {$OVERFLOWCHECKS OFF} 17 | {$RANGECHECKS OFF} 18 | {$REFERENCEINFO ON} 19 | {$SAFEDIVIDE OFF} 20 | {$STACKFRAMES ON} 21 | {$TYPEDADDRESS OFF} 22 | {$VARSTRINGCHECKS ON} 23 | {$WRITEABLECONST OFF} 24 | {$MINENUMSIZE 1} 25 | {$IMAGEBASE $400000} 26 | {$DEFINE DEBUG} 27 | {$ENDIF IMPLICITBUILDING} 28 | {$IMPLICITBUILD ON} 29 | 30 | requires 31 | rtl, 32 | vcl, 33 | soaprtl, 34 | dbrtl, 35 | inet, 36 | IndySystem, 37 | IndyProtocols, 38 | IndyCore, 39 | FireDAC, 40 | FireDACCommonDriver, 41 | FireDACCommon, 42 | RestDatawareCORE, 43 | DbxCommonDriver, 44 | bindengine, 45 | bindcomp, 46 | RESTComponents, 47 | dac260, 48 | unidac260; 49 | 50 | contains 51 | SimpleAttributes in 'SimpleAttributes.pas', 52 | SimpleDAO in 'SimpleDAO.pas', 53 | SimpleInterface in 'SimpleInterface.pas', 54 | SimpleQueryFiredac in 'SimpleQueryFiredac.pas', 55 | SimpleQueryRestDW in 'SimpleQueryRestDW.pas', 56 | SimpleRTTI in 'SimpleRTTI.pas', 57 | SimpleSQL in 'SimpleSQL.pas', 58 | SimpleDAOSQLAttribute in 'SimpleDAOSQLAttribute.pas', 59 | SimpleRTTIHelper in 'SimpleRTTIHelper.pas', 60 | SimpleValidator in 'SimpleValidator.pas', 61 | SimpleUtil in 'SimpleUtil.pas', 62 | SimpleEntity in 'SimpleEntity.pas', 63 | SimpleJSONUtil in 'SimpleJSONUtil.pas', 64 | SimpleJSON in 'SimpleJSON.pas', 65 | SimpleQueryUnidac in 'SimpleQueryUnidac.pas'; 66 | 67 | end. 68 | -------------------------------------------------------------------------------- /SimpleORM.dpr: -------------------------------------------------------------------------------- 1 | program SimpleORM; 2 | 3 | uses 4 | Vcl.Forms, 5 | SimpleDAO in 'SimpleDAO.pas', 6 | SimpleInterface in 'SimpleInterface.pas', 7 | SimpleAttributes in 'SimpleAttributes.pas', 8 | SimpleRTTI in 'SimpleRTTI.pas', 9 | SimpleSQL in 'SimpleSQL.pas', 10 | SimpleQueryFiredac in 'SimpleQueryFiredac.pas', 11 | SimpleQueryRestDW in 'SimpleQueryRestDW.pas'; 12 | 13 | {$R *.res} 14 | 15 | begin 16 | Application.Initialize; 17 | ReportMemoryLeaksOnShutdown := True; 18 | Application.MainFormOnTaskbar := True; 19 | Application.Run; 20 | end. 21 | -------------------------------------------------------------------------------- /SimpleORM.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/SimpleORM.res -------------------------------------------------------------------------------- /SimpleORM_Group.groupproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {AF438914-C65C-47AA-A894-FC952BEDF3B6} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Default.Personality.12 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /SimpleQueryFiredac.pas: -------------------------------------------------------------------------------- 1 | unit SimpleQueryFiredac; 2 | 3 | interface 4 | 5 | uses 6 | SimpleInterface, FireDAC.Comp.Client, System.Classes, Data.DB, 7 | FireDAC.Stan.Param, FireDAC.DatS, 8 | FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet; 9 | 10 | Type 11 | TSimpleQueryFiredac = class(TInterfacedObject, iSimpleQuery) 12 | private 13 | FConnection : TFDConnection; 14 | FQuery : TFDQuery; 15 | FParams : TParams; 16 | public 17 | constructor Create(aConnection : TFDConnection); 18 | destructor Destroy; override; 19 | class function New(aConnection : TFDConnection) : iSimpleQuery; 20 | function SQL : TStrings; 21 | function Params : TParams; 22 | function ExecSQL : iSimpleQuery; 23 | function DataSet : TDataSet; 24 | function Open(aSQL : String) : iSimpleQuery; overload; 25 | function Open : iSimpleQuery; overload; 26 | end; 27 | 28 | implementation 29 | 30 | uses 31 | System.SysUtils; 32 | 33 | { TSimpleQuery } 34 | 35 | constructor TSimpleQueryFiredac.Create(aConnection : TFDConnection); 36 | begin 37 | FQuery := TFDQuery.Create(nil); 38 | FConnection := aConnection; 39 | FQuery.Connection := FConnection; 40 | end; 41 | 42 | function TSimpleQueryFiredac.DataSet: TDataSet; 43 | begin 44 | Result := TDataSet(FQuery); 45 | end; 46 | 47 | destructor TSimpleQueryFiredac.Destroy; 48 | begin 49 | FreeAndNil(FQuery); 50 | if Assigned(FParams) then 51 | FreeAndNil(FParams); 52 | inherited; 53 | end; 54 | 55 | function TSimpleQueryFiredac.ExecSQL: iSimpleQuery; 56 | begin 57 | Result := Self; 58 | if Assigned(FParams) then 59 | FQuery.Params.Assign(FParams); 60 | 61 | FQuery.Prepare; 62 | FQuery.ExecSQL; 63 | 64 | if Assigned(FParams) then 65 | FreeAndNil(FParams); 66 | end; 67 | 68 | class function TSimpleQueryFiredac.New(aConnection : TFDConnection): iSimpleQuery; 69 | begin 70 | Result := Self.Create(aConnection); 71 | end; 72 | 73 | function TSimpleQueryFiredac.Open: iSimpleQuery; 74 | begin 75 | Result := Self; 76 | FQuery.Close; 77 | 78 | if Assigned(FParams) then 79 | FQuery.Params.Assign(FParams); 80 | 81 | FQuery.Prepare; 82 | FQuery.Open; 83 | 84 | if Assigned(FParams) then 85 | FreeAndNil(FParams); 86 | end; 87 | 88 | function TSimpleQueryFiredac.Open(aSQL: String): iSimpleQuery; 89 | begin 90 | Result := Self; 91 | FQuery.Close; 92 | FQuery.Open(aSQL); 93 | end; 94 | 95 | function TSimpleQueryFiredac.Params: TParams; 96 | begin 97 | if not Assigned(FParams) then 98 | begin 99 | FParams := TParams.Create(nil); 100 | FParams.Assign(FQuery.Params); 101 | end; 102 | Result := FParams; 103 | end; 104 | 105 | function TSimpleQueryFiredac.SQL: TStrings; 106 | begin 107 | Result := FQuery.SQL; 108 | end; 109 | 110 | end. 111 | -------------------------------------------------------------------------------- /SimpleQueryRestDW.pas: -------------------------------------------------------------------------------- 1 | unit SimpleQueryRestDW; 2 | 3 | interface 4 | 5 | uses 6 | SimpleInterface, System.Classes, Data.DB, uDWConstsData, uRESTDWPoolerDB; 7 | 8 | Type 9 | TSimpleQueryRestDW = class(TInterfacedObject, iSimpleQuery) 10 | private 11 | FConnection : TRESTDWDataBase; 12 | FQuery : TRESTDWClientSQL; 13 | public 14 | constructor Create(aConnection : TRESTDWDataBase); 15 | destructor Destroy; override; 16 | class function New(aConnection : TRESTDWDataBase) : iSimpleQuery; 17 | function SQL : TStrings; 18 | function Params : TParams; 19 | function ExecSQL : iSimpleQuery; 20 | function DataSet : TDataSet; 21 | function Open(aSQL : String) : iSimpleQuery; overload; 22 | function Open : iSimpleQuery; overload; 23 | end; 24 | 25 | implementation 26 | 27 | uses 28 | System.SysUtils, SimpleRTTI; 29 | 30 | { TSimpleQuery } 31 | 32 | constructor TSimpleQueryRestDW.Create(aConnection : TRESTDWDataBase); 33 | var 34 | aTable : String; 35 | begin 36 | FConnection := aConnection; 37 | FQuery := TRESTDWClientSQL.Create(nil); 38 | FQuery.DataBase := FConnection; 39 | TSimpleRTTI.New(nil).ClassName(aTable); 40 | FQuery.AutoCommitData := False; 41 | FQuery.AutoRefreshAfterCommit := True; 42 | //FQuery.SetInBlockEvents(false); 43 | FQuery.UpdateTableName := aTable; 44 | end; 45 | 46 | function TSimpleQueryRestDW.DataSet: TDataSet; 47 | begin 48 | Result := FQuery; 49 | end; 50 | 51 | destructor TSimpleQueryRestDW.Destroy; 52 | begin 53 | FreeAndNil(FQuery); 54 | inherited; 55 | end; 56 | 57 | function TSimpleQueryRestDW.ExecSQL: iSimpleQuery; 58 | var 59 | aErro : String; 60 | begin 61 | Result := Self; 62 | FQuery.ExecSQL(aErro); 63 | FQuery.ApplyUpdates(aErro); 64 | end; 65 | 66 | class function TSimpleQueryRestDW.New(aConnection : TRESTDWDataBase): iSimpleQuery; 67 | begin 68 | Result := Self.Create(aConnection); 69 | end; 70 | 71 | function TSimpleQueryRestDW.Open: iSimpleQuery; 72 | begin 73 | Result := Self; 74 | FQuery.Close; 75 | FQuery.Open; 76 | end; 77 | 78 | function TSimpleQueryRestDW.Open(aSQL: String): iSimpleQuery; 79 | begin 80 | FQuery.Close; 81 | Result := Self; 82 | FQuery.Open(aSQL); 83 | end; 84 | 85 | function TSimpleQueryRestDW.Params: TParams; 86 | begin 87 | Result := FQuery.Params; 88 | end; 89 | 90 | function TSimpleQueryRestDW.SQL: TStrings; 91 | begin 92 | Result := FQuery.SQL; 93 | end; 94 | 95 | end. 96 | -------------------------------------------------------------------------------- /SimpleQueryUnidac.pas: -------------------------------------------------------------------------------- 1 | unit SimpleQueryUnidac; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, 7 | Data.DB, 8 | Uni, 9 | SimpleInterface; 10 | 11 | type 12 | TSimpleQueryUniDac = class(TInterfacedObject, iSimpleQuery) 13 | private 14 | FConnection : TUniConnection; 15 | FQuery : TUniQuery; 16 | FParams : TParams; 17 | public 18 | constructor Create(aConnection : TUniConnection); 19 | destructor Destroy; override; 20 | class function New(aConnection : TUniConnection) : iSimpleQuery; 21 | 22 | function SQL : TStrings; 23 | function Params : TParams; 24 | function ExecSQL : iSimpleQuery; 25 | function DataSet : TDataSet; 26 | function Open(aSQL : String) : iSimpleQuery; overload; 27 | function Open : iSimpleQuery; overload; 28 | end; 29 | 30 | implementation 31 | 32 | uses 33 | System.SysUtils; 34 | 35 | { TSimpleQueryUniDac } 36 | 37 | constructor TSimpleQueryUniDac.Create(aConnection: TUniConnection); 38 | begin 39 | FQuery := TUniQuery.Create(nil); 40 | FConnection := aConnection; 41 | FQuery.Connection := FConnection; 42 | end; 43 | 44 | function TSimpleQueryUniDac.DataSet: TDataSet; 45 | begin 46 | Result := TDataSet(FQuery); 47 | end; 48 | 49 | destructor TSimpleQueryUniDac.Destroy; 50 | begin 51 | FreeAndNil(FQuery); 52 | if Assigned(FParams) then 53 | FreeAndNil(FParams); 54 | inherited; 55 | end; 56 | 57 | function TSimpleQueryUniDac.ExecSQL: iSimpleQuery; 58 | begin 59 | Result := Self; 60 | if Assigned(FParams) then 61 | FQuery.Params.Assign(FParams); 62 | 63 | FQuery.Prepare; 64 | FQuery.ExecSQL; 65 | 66 | if Assigned(FParams) then 67 | FreeAndNil(FParams); 68 | end; 69 | 70 | class function TSimpleQueryUniDac.New(aConnection: TUniConnection): iSimpleQuery; 71 | begin 72 | Result := Self.Create(aConnection); 73 | end; 74 | 75 | function TSimpleQueryUniDac.Open(aSQL: String): iSimpleQuery; 76 | begin 77 | Result := Self; 78 | FQuery.Close; 79 | FQuery.SQL.Text := aSQL; 80 | FQuery.Open; 81 | end; 82 | 83 | function TSimpleQueryUniDac.Open: iSimpleQuery; 84 | begin 85 | Result := Self; 86 | FQuery.Close; 87 | 88 | if Assigned(FParams) then 89 | FQuery.Params.Assign(FParams); 90 | 91 | FQuery.Prepare; 92 | FQuery.Open; 93 | 94 | if Assigned(FParams) then 95 | FreeAndNil(FParams); 96 | end; 97 | 98 | function TSimpleQueryUniDac.Params: TParams; 99 | begin 100 | if not Assigned(FParams) then 101 | begin 102 | FParams := TParams.Create(nil); 103 | FParams.Assign(FQuery.Params); 104 | end; 105 | Result := FParams; 106 | end; 107 | 108 | function TSimpleQueryUniDac.SQL: TStrings; 109 | begin 110 | Result := FQuery.SQL; 111 | end; 112 | 113 | end. 114 | -------------------------------------------------------------------------------- /SimpleQueryZeos.pas: -------------------------------------------------------------------------------- 1 | Unit SimpleQueryZeos; 2 | 3 | interface 4 | 5 | uses 6 | SimpleInterface, ZAbstractConnection, ZConnection, 7 | ZAbstractRODataset, ZAbstractDataset, ZAbstractTable, ZDataset, System.Classes, Data.DB; 8 | 9 | Type 10 | TSimpleQueryZeos = class(TInterfacedObject, iSimpleQuery) 11 | private 12 | FConnection : TZConnection; 13 | FQuery : TZQuery; 14 | FParams : TParams; 15 | public 16 | constructor Create(aConnection : TZConnection); 17 | destructor Destroy; override; 18 | class function New(aConnection : TZConnection) : iSimpleQuery; 19 | function SQL : TStrings; 20 | function Params : TParams; 21 | function ExecSQL : iSimpleQuery; 22 | function DataSet : TDataSet; 23 | function Open(aSQL : String) : iSimpleQuery; overload; 24 | function Open : iSimpleQuery; overload; 25 | end; 26 | 27 | implementation 28 | 29 | uses 30 | System.SysUtils; 31 | 32 | { TSimpleQuery } 33 | 34 | constructor TSimpleQueryZeos.Create(aConnection : TZConnection); 35 | begin 36 | FQuery := TZQuery.Create(nil); 37 | FConnection := aConnection; 38 | FQuery.Connection := FConnection; 39 | end; 40 | 41 | function TSimpleQueryZeos.DataSet: TDataSet; 42 | begin 43 | Result := TDataSet(FQuery); 44 | end; 45 | 46 | destructor TSimpleQueryZeos.Destroy; 47 | begin 48 | FreeAndNil(FQuery); 49 | if Assigned(FParams) then 50 | FreeAndNil(FParams); 51 | inherited; 52 | end; 53 | 54 | function TSimpleQueryZeos.ExecSQL: iSimpleQuery; 55 | var 56 | a: string; 57 | begin 58 | Result := Self; 59 | FQuery.Params.Assign(FParams); 60 | FQuery.Prepare; 61 | FQuery.ExecSQL; 62 | 63 | if Assigned(FParams) then 64 | FreeAndNil(FParams); 65 | end; 66 | 67 | class function TSimpleQueryZeos.New(aConnection : TZConnection): iSimpleQuery; 68 | begin 69 | Result := Self.Create(aConnection); 70 | end; 71 | 72 | function TSimpleQueryZeos.Open: iSimpleQuery; 73 | begin 74 | Result := Self; 75 | FQuery.Close; 76 | 77 | if Assigned(FParams) then 78 | FQuery.Params.Assign(FParams); 79 | 80 | FQuery.Prepare; 81 | FQuery.Open; 82 | 83 | if Assigned(FParams) then 84 | FreeAndNil(FParams); 85 | end; 86 | 87 | function TSimpleQueryZeos.Open(aSQL: String): iSimpleQuery; 88 | begin 89 | Result := Self; 90 | FQuery.Close; 91 | FQuery.SQL.Clear; 92 | FQuery.SQL.Add(aSQL); 93 | FQuery.Open; 94 | end; 95 | 96 | function TSimpleQueryZeos.Params: TParams; 97 | begin 98 | if not Assigned(FParams) then 99 | begin 100 | FParams := TParams.Create(nil); 101 | FParams.Assign(FQuery.Params); 102 | end; 103 | Result := FParams; 104 | end; 105 | 106 | function TSimpleQueryZeos.SQL: TStrings; 107 | begin 108 | Result := FQuery.SQL; 109 | end; 110 | 111 | end. 112 | -------------------------------------------------------------------------------- /SimpleRTTIHelper.pas: -------------------------------------------------------------------------------- 1 | unit SimpleRTTIHelper; 2 | 3 | interface 4 | 5 | uses 6 | RTTI, SimpleAttributes; 7 | 8 | type 9 | TCustomAttributeClass = class of TCustomAttribute; 10 | 11 | TRttiPropertyHelper = class helper for TRttiProperty 12 | public 13 | function Tem: Boolean; 14 | function GetAttribute: T; 15 | function IsNotNull: Boolean; 16 | function IsIgnore: Boolean; 17 | function IsEnum: Boolean; 18 | function IsAutoInc: Boolean; 19 | function EhCampo: Boolean; 20 | function EhChavePrimaria: Boolean; 21 | function EhChaveEstrangeira: Boolean; 22 | function EhSomenteNumeros: Boolean; 23 | function EhPermitidoNulo: Boolean; 24 | function DisplayName: string; 25 | function FieldName: string; 26 | function EnumName: string; 27 | end; 28 | 29 | TRttiTypeHelper = class helper for TRttiType 30 | public 31 | function Tem: Boolean; 32 | function GetAttribute: T; 33 | function GetPropertyFromAttribute 34 | : TRttiProperty; overload; 35 | function GetPropertyFromAttribute(const aFieldName: string) 36 | : TRttiProperty; overload; 37 | function GetPKField: TRttiProperty; 38 | function IsTabela: Boolean; 39 | end; 40 | 41 | TRttiFieldHelper = class helper for TRttiField 42 | public 43 | function Tem: Boolean; 44 | function GetAttribute: T; 45 | end; 46 | 47 | TValueHelper = record helper for TValue 48 | public 49 | function AsStringNumberOnly: String; 50 | end; 51 | 52 | implementation 53 | 54 | uses 55 | System.SysUtils; 56 | 57 | { TRttiPropertyMelhorado } 58 | 59 | function TRttiPropertyHelper.GetAttribute: T; 60 | var 61 | oAtributo: TCustomAttribute; 62 | begin 63 | Result := nil; 64 | for oAtributo in GetAttributes do 65 | if oAtributo is T then 66 | Exit((oAtributo as T)); 67 | end; 68 | 69 | function TRttiPropertyHelper.DisplayName: string; 70 | begin 71 | Result := Name; 72 | 73 | if Tem then 74 | Result := GetAttribute.Name 75 | end; 76 | 77 | function TRttiPropertyHelper.EhCampo: Boolean; 78 | begin 79 | Result := Tem 80 | end; 81 | 82 | function TRttiPropertyHelper.EhChaveEstrangeira: Boolean; 83 | begin 84 | Result := Tem 85 | end; 86 | 87 | function TRttiPropertyHelper.EhChavePrimaria: Boolean; 88 | begin 89 | Result := Tem 90 | end; 91 | 92 | function TRttiPropertyHelper.IsNotNull: Boolean; 93 | begin 94 | Result := Tem 95 | end; 96 | 97 | function TRttiPropertyHelper.IsIgnore: Boolean; 98 | begin 99 | Result := Tem 100 | end; 101 | 102 | function TRttiPropertyHelper.IsEnum: Boolean; 103 | begin 104 | Result := Tem 105 | end; 106 | 107 | function TRttiPropertyHelper.IsAutoInc: Boolean; 108 | begin 109 | Result := Tem 110 | end; 111 | 112 | function TRttiPropertyHelper.EhPermitidoNulo: Boolean; 113 | begin 114 | Result := not IsNotNull; 115 | end; 116 | 117 | function TRttiPropertyHelper.EhSomenteNumeros: Boolean; 118 | begin 119 | Result := Tem 120 | end; 121 | 122 | function TRttiPropertyHelper.FieldName: string; 123 | begin 124 | Result := Name; 125 | if EhCampo then 126 | Result := GetAttribute.Name; 127 | end; 128 | 129 | function TRttiPropertyHelper.EnumName: string; 130 | begin 131 | Result := Name; 132 | if IsEnum then 133 | Result := GetAttribute.Tipo; 134 | end; 135 | function TRttiPropertyHelper.Tem: Boolean; 136 | begin 137 | Result := GetAttribute <> nil 138 | end; 139 | 140 | { TRttiTypeMelhorado } 141 | 142 | function TRttiTypeHelper.GetAttribute: T; 143 | var 144 | oAtributo: TCustomAttribute; 145 | begin 146 | Result := nil; 147 | for oAtributo in GetAttributes do 148 | if oAtributo is T then 149 | Exit((oAtributo as T)); 150 | end; 151 | 152 | function TRttiTypeHelper.GetPKField: TRttiProperty; 153 | begin 154 | Result := GetPropertyFromAttribute; 155 | end; 156 | 157 | function TRttiTypeHelper.GetPropertyFromAttribute( 158 | const aFieldName: string): TRttiProperty; 159 | var 160 | RttiProp: TRttiProperty; 161 | begin 162 | Result := nil; 163 | for RttiProp in GetProperties do 164 | begin 165 | if RttiProp.GetAttribute = nil then 166 | Continue; 167 | 168 | if RttiProp.GetAttribute.Name = aFieldName then 169 | Exit(RttiProp); 170 | end; 171 | end; 172 | 173 | function TRttiTypeHelper.GetPropertyFromAttribute: TRttiProperty; 174 | var 175 | RttiProp: TRttiProperty; 176 | begin 177 | Result := nil; 178 | for RttiProp in GetProperties do 179 | if RttiProp.GetAttribute <> nil then 180 | Exit(RttiProp); 181 | end; 182 | 183 | function TRttiTypeHelper.isTabela: Boolean; 184 | begin 185 | Result := Tem 186 | end; 187 | 188 | function TRttiTypeHelper.Tem: Boolean; 189 | begin 190 | Result := GetAttribute <> nil 191 | end; 192 | 193 | { TRttiFieldHelper } 194 | 195 | function TRttiFieldHelper.GetAttribute: T; 196 | var 197 | oAtributo: TCustomAttribute; 198 | begin 199 | Result := nil; 200 | for oAtributo in GetAttributes do 201 | if oAtributo is T then 202 | Exit((oAtributo as T)); 203 | end; 204 | 205 | function TRttiFieldHelper.Tem: Boolean; 206 | begin 207 | Result := GetAttribute <> nil 208 | end; 209 | 210 | { TValueHelper.NumberOnly } 211 | 212 | function TValueHelper.AsStringNumberOnly: String; 213 | var 214 | sContent: string; 215 | nIndex: Integer; 216 | begin 217 | Result := ''; 218 | sContent := Trim(AsString); 219 | 220 | for nIndex := 1 to Length(sContent) do 221 | if CharInSet(sContent[nIndex], ['0'..'9']) then 222 | Result := Result + sContent[nIndex]; 223 | end; 224 | 225 | end. 226 | 227 | -------------------------------------------------------------------------------- /SimpleSQL.pas: -------------------------------------------------------------------------------- 1 | unit SimpleSQL; 2 | interface 3 | uses 4 | SimpleInterface; 5 | Type 6 | TSimpleSQL = class(TInterfacedObject, iSimpleSQL) 7 | private 8 | FInstance : T; 9 | FFields : String; 10 | FWhere : String; 11 | FOrderBy : String; 12 | FGroupBy : String; 13 | FJoin : String; 14 | public 15 | constructor Create(aInstance : T); 16 | destructor Destroy; override; 17 | class function New(aInstance : T) : iSimpleSQL; 18 | function Insert (var aSQL : String) : iSimpleSQL; 19 | function Update (var aSQL : String) : iSimpleSQL; 20 | function Delete (var aSQL : String) : iSimpleSQL; 21 | function Select (var aSQL : String) : iSimpleSQL; 22 | function SelectId(var aSQL: String): iSimpleSQL; 23 | function Fields (aSQL : String) : iSimpleSQL; 24 | function Where (aSQL : String) : iSimpleSQL; 25 | function OrderBy (aSQL : String) : iSimpleSQL; 26 | function GroupBy (aSQL : String) : iSimpleSQL; 27 | function Join (aSQL : String) : iSimpleSQL; 28 | function LastID (var aSQL : String) : iSimpleSQL; 29 | function LastRecord (var aSQL : String) : iSimpleSQL; 30 | end; 31 | implementation 32 | 33 | uses 34 | SimpleRTTI, System.Generics.Collections, System.SysUtils; 35 | { TSimpleSQL } 36 | 37 | constructor TSimpleSQL.Create(aInstance : T); 38 | begin 39 | FInstance := aInstance; 40 | end; 41 | 42 | function TSimpleSQL.Delete(var aSQL: String): iSimpleSQL; 43 | var 44 | aClassName, aWhere : String; 45 | begin 46 | Result := Self; 47 | TSimpleRTTI.New(FInstance) 48 | .TableName(aClassName) 49 | .Where(aWhere); 50 | aSQL := aSQL + 'DELETE FROM ' + aClassName; 51 | aSQL := aSQL + ' WHERE ' + aWhere; 52 | end; 53 | 54 | destructor TSimpleSQL.Destroy; 55 | begin 56 | inherited; 57 | end; 58 | 59 | function TSimpleSQL.Fields(aSQL: String): iSimpleSQL; 60 | begin 61 | Result := Self; 62 | if Trim(aSQL) <> '' then 63 | FFields := aSQL; 64 | end; 65 | 66 | function TSimpleSQL.GroupBy(aSQL: String): iSimpleSQL; 67 | begin 68 | Result := Self; 69 | if Trim(aSQL) <> '' then 70 | FGroupBy := aSQL; 71 | end; 72 | 73 | function TSimpleSQL.Insert(var aSQL: String): iSimpleSQL; 74 | var 75 | aClassName, aFields, aParam : String; 76 | begin 77 | Result := Self; 78 | TSimpleRTTI.New(FInstance) 79 | .TableName(aClassName) 80 | .FieldsInsert(aFields) 81 | .Param(aParam); 82 | aSQL := aSQL + 'INSERT INTO ' + aClassName; 83 | aSQL := aSQL + ' (' + aFields + ') '; 84 | aSQL := aSQL + ' VALUES (' + aParam + ');'; 85 | end; 86 | 87 | function TSimpleSQL.Join(aSQL: String): iSimpleSQL; 88 | begin 89 | Result := Self; 90 | FJoin := aSQL; 91 | end; 92 | 93 | function TSimpleSQL.LastID(var aSQL: String): iSimpleSQL; 94 | var 95 | aClassName, aPK: String; 96 | begin 97 | Result := Self; 98 | TSimpleRTTI.New(FInstance) 99 | .TableName(aClassName) 100 | .PrimaryKey(aPK); 101 | aSQL := aSQL + 'select first(1) ' + aPK; 102 | aSQL := aSQL + ' from '+ aClassName; 103 | aSQL := aSQL + ' order by ' + aPK + ' desc'; 104 | end; 105 | 106 | function TSimpleSQL.LastRecord(var aSQL: String): iSimpleSQL; 107 | var 108 | aClassName, aPK, aFields : String; 109 | begin 110 | Result := Self; 111 | TSimpleRTTI.New(FInstance) 112 | .TableName(aClassName) 113 | .Fields(aFields) 114 | .PrimaryKey(aPK); 115 | aSQL := aSQL + 'select first(1) '+aFields; 116 | aSQL := aSQL + ' from '+ aClassName; 117 | aSQL := aSQL + ' order by ' + aPK + ' desc'; 118 | end; 119 | 120 | class function TSimpleSQL.New(aInstance : T): iSimpleSQL; 121 | begin 122 | Result := Self.Create(aInstance); 123 | end; 124 | 125 | function TSimpleSQL.OrderBy(aSQL: String): iSimpleSQL; 126 | begin 127 | Result := Self; 128 | FOrderBy := aSQL; 129 | end; 130 | 131 | function TSimpleSQL.Select (var aSQL : String) : iSimpleSQL; 132 | var 133 | aFields, aClassName : String; 134 | begin 135 | Result := Self; 136 | TSimpleRTTI.New(nil) 137 | .Fields(aFields) 138 | .TableName(aClassName); 139 | if Trim(FFields) <> '' then 140 | aSQL := aSQL + ' SELECT ' + FFields 141 | else 142 | aSQL := aSQL + ' SELECT ' + aFields; 143 | aSQL := aSQL + ' FROM ' + aClassName; 144 | if Trim(FJoin) <> '' then 145 | aSQL := aSQL + ' ' + FJoin + ' '; 146 | if Trim(FWhere) <> '' then 147 | aSQL := aSQL + ' WHERE ' + FWhere; 148 | if Trim(FGroupBy) <> '' then 149 | aSQL := aSQL + ' GROUP BY ' + FGroupBy; 150 | if Trim(FOrderBy) <> '' then 151 | aSQL := aSQL + ' ORDER BY ' + FOrderBy; 152 | end; 153 | 154 | function TSimpleSQL.SelectId(var aSQL: String): iSimpleSQL; 155 | var 156 | aFields, aClassName, aWhere : String; 157 | begin 158 | Result := Self; 159 | TSimpleRTTI.New(FInstance) 160 | .Fields(aFields) 161 | .TableName(aClassName) 162 | .Where(aWhere); 163 | if Trim(FWhere) <> '' then 164 | aSQL := aSQL + ' WHERE ' + FWhere; 165 | 166 | aSQL := aSQL + ' SELECT ' + aFields; 167 | aSQL := aSQL + ' FROM ' + aClassName; 168 | aSQL := aSQL + ' WHERE ' + aWhere; 169 | end; 170 | 171 | function TSimpleSQL.Update(var aSQL: String): iSimpleSQL; 172 | var 173 | ClassName, aUpdate, aWhere : String; 174 | begin 175 | Result := Self; 176 | TSimpleRTTI.New(FInstance) 177 | .TableName(ClassName) 178 | .Update(aUpdate) 179 | .Where(aWhere); 180 | 181 | aSQL := aSQL + 'UPDATE ' + ClassName; 182 | aSQL := aSQL + ' SET ' + aUpdate; 183 | aSQL := aSQL + ' WHERE ' + aWhere; 184 | end; 185 | 186 | function TSimpleSQL.Where(aSQL: String): iSimpleSQL; 187 | begin 188 | Result := Self; 189 | FWhere := aSQL; 190 | end; 191 | 192 | end. 193 | -------------------------------------------------------------------------------- /SimpleTypes.pas: -------------------------------------------------------------------------------- 1 | unit SimpleTypes; 2 | 3 | interface 4 | 5 | type 6 | TSQLType = (Firebird, MySQL, SQLite, Oracle); 7 | 8 | implementation 9 | 10 | end. 11 | -------------------------------------------------------------------------------- /SimpleUtil.pas: -------------------------------------------------------------------------------- 1 | unit SimpleUtil; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, Data.DB, System.Generics.Collections, 7 | {$IFNDEF CONSOLE} 8 | {$IFDEF FMX} 9 | FMX.Forms, FMX.StdCtrls, FMX.DateTimeCtrls, 10 | {$ELSE} 11 | Vcl.Forms, Vcl.StdCtrls, Vcl.ComCtrls, 12 | {$ENDIF} 13 | {$ENDIF} 14 | SimpleEntity; 15 | 16 | type 17 | TSimpleUtil = class 18 | private 19 | {$IFNDEF CONSOLE} 20 | class function GetTextFromComponent(aComponent: TComponent): string; 21 | {$ENDIF} 22 | public 23 | class procedure DataSetToObjectList(const poDataSet: 24 | TDataSet; const poLista: TObjectList); overload; 25 | class procedure DataSetToObjectList(const poDataSet: 26 | TDataSet; const poLista: TSimpleEntityList); overload; 27 | class procedure GetValuesFromDataset(const poDataset: TDataSet; const poClasse: TObject); 28 | {$IFNDEF CONSOLE} 29 | class procedure GetObjectFromForm(const aForm: TForm; const aObject: TObject); 30 | class procedure SetFormFromObject(const aForm: TForm; const aObject: TObject); 31 | {$ENDIF} 32 | end; 33 | 34 | implementation 35 | 36 | { TcdRTTIUtils } 37 | 38 | uses 39 | System.Rtti, SysUtils, FireDAC.Comp.Client, SimpleRTTIHelper, SimpleAttributes; 40 | 41 | class procedure TSimpleUtil.DataSetToObjectList(const poDataSet: TDataSet; const 42 | poLista: TObjectList); 43 | var 44 | oObjeto: T; 45 | begin 46 | poDataSet.DisableControls; 47 | poDataSet.First; 48 | while not poDataSet.Eof do 49 | begin 50 | oObjeto := T.Create; 51 | GetValuesFromDataset(poDataSet, oObjeto); 52 | poLista.Add(oObjeto); 53 | poDataSet.Next; 54 | end; 55 | poDataSet.EnableControls; 56 | end; 57 | 58 | class procedure TSimpleUtil.DataSetToObjectList(const poDataSet: TDataSet; 59 | const poLista: TSimpleEntityList); 60 | var 61 | oObjeto: T; 62 | begin 63 | poDataSet.DisableControls; 64 | poDataSet.First; 65 | while not poDataSet.Eof do 66 | begin 67 | oObjeto := T.Create; 68 | oObjeto.Parse(poDataSet); 69 | poLista.Add(oObjeto); 70 | poDataSet.Next; 71 | end; 72 | poDataSet.EnableControls; 73 | end; 74 | 75 | class procedure TSimpleUtil.GetValuesFromDataset(const poDataset: TDataSet; 76 | const poClasse: TObject); 77 | var 78 | oContexto: TRttiContext; 79 | oTipo: TRttiType; 80 | oPropriedade: TRttiProperty; 81 | Value: TValue; 82 | 83 | function Campo: TField; 84 | begin 85 | Result := poDataset.FindField(oPropriedade.FieldName); 86 | end; 87 | 88 | begin 89 | oTipo := oContexto.GetType(poClasse.classType); 90 | for oPropriedade in oTipo.GetProperties do 91 | begin 92 | Value := oPropriedade.GetValue(poClasse); 93 | if (Campo = nil) then 94 | Continue; 95 | 96 | case Value.Kind of 97 | tkString, tkWChar, tkLString, tkWString, tkVariant, tkUString: 98 | Value := Campo.AsString; 99 | tkInteger: 100 | Value := StrToIntDef(Campo.AsString, 0); 101 | tkInt64: 102 | Value := StrToInt64Def(Campo.AsString, 0); 103 | tkFloat: 104 | begin 105 | if Value.TypeInfo = TypeInfo(TDate) then 106 | Value := Campo.AsDateTime 107 | else 108 | Value := Campo.AsExtended; 109 | end; 110 | tkClass: 111 | if oPropriedade.Tem then 112 | begin 113 | if Value.AsObject is TSimpleEntity then 114 | TSimpleEntity(Value.AsObject).Parse(poDataSet) 115 | else 116 | GetValuesFromDataset(poDataSet, Value.AsObject); 117 | end; 118 | end; 119 | 120 | if (Campo <> nil) then 121 | oPropriedade.SetValue(poClasse, Value); 122 | end; 123 | end; 124 | 125 | {$IFNDEF CONSOLE} 126 | 127 | class procedure TSimpleUtil.GetObjectFromForm(const aForm: TForm; 128 | const aObject: TObject); 129 | var 130 | ctxRttiEntity: TRttiContext; 131 | typRttiEntity: TRttiType; 132 | typRttiForm: TRttiType; 133 | fldRtti: TRttiField; 134 | prpRtti: TRttiProperty; 135 | Value: TValue; 136 | Component: TComponent; 137 | vFieldName: string; 138 | begin 139 | ctxRttiEntity := TRttiContext.Create; 140 | typRttiEntity := ctxRttiEntity.GetType(aObject.ClassType); 141 | typRttiForm := ctxRttiEntity.GetType(aForm.ClassInfo); 142 | 143 | for prpRtti in typRttiEntity.GetProperties do 144 | begin 145 | for fldRtti in typRttiForm.GetFields do 146 | begin 147 | if not fldRtti.Tem then 148 | Continue; 149 | 150 | vFieldName := LowerCase(fldRtti.GetAttribute.Field); 151 | if not (vFieldName.Equals(LowerCase(prpRtti.FieldName)) 152 | or vFieldName.Equals(LowerCase(prpRtti.Name))) then 153 | Continue; 154 | 155 | Component := (fldRtti.GetValue(aForm).AsObject as TComponent); 156 | case prpRtti.GetValue(aObject).Kind of 157 | tkString, tkWChar, tkLString, tkWString, tkVariant, tkUString: 158 | Value := GetTextFromComponent(Component); 159 | tkInteger: 160 | Value := StrToInt(GetTextFromComponent(Component)); 161 | tkFloat: 162 | Value := StrToFloat(GetTextFromComponent(Component)); 163 | end; 164 | 165 | prpRtti.SetValue(aObject, Value); 166 | end; 167 | end; 168 | end; 169 | 170 | class function TSimpleUtil.GetTextFromComponent(aComponent: TComponent): string; 171 | begin 172 | if aComponent is TEdit then 173 | begin 174 | if (aComponent as TEdit).NumbersOnly and ((aComponent as TEdit).Text = '') then 175 | Exit('0') 176 | else 177 | Exit((aComponent as TEdit).Text); 178 | end; 179 | 180 | if aComponent is TComboBox then 181 | Exit((aComponent as TComboBox).Text); 182 | 183 | if aComponent is TDateTimePicker then 184 | Exit(FloatToStr((aComponent as TDateTimePicker).Date)); 185 | end; 186 | 187 | class procedure TSimpleUtil.SetFormFromObject(const aForm: TForm; 188 | const aObject: TObject); 189 | var 190 | ctxRttiEntity: TRttiContext; 191 | typRttiEntity: TRttiType; 192 | typRttiForm: TRttiType; 193 | fldRtti: TRttiField; 194 | prpRtti: TRttiProperty; 195 | Component: TComponent; 196 | vFieldName, vFieldNameForm: string; 197 | begin 198 | ctxRttiEntity := TRttiContext.Create; 199 | typRttiEntity := ctxRttiEntity.GetType(aObject.ClassType); 200 | typRttiForm := ctxRttiEntity.GetType(aForm.ClassInfo); 201 | 202 | for prpRtti in typRttiEntity.GetProperties do 203 | begin 204 | vFieldName := prpRtti.Name; 205 | if prpRtti.EhCampo then 206 | vFieldName := prpRtti.GetAttribute.Name; 207 | for fldRtti in typRttiForm.GetFields do 208 | begin 209 | if not fldRtti.Tem then 210 | Continue; 211 | 212 | vFieldNameForm := fldRtti.GetAttribute.Field; 213 | if not vFieldNameForm.Equals(vFieldName) then 214 | Continue; 215 | 216 | Component := (fldRtti.GetValue(aForm).AsObject as TComponent); 217 | 218 | if Component is TEdit then 219 | (Component as TEdit).Text := prpRtti.GetValue(aObject).ToString; 220 | 221 | if Component is TComboBox then 222 | (Component as TComboBox).Text := prpRtti.GetValue(aObject).ToString; 223 | 224 | if Component is TDateTimePicker then 225 | (Component as TDateTimePicker).Date := prpRtti.GetValue(aObject) 226 | .AsExtended; 227 | end; 228 | end; 229 | end; 230 | 231 | {$ENDIF} 232 | 233 | end. 234 | 235 | -------------------------------------------------------------------------------- /SimpleValidator.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/SimpleValidator.pas -------------------------------------------------------------------------------- /assets/logo.fw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/assets/logo.fw.png -------------------------------------------------------------------------------- /assets/logo2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/assets/logo2.jpg -------------------------------------------------------------------------------- /assets/logo_2.fw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/assets/logo_2.fw.png -------------------------------------------------------------------------------- /boss.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "SimpleORM", 3 | "description": "", 4 | "version": "1.0.0", 5 | "homepage": "", 6 | "mainsrc": "./", 7 | "projects": [], 8 | "dependencies": {} 9 | } -------------------------------------------------------------------------------- /public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/academiadocodigo/SimpleORM/a2c75517d4d0107332984f40bc3a48a51ad502af/public/logo.png --------------------------------------------------------------------------------