mormot概述
- ORM/ODM :几乎所有数据库(SQL或Nosql)上的对象持久性;
- SOA 把你的商业逻辑组织成rest服务;
- 客户 :通过ORM类或SOA接口,从任何平台上使用您的数据或服务;
- 网络MVC :发布您的ORM/SOA流程作为响应网络应用程序。
mormot总设计:
mormot c/s orm/soa 框架:
mormot架构图:
mormot model驱动设计:
unit Unit1; /// <author>cxg 202371</author> interface uses mormot2.json.serial, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Vcl.StdCtrls, Vcl.Grids, Vcl.DBGrids, MemDS, DBAccess, Uni, UniProvider, SQLServerUniProvider, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Comp.DataSet, FireDAC.Comp.Client; type Tdw = record //定义model 一般用结构体或类定义model unitid: string; unitname: string; end; Tdws = record dw: TArray<Tdw>; end; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; DBGrid1: TDBGrid; Memo1: TMemo; UniConnection1: TUniConnection; UniQuery1: TUniQuery; SQLServerUniProvider1: TSQLServerUniProvider; DataSource1: TDataSource; FDMemTable1: TFDMemTable; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); //序列 begin //数据层的查询 UniQuery1.Close; UniQuery1.SQL.Clear; UniQuery1.SQL.Text := 'select * from tunit'; UniQuery1.Open; //dataset-->model var dws: Tdws; SetLength(dws.dw, UniQuery1.RecordCount); var i: Integer := 0; UniQuery1.First; while not UniQuery1.Eof do begin dws.dw[i].unitid := UniQuery1.FieldByName('unitid').AsString; dws.dw[i].unitname := UniQuery1.FieldByName('unitname').AsString; UniQuery1.Next; Inc(i); end; //序列model-->json var serial: TSerial; Memo1.Text := serial.marshal<Tdws>(dws); end; procedure TForm1.Button2Click(Sender: TObject); //还原 begin //还原json-->model var serial: TSerial; var dws: Tdws := serial.unmarshal<Tdws>(Memo1.Text); //model添加进内存表 FDMemTable1.DisableControls; FDMemTable1.EmptyDataSet; for var i: Integer := 0 to High(dws.dw) do FDMemTable1.InsertRecord([dws.dw[i].unitid, dws.dw[i].unitname]); FDMemTable1.EnableControls; end; procedure TForm1.FormCreate(Sender: TObject); begin //建内存表 FDMemTable1.FieldDefs.Clear; FDMemTable1.FieldDefs.Add('unitid', ftString, 9); FDMemTable1.FieldDefs.Add('unitname', ftString, 9); FDMemTable1.CreateDataSet; end; end.
有本地或远程访问,通过配置服务器配置文件自动路由REST服务:
{ "bin": [ { "classname":"TFuncBin", "method":"POST", "funcname":"select" }, { "classname":"TFuncBin", "method":"POST", "funcname":"save" }, { "classname":"TFuncBin", "method":"POST", "funcname":"execsql" }, { "classname":"TFuncBin", "method":"POST", "funcname":"spopen" }, { "classname":"TFuncBin", "method":"POST", "funcname":"download" }, { "classname":"TFuncBin", "method":"POST", "funcname":"upload" }, { "classname":"TFuncBin", "method":"POST", "funcname":"snowflake" }, { "classname":"TFuncBin", "method":"POST", "funcname":"starttrans" }, { "classname":"TFuncBin", "method":"POST", "funcname":"committrans" }, { "classname":"TFuncBin", "method":"POST", "funcname":"rollbacktrans" } ], "tunit": [ { "classname":"TFuncUnit", "method":"GET", "funcname":"select" }, { "classname":"TFuncUnit", "method":"POST", "funcname":"insert" }, { "classname":"TFuncUnit", "method":"PUT", "funcname":"update" }, { "classname":"TFuncUnit", "method":"DELETE", "funcname":"delete" } ], "multipart": [ { "classname":"TMultiPart", "method":"GET", "funcname":"filedownload" }, { "classname":"TMultiPart", "method":"POST", "funcname":"fileupload" } ], "storedproc": [ { "classname":"TStoredProc", "method":"POST", "funcname":"sp9" } ], "tunit2": [ { "classname":"TFuncUnit2", "method":"GET", "funcname":"select" } ] }
按领域(资源)组织的rest api:
type TCRUD = record resource: string; //资源 sender: TComponent; where: string; function Select: TClientDataSet; function Insert(const rec: array of const): string; function Update(const rec: array of const): string; function Delete: string; end; TMultiPart = record resource: string; //资源 FileSaveTo: string; FileName: string; function DownloadFile: string; function UploadFile: string; end; TStoredProc = record resource: string; //资源 function SP9(sender: TComponent; params: array of const): TClientDataSet; end;
标签:classname,string,funcname,mormot,概述,UniQuery1,POST,method From: https://www.cnblogs.com/hnxxcxg/p/17520354.html