使用kbmmw 的ORM 一定先要了解ORM 的对象定义语法。

下面简单说一下

// kbmMW_Table - Define a table.  定义一个表
// Must be used on classes.
//
// Define a table named person.
// [kbmMW_Table('name:person')] 定义表名
//
// Define 2 ascending indexes i_fieldname, and i_anotherfieldname on the field fieldname and anotherfieldname. 定义正向索引
// [kbmMW_Table('name:person, index:fieldname, index:anotherfieldname...
//
// Define an ascending index named i1, on the field name 使用索引名为一个字段定义索引
// [kbmMW_Table('name:person, index:{name:i1,field:name},...
//
// Define a descending index named i1, on the field name 定义反向索引
// [kbmMW_Table('name:person, index:{name:i1,field:name,descending:true},...
//
// Define a compound unique index named i2, on the fields name and age. Name field part is descending. 定义组合唯一索引
// [kbmMW_Table('name:person, index:{name:i2,unique:true,fields:[{name:name,descending:true},{name:age}]
//
// Define method to use when deleting records from a table. Default it will do a regular delete, 定义删除标志,是常规删除还是标志删除
// but it can be set to flag the record as deleted (which is then automatically respected by
// queries later on) or it can be set to backup the record before deletion, to another table.
// [kbmMW_Table('name:person, defaultDeleteMethod:delete')] 也可以定义为移动到另外一个表里面
// defaultDeleteMethod can be delete/default, mark or move.
// If its mark, then deleteMarkProperty must be set to point to a property or field member of the
// class that should mark the deletion state. Futher deleteMarkValue must be set to the (non null)
// value indicating a deleted record.
// If its move, then deleteMoveToTable must be set to the fully scoped name of another defined
// table, which will hold the backups. Make sure to define the table with similarly named field names.
// Also add a different main identifier property as primary key.
//
//
// kbmMW_Field - Define fields in a table. 定义表中的字段
// Must be used on properties within a class if they are to be persisted.
//
// Define a field that will be persisted. Its type will be decided for
// from the property type. String type fields will have a size of 50.
// Table field name will be the same as the property name.
// [kbmMW_Field] 字段标识
//
// Define a field that will be persisted. It will accept unicode data of max 50 characters.
// It will have the same name as the property.
// [kbmMW_Field(ftWideString,50)] 长度为50的字符类型
//
// Define a field named id, and make it primary key. It will be automatically populated bu the generator shortGuid.
// [kbmMW_Field('name:id, primary:true, generator:shortGuid',ftString,40)] 定义字段名称、类型、长度,自动生成属性
// property ID:kbmMWNullable<string> read FID write FID;
// 四种自动生成类型
// These generators exists:
// GUID - Returns a GUID formatted as a regular GUID {123e4567-e89b-12d3-a456-426655440000}
// SHORTGUID - Returns a short GUID where braces and dashes are missing: 123e4567e89b12d3a456426655440000
// SEQUENCE - Returns next unique number from a sequence. Provide name of sequencer in sequence property
// and optional sequencestart property (not supported by all databases!)
// DATETIME - Returns a date time value, formatted according to the dateFormat property. //
// Define a field named id, and make it primary key. It will be populated by a sequence generator.
// Since no sequencer was given, one is automatically generated named s_tablename_fieldname
// [kbmMW_Field('name:id, primary:true, generator:sequence',ftInteger)] 定义字段为主键,并自动用序列生成
// property ID:kbmMWNullable<integer> read FID write FID;
//
// Define a field named id, and make it primary key. It will be populated by sequence generator SEQ, starting from value 10.
// (not all databases supports sequencers with a defined start!) 从10开始,定义序列
// [kbmMW_Field('name:id, primary:true, generator:sequence, seqneuce:SEQ1, sequenceStart:10',ftInteger)]
// property ID:kbmMWNullable<integer> read FID write FID; 属性定义,与字段名相同
//
// Define a field named id, and make it primary key. It will be populated automatically by the database.
// (not all databases support auto increment type fields!)
// [kbmMW_Field('name:id, primary:true',ftAutoInc)] 定位为自增长
// property ID:kbmMWNullable<integer> read FID write FID;
//
// Define a field named datetime containing date/time values as Delphi local time values.
// [kbmMW_Field('name:datetime',ftDateTime)] 定义为日期字段
// property DateTime:TkbmMWDateTime read FDateTime write FDateTime;
//
// Define a field named datetime containing date/time values as Delphi UTC values.
// [kbmMW_Field('name:datetime, dateFormat:UTC',ftDateTime)] 使用UTC 日期
// property DateTime:TkbmMWDateTime read FDateTime write FDateTime;
//
// Define a field named datetime containing date/time values as Unix local time millisecs since EPOC.
// [kbmMW_Field('name:datetime, dateFormat:LOCALSINCEEPOCHMS',ftInt64)] 使用unix 当地日期,毫秒计时
// property DateTime:TkbmMWDateTime read FDateTime write FDateTime;
//
// Define a field named datetime containing date/time values as Unix UTC time millisecs since EPOC.
// [kbmMW_Field('name:datetime, dateFormat:UTCSINCEEPOCHMS',ftInt64)]使用unix UTC日期,毫秒计时
// property DateTime:TkbmMWDateTime read FDateTime write FDateTime;
//
// Define a field named datetime containing date/time values as Unix local time secs since EPOC.
// [kbmMW_Field('name:datetime, dateFormat:LOCALSINCEEPOCH',ftInt64)]使用unix 当地日期,秒计时
// property DateTime:TkbmMWDateTime read FDateTime write FDateTime;
//
// Define a field named datetime containing date/time values as Unix UTC time secs since EPOC.
// [kbmMW_Field('name:datetime, dateFormat:UTCSINCEEPOCH',ftInt64)]使用unix TUC日期,秒计时
// property DateTime:TkbmMWDateTime read FDateTime write FDateTime;
//
// Define a field named datetime containing date/time values as ISO8601 formatted string.
// [kbmMW_Field('name:datetime, dateFormat:ISO8601',ftString,50)] ISO08601 日期
// property DateTime:TkbmMWDateTime read FDateTime write FDateTime;
//
// Define a field named datetime containing date/time values as RFC1123 formatted string.
// [kbmMW_Field('name:datetime, dateFormat:RFC1123',ftString,50)] RFC1123 日期
// property DateTime:TkbmMWDateTime read FDateTime write FDateTime;
//
// Define a field named datetime containing date/time values as NCSA formatted string.
// [kbmMW_Field('name:datetime, dateFormat:NCSA',ftString,50)] NCSA 日期
// property DateTime:TkbmMWDateTime read FDateTime write FDateTime;
//
// kbmMW_Null - Specify NULL conversion.
// (This attribute is also used for object marshalling).
//
// If, for example, a property is of type integer, the property is not directly able to indicate a NULL state since
// all values of an integer are considered non NULL values.
// However its possible to define a specific value to be interpreted as NULL.
// Eg.
// [kbmMW_Field('name:somefield',ftInteger)]
// [kbmMW_Null(-1)] 定义-1 为空
// property MyProperty:integer read FMyProperty write FMyProperty;
//
// This will define that the value -1 must be interpreted as NULL when storing and retrieving data
// from the database.
//
// kbmMW_NotNull - Indicate that the property must never contain the NULL value (either interpreted via the kbmMW_Null attribute or actual).
// Eg.
// [kbmMW_Field('name:somefield',ftInteger)] 字段不准为空
// [kbmMW_NotNull]
// property MyProperty:kbmMWNullable<integer> read FMyProperty write FMyProperty;

以下为实际的定义,请大家认真理解 [kbmMW_Table('name:person, index:{name:i1,field:name,descending:false}, index:{name:i2,unique:true,fields:[{name:name,descending:true},{name:age}]')]
TPerson = class
private
FID:kbmMWNullable<string>;
FName:kbmMWNullable<string>;
FAddress:kbmMWNullable<string>;
FAge:kbmMWNullable<integer>;
public
[kbmMW_Field('name:id, primary:true, generator:shortGuid',ftString,)]
property ID:kbmMWNullable<string> read FID write FID; [kbmMW_Field('name:name',ftWideString,)]
property FullName:kbmMWNullable<string> read FName write FName; [kbmMW_Field('name:address',ftWideString,)]
property Address:kbmMWNullable<string> read FAddress write FAddress; [kbmMW_Field('name:age',ftInteger)]
property Age:kbmMWNullable<integer> read FAge write FAge;
end; [kbmMW_Table('name:account')]
TAccount = class
private
FID:kbmMWNullable<string>;
FPersonID:string;
FName:kbmMWNullable<string>;
FValue:double;
public
[kbmMW_Field('name:id, primary:true, generator:shortGuid',ftString,)]
[kbmMW_NotNull]
property ID:kbmMWNullable<string> read FID write FID; [kbmMW_Field('name:personid',ftString,)]
[kbmMW_NotNull]
[kbmMW_Null('')]
property PID:string read FPersonID write FPersonID; [kbmMW_Field('name:name, default:"Unknown"',ftString,)]
[kbmMW_NotNull]
property Name:kbmMWNullable<string> read FName write FName; [kbmMW_Field]
[kbmMW_Null(Math.NaN)]
property Value:double read FValue write FValue;
end; [kbmMW_VirtualTable(TAccount)]
TAccountWithPerson = class(TAccount)
private
FPerson:TPerson;
public
destructor Destroy; override; [kbmMW_VirtualField('name:person, source:uData.TPerson, key:PID, sourceKey:ID')]
property Person:TPerson read FPerson write FPerson;
end; [kbmMW_VirtualTable(TAccount)]
TAccountWithPersonName = class(TAccount)
private
FFullName:kbmMWNullable<string>;
public
// [kbmMW_VirtualField('name:fullName, source:uData.TPerson, key:PID, sourceKey:ID, value:uData.TPerson.FullName')]
[kbmMW_VirtualField('name:fullName, source:uData.TPerson, key:PID, sourceKey:ID, value:"uData.TPerson.FullName||\" Age:\"||uData.TPerson.Age"')]
property FullName:kbmMWNullable<string> read FFullName write FFullName;
end; [kbmMW_VirtualTable(TPerson)]
TPersonWithAccounts = class(TPerson)
private
FAccounts:TObjectList<TAccount>;
public
destructor Destroy; override; [kbmMW_VirtualField('name:accounts, source:uData.TAccount, key:ID, sourceKey:PID')]
property Accounts:TObjectList<TAccount> read FAccounts write FAccounts;
end; // [kbmMW_Table('name:image, defaultDeleteMethod:mark, deleteMarkProperty:Deleted, deleteMarkValue:true')]
[kbmMW_Table('name:image, defaultDeleteMethod:move, deleteMoveToTable:uData.TBackupImage')]
TImage = class
private
FID:kbmMWNullable<string>;
FDescription:kbmMWNullable<string>;
FPersonID:string;
FBlob:TMemoryStream;
FDeleted:boolean;
protected
procedure SetBlob(AValue:TMemoryStream); virtual;
public
constructor Create; virtual;
destructor Destroy; override; [kbmMW_Field('name:id, primary:true, generator:shortGuid',ftString,)]
[kbmMW_NotNull]
property ID:kbmMWNullable<string> read FID write FID; [kbmMW_Field('name:personid',ftString,)]
[kbmMW_NotNull]
[kbmMW_Null('')]
property PID:string read FPersonID write FPersonID; [kbmMW_Field('name:description',ftString,)]
property Description:kbmMWNullable<string> read FDescription write FDescription; [kbmMW_Field('name:blob',ftGraphic)]
[kbmMW_NotNull]
property Blob:TMemoryStream read FBlob write SetBlob; [kbmMW_Field('name:deleted',ftBoolean)]
[kbmMW_NotNull]
property Deleted:boolean read FDeleted write FDeleted;
end; [kbmMW_Table('name:backupImage')]
TBackupImage=class(TImage)
private
FBackupID:kbmMWNullable<string>; public
// [kbmMW_Field('name:backupId, primary:true, generator:shortGuid',ftString,40)]
// [kbmMW_NotNull]
// property BackupID:kbmMWNullable<string> read FBackupID write FBackupID;
//
[kbmMW_Field('name:id, primary:true',ftString,)]
[kbmMW_NotNull]
property ID:kbmMWNullable<string> read FID write FID;
end; [kbmMW_VirtualTable]
TPersonAccount = class
private
FID:string;
FName,FAccountName:kbmMWNullable<string>;
FValue:double;
public
[kbmMW_Field('name:id')]
property ID:string read FID write FID; [kbmMW_Field('name:name')]
property Name:kbmMWNullable<string> read FName write FName; [kbmMW_Field('name:accountName')]
property AccountName:kbmMWNullable<string> read FAccountName write FAccountName; [kbmMW_Field('name:value')]
property Value:double read FValue write FValue;
end; [kbmMW_Table('name:person2')]
TPerson2 = class
private
FID:kbmMWNullable<string>;
FName:kbmMWNullable<string>;
FAddress:kbmMWNullable<string>;
FAge:kbmMWNullable<integer>;
FAccounts:TObjectList<TAccount>;
public
constructor Create; virtual;
destructor Destroy; override; [kbmMW_Field('name:id, primary:true, generator:shortGuid',ftString,)]
property ID:kbmMWNullable<string> read FID write FID; [kbmMW_Field('name:name',ftWideString,)]
property Name:kbmMWNullable<string> read FName write FName; [kbmMW_Field('name:address',ftWideString,)]
property Address:kbmMWNullable<string> read FAddress write FAddress; [kbmMW_Field('name:age',ftInteger)]
property Age:kbmMWNullable<integer> read FAge write FAge; [kbmMW_Field('join:{source:ID,dest:PersonID}')]
property Accounts:TObjectList<TAccount> read FAccounts;
end;
东西真多,什么时候可以可视化设计就好了。

kbmmw ORM 对象定义语法简析的更多相关文章

  1. windows bat批处理语法简析

    第一节先介绍windows批处理.这个起源于跟旁边同事学习在windows用命令行办公,渐渐地有些批处理功能就需要了,于是专门抽出了几天学习了一下.我认为文档最重要的功能是为了备忘,择取了很多文档的例 ...

  2. Java Annotation 及几个常用开源项目注解原理简析

    PDF 版: Java Annotation.pdf, PPT 版:Java Annotation.pptx, Keynote 版:Java Annotation.key 一.Annotation 示 ...

  3. 简析 .NET Core 构成体系

    简析 .NET Core 构成体系 Roslyn 编译器 RyuJIT 编译器 CoreCLR & CoreRT CoreFX(.NET Core Libraries) .NET Core 代 ...

  4. Php ORM 对象关系映射

    ORM的全称是Object Relational Mapping,即对象关系映射.它的实质就是将关系数据(库)中的业务数据用对象的形式表示出来,并通过面向对象(Object-Oriented)的方式将 ...

  5. [转载] Thrift原理简析(JAVA)

    转载自http://shift-alt-ctrl.iteye.com/blog/1987416 Apache Thrift是一个跨语言的服务框架,本质上为RPC,同时具有序列化.发序列化机制:当我们开 ...

  6. 简析 __init__、__new__、__call__ 方法

    简析 __init__.__new__.__call__ 方法 任何事物都有一个从创建,被使用,再到消亡的过程,在程序语言面向对象编程模型中,对象也有相似的命运:创建.初始化.使 用.垃圾回收,不同的 ...

  7. 0002 - Spring MVC 拦截器源码简析:拦截器加载与执行

    1.概述 Spring MVC中的拦截器(Interceptor)类似于Servlet中的过滤器(Filter),它主要用于拦截用户请求并作相应的处理.例如通过拦截器可以进行权限验证.记录请求信息的日 ...

  8. Unity5中新的Shader体系简析

    一.Unity5中新的Shader体系简析 Unity5和之前的书写模式有了一定的改变.Unity5时代的Shader Reference官方文档也进一步地变得丰满. 主要需要了解到的是,在原来的Un ...

  9. Linux VFS机制简析(二)

    Linux VFS机制简析(二) 接上一篇Linux VFS机制简析(一),本篇继续介绍有关Address space和address operations.file和file operations. ...

随机推荐

  1. GIT 命令集

    Git图形化界面 下面是我整理的常用 Git 命令清单.几个专用名词的译名如下. Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remot ...

  2. js实现右击

    <!DOCTYPE html> <html>     <head>  <meta charset="UTF-8">  <tit ...

  3. Centos 下使用VLAN+Bridge 搭建KVM基础网络环境

    一.使用环境介绍 宿主机上同时运行多网段虚拟机,为了解决宿主机网卡资源紧张问题,采用如下网络模式:(本实验vlan 105:192.168.5.x    vlan108:192.168.8.x) 二. ...

  4. HDU-1212.BigNumber(有关模数的定理)

    本题大意:给出一个1000位以内的大数和一个小数,让你计算并给出大数对小数取余的结果. 本题思路:由下面的公式可以推出本题的计算公式,套入即可解决,建议自己把这个公式推一下,很简单的... 参考代码: ...

  5. Mac 动态库加载不上

    OC xcode can't found xxx.dylib 1 targer- build phase :link binary with library添加动态库 注意不要将后边的选项选成opti ...

  6. day 06 列表去重, 数据类型的补充,编码,深浅copy

    因为重要,所以放前面 列表去重 l1 = [1, 2, 3, 4, 5] l2 = [3, 4, 5, 6, 7] set = list(set(l1 + l2)) # set自动去重,然后变成lis ...

  7. RPM打包原理、示例、详解及备查( 转)

    RPM(Redhat Package Manager)是用于Redhat.CentOS.Fedora等Linux 分发版(distribution)的常见的软件包管理器.因为它允许分发已编译的软件,所 ...

  8. 利用shell脚本远程登录服务器并修改saltstack配置并重启服务

    最近公司为了上一个活动功能,增加了40台服务器,虽然服务器可以通过saltstack 来统一管理(自动化运维工具 SaltStack 搭建),项目可以通过jenkins + saltstack统一发布 ...

  9. go语言sync包的学习(Mutex、WaitGroup、Cond)

    package main; import ( "fmt" "sync" "runtime" "time" ) //加锁, ...

  10. JAVA虚拟机是?为什么称作是“平台无关的语言”?

    Java虚拟机(Java Virtual Machine)简称JVM ,它是抽象化的计算机,有自己完善的硬体架构,如处理器.堆栈.寄存器等,还具有相应的指令系统.JVM屏蔽了与具体操作系统平台相关的信 ...