缺省SQLGeneration的快速帮助
EDT 0.7.0版本为基于EGL的行为语句产生缺省的SQL语句提供了快速帮助:
-
ADD 语句
-
DELETE语句
-
GET语句
-
OPEN语句
-
REPLACE语句
下面用样例来说明如何在EDT中使用这种功能:
EGL 记录定义
recordProduct{@Table {name="Product"}} id bigint{@Id}; name string; price float; end
上面定义了一个基本记录类型,必须使用注释@Id来指定记录的那个字段映射为表的主键,使用注释@Table来说明这个记录映射为那个表,就像上面的定义那样,不过@Table的使用是可选的。
record OrderItem type Entity{@table{name = "OrderItem"}} ITEM_ID int{@Id}; NAME string{ @Column { insertable=true } }; IMAGE string?{ @Column { updateable=true } }; PRICE decimal(7, 2)?; DESCRIPTION string?; end
上面是对应一个表的 entity 记录定义。
EGL变量定义
basicRec Product; itemEntity OrderItem; rs SQLResultSet?; ds SQLDataSource? = new SQLDataSource("jdbc:derby:C:/databases/EGLDerbyR7;create=true");ADD语句
在EGL语句的任何地方点击并按Ctrl+1,选择“AddSQL Statement” 建议,缺省的SQL语句将添加到已有的EGL语句中:
add basicRec to ds; //for basic record变成:
add basicRec to ds with #sql{ insert into Product (id, name, price) values (?, ?, ?) };
add itemEntity to ds; //for entity record变成:
add itemEntity to ds with #sql{ insert into OrderItem (ITEM_ID, Name, IMAGE, price, description) values (?, ?, ?, ?, ?) };
DELETE语句
GET语句
GET basicRec from ds; //for basic record变成:GET itemEntity from ds; //for entity record变成: