洞察探索open banking如何通过小程序容器技术助力金融企业实现数据安全和数字化转型
1734
2022-10-11
Hexya是一个用Go编写的开源ERP和业务应用程序开发框架
Hexya
Hexya is an open source ERP and a business application development framework written in Go.
This repository houses the business application development framework. The ERP is built by integrating modules of the Hexya Addons Project
Features of the framework
The Hexya framework is designed to develop business applications quickly and safely. It includes all needed components in a very opinionated way.
The examples below are here to give you a first idea of Hexya.
Head to the /doc directory and especially our Tutorial if you want to start developing your business application with Hexya.
ORM
Hexya includes a full-featured type safe ORM, including a type safe query builder.
Declare a model and add some fields
var fields_User = map[string]models.FieldDefinition{ "Name": fields.Char{String: "Name", Help: "The user's username", Unique: true, NoCopy: true, OnChange: h.User().Methods().OnChangeName()}, "Email": fields.Char{Help: "The user's email address", Size: 100, Index: true}, "Password": fields.Char{}, "IsStaff": fields.Boolean{String: "Is a Staff Member", Help: "Set to true if this user is a member of staff"},}func init() { models.NewModel("User") h.User().AddFields(fields_User)}
Use the ORM to create a record in the database with type-safe data
newUser := h.User().Create(env, h.User().NewData(). SetName("John"). SetEmail("john@example.com"). SetIsStaff(true))
Search the database using the type-safe query builder and update records directly
myUsers := h.User().Search(env, q.User().Name().Contains("John"). And().Email().NotEquals("contact@example.com"))for _, myUser := range myUsers.Records() { if myUser.IsStaff() { myUser.SetEmail("contact@example.com") } }
Add methods to the models
// GetEmail returns the Email of the user with the given namefunc user_GetEmail(rs m.UserSet, name string) string { user := h.User().Search(env, q.User().Name().Equals("John")).Limit(1) user.Sanitize() // Call other methods of the model return user.Email() // If user is empty, then Email() will return the empty string}func init() { h.User().NewMethod("GetEmail", user_GetEmail)}
Views
Define views of different types using a simple XML view definition and let the framework do the rendering:
Controllers
Most of the time, you do not need to declare controllers in Hexya. Instead, declare an "Action" with the views you want and a menu to access it. The framework will take care of the UI including rendering views, navigation, CRUD, etc.
Iterative Definition and Modularity
Each part of the Hexya Framework is modular and follow the Iterative Definition concept.
This means that an object (for example a model class) can be defined in a module and then extended in place by dependent modules. So any subsequent modification will be made on the original model and will be available for the whole application.
This makes it possible to customize the application by creating a new module with the new features without forking and still benefiting from upstream updates.
Example on models:
package Avar fields_User = map[string]models.FieldDefinition{ "Name": fields.Char{String: "Name", Help: "The user's username", Unique: true, NoCopy: true, OnChange: h.User().Methods().OnChangeName()}, "Email": fields.Char{Help: "The user's email address", Size: 100, Index: true}, "Password": fields.Char{}, "IsStaff": fields.Boolean{String: "Is a Staff Member", Help: "Set to true if this user is a member of staff"},}func init() { models.NewModel("User") h.User().AddFields(fields_User)}
package Bvar fields_User = map[string]models.FieldDefinition{ "Size": models.Float{},}func init() { h.User().AddFields(fields_User)}
// Anywhere elsenewUser := h.User().Create(env, h.User().NewData(). SetName("John"). SetEmail("john@example.com"). SetSize(185.7))fmt.Println(newUser.Name())// output : Johnfmt.Println(newUser.Size())// output : 185.7
Model methods can be extended too:
package A// GetEmail returns the Email of the user with the given namefunc user_GetEmail(rs m.UserSet, name string) string { user := h.User().Search(rs.Env(), q.User().Name().Equals(name)).Limit(1) user.Sanitize() return user.Email() }func init() { h.User().NewMethod("GetEmail", user_GetEmail)}
package Bfunc init() { h.User().Methods().GetEmail().Extend( func(rs m.UserSet, name string) string { res := rs.Super().GetEmail(name) return fmt.Sprintf("<%s>", res) })}
// Anywhere elseemail := h.User().NewSet(env).GetEmail("John")fmt.Println(email)// output:
And it works also with views:
And the rendered view will be :
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~