DT 的数据字典
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
4.2 KiB

1 year ago
<%@ CodeTemplate Language="C#" ClassName="Go_ModelOrm2" TargetLanguage="C#" Debug="False" Description="" encoding="GB2312" %>
<%@ Property Name="databaseProjectName" Type="System.String" Default="SpSampleDb" Optional="True" Category="Context" Description="" %>
<%@ Property Name="nameSpace" Type="System.String" Default="Model" Optional="True" Category="Context" Description="" %>
<%
DbEntity db = Template.GetDataBase(databaseProjectName);
foreach(Table tb in db.Tables)
{
OpenResponse(databaseProjectName+"\\GoModelOrm2\\"+tb.ModuleName.ToLower()+"\\"+tb.PropertyName.ToLower()+".go");
string pkey = "";
string pkeyvalue = "";
string pkParmList = "";
foreach(Field fd in tb.Fields)
{
if(fd.IsPK == true){
pkParmList += fd.DataType.DotNetType+" "+fd.MemberName+",";
pkey=fd.PropertyName;
}
}
pkParmList = pkParmList.Trim(',');
%>
/*******************************************************/
/*Project:
Module :
Description :
Date : <%=DateTime.Now.ToString()%>
Create : Lxc
Update :
TODO : */
/*******************************************************/
package <%=tb.ModuleName.ToLower()%>
import (
"hm/eclibs/formatcom"
"hm/eclibs/logger"
"hm/eclibs/db2/db"
)
type <%=tb.PropertyName%> struct {
<%
foreach(Field fd in tb.Fields)
{
if( fd.DataType.Convert == "ToDateTime")
{
Response.Write("\t"+fd.PropertyName +" string ");
}
else if( fd.DataType.Convert == "ToInt32")
{
Response.Write("\t"+fd.PropertyName +" int64 ");
}
else if( fd.DataType.Convert == "ToString")
{
Response.Write("\t"+fd.PropertyName +" string");
}
else if( fd.DataType.Convert == "ToDecimal")
{
Response.Write("\t"+fd.PropertyName +" float64");
}
else {
Response.Write("\t"+fd.PropertyName +" string");
}
Response.WriteLine("\t`json:\""+fd.PropertyName.ToLower()+"\"`");
}
%>
}
func (m *<%=tb.PropertyName%>) TableName() string {
return "<%=tb.TableSpace.ToLower()+tb.PropertyName.ToLower()%>"
}
func (m *<%=tb.PropertyName%>) ViewName() string {
return "v_<%=tb.PropertyName.ToLower()%>"
}
func (m *<%=tb.PropertyName%>) PrimaryKey() string {
return "<%=pkey.ToLower()%>"
}
func (m *<%=tb.PropertyName%>)Add() (int64, error) {
return db.Insert(m)
}
func (m *<%=tb.PropertyName%>) Update( ) (int64, error) {
return db.Update(m)
}
func (m *<%=tb.PropertyName%>) Delete(uid string ) (int64, error) {
sql := "delete from " + m.TableName() + " where "+m.PrimaryKey()+"=?"
return db.ExeSql(sql, uid)
}
func (m *<%=tb.PropertyName%>) GetModel(uid string) *<%=tb.PropertyName%> {
where := m.PrimaryKey()+"=?"
return m.GetModelByWhere(where, uid)
}
func (m *<%=tb.PropertyName%>) GetModelByWhere(where string, args ...interface{}) *<%=tb.PropertyName%> {
<%=tb.PropertyName.ToLower()%>Arr, err := m.<%=tb.PropertyName%>Arr(where,args...)
if err != nil {
logger.Error("GetModel where=", where)
return nil
}
for _, value := range <%=tb.PropertyName.ToLower()%>Arr {
model := new(<%=tb.PropertyName%>)
err :=db.BindData(model, value)
if err !=nil{
logger.Error(err)
continue
}
return model
}
return nil
}
func (m *<%=tb.PropertyName%>)<%=tb.PropertyName%>Arr(where string,args ...interface{}) ([]db.Params, error) {
var sqlstr = "select a.* from " + m.TableName() + " a "
if where != "" {
sqlstr += " where " + where
}
<%=tb.PropertyName.ToLower()%>list, err := db.Query(sqlstr,args...)
return <%=tb.PropertyName.ToLower()%>list, err
}
func (m *<%=tb.PropertyName%>)<%=tb.PropertyName%>List(where string, args ...interface{}) ([]*<%=tb.PropertyName%>, error) {
<%=tb.PropertyName.ToLower()%>List := make([]*<%=tb.PropertyName%>, 0, 1)
<%=tb.PropertyName.ToLower()%>Arr, err := m.<%=tb.PropertyName%>Arr(where,args...)
if err != nil {
return <%=tb.PropertyName.ToLower()%>List, err
}
if <%=tb.PropertyName.ToLower()%>Arr == nil {
return <%=tb.PropertyName.ToLower()%>List, nil
}
for _, value := range <%=tb.PropertyName.ToLower()%>Arr {
model := new(<%=tb.PropertyName%>)
err :=db.BindData(model, value)
if err !=nil{
logger.Error(err)
continue
}
<%=tb.PropertyName.ToLower()%>List = append(<%=tb.PropertyName.ToLower()%>List, model)
}
return <%=tb.PropertyName.ToLower()%>List, nil
}
<%
CloseResponse();
}
%>