Sunday, September 8, 2024
HomeGolangGDAO: A Streamlined Go Persistence Framework with Enhanced Productiveness and Efficiency -...

GDAO: A Streamlined Go Persistence Framework with Enhanced Productiveness and Efficiency – Releases


GDAO —— Go Persistence Framework

A Streamlined Go Persistence Framework with Enhanced Productiveness and Efficiency
Combining the Abstraction of Hibernate with the Flexibility of MyBatis for Go Purposes

Introduction

Gdao is an revolutionary persistence layer resolution geared toward lowering coding workload, enhancing productiveness, enhancing efficiency, supporting multi-data supply integration, and facilitating knowledge read-write separation. By leveraging Gdao, builders can lower the quantity of code required for the persistence layer by 30% to 50%, set up unified coding requirements, reduce errors, and guarantee simpler upkeep and growth.

gdao for go is equal to hibernate+mybatis for java, the gdao framework combines the abstraction of Hibernate and the pliability of MyBatis, and solves the ache factors of their respective long-standing use on ORM frameworks. Check with the jdao utilization documentation for ache factors between hibernate and mybatis

  • The GDAO design construction is each concise and rigorous, with all interfaces and features named descriptively so their objective is straight away clear.
  • Even in case you are new to GDAO, you’ll be able to rapidly perceive its code and the related knowledge behaviors.
  • The simplicity of GDAO ensures you could grasp its utilization inside minutes.

Github

Official Web site

Documentation

Demo

Key Options

  1. Code Technology: Use the Gdao code technology software to create standardized entity courses for database tables, just like Thrift/Protobuf.
  2. Environment friendly Serialization: The standardized entity courses for tables implement environment friendly serialization and deserialization, larger efficiency and smaller knowledge quantity.
  3. Help for Information Learn-Write Separation: Gdao helps binding a number of knowledge sources and knowledge read-write separation, permitting knowledge sources to be certain to tables, courses, mapping interfaces, and different properties.
  4. Help for Information Caching: Gdao helps knowledge caching with detailed management over cache knowledge lifecycle and recycling options.
  5. Broad Compatibility: Gdao theoretically helps all databases that implement the Go database driver interface.
  6. Superior Options: Helps transactions, saved procedures, batch processing, and different database operations.
  7. Help SQL and program separation: Just like mybatis, gdao helps xml file write sql mapping calls. This is without doubt one of the few orm options that helps the separation of SQL and applications, however it is extremely highly effective.

GDAO’s Modern ORM Resolution

Gdao is a sibling framework to Jdao, sharing its design patterns.

  1. Standardized Mapped Entity Courses for Single Desk CRUD Operations: Over 90% of single-table operations might be carried out by entity courses. These CRUD operations are typically not concerned in advanced SQL optimization and might be generated by entity courses to scale back error charges and simplify upkeep.
    By using mechanisms comparable to caching and read-write separation, the persistence layer turns into extra environment friendly and handy. The information operation format of standardized entity courses is just not merely a concatenation of object features however is extra akin to SQL operations, making it simpler to grasp.
  2. Execution of Complicated SQL: Complicated SQL, particularly multi-table joins, typically require optimization based mostly on the desk construction and index properties. Utilizing objects to concatenate advanced SQL can enhance the issue of understanding and will result in builders being unaware of the ultimate executed SQL, thereby growing threat and upkeep issue.
    Due to this fact, Gdao recommends utilizing Gdao’s CRUD interfaces for advanced SQL issues. Gdao offers versatile knowledge conversion and environment friendly object mapping implementations, avoiding extreme use of time-consuming operations comparable to reflection.
  3. SQL Mapping Information: For advanced SQL operations, Gdao offers corresponding CRUD interfaces. It additionally helps mapping SQL by XML configuration for interface invocation, just like the Java MyBatis ORM framework. Nevertheless, in contrast to MyBatis which requires mapping all SQL operations, Gdao offers full SQL mapping interfaces however recommends solely mapping advanced SQL or operations that standardized entity courses can not full.
    Gdao’s SQL configuration information reference the MyBatis configuration file format, implementing a brand new parser that permits for larger flexibility and tolerance of configuration parameter sorts (check with the documentation).


Core Elements

1. gdao

Foremost core entry level offering the next functionalities:

  • Setting knowledge sources
  • SQL CRUD features

2. gdaoCache

Cache entry level supporting the next functionalities:

  • Binding or unbinding packages, courses, and different properties to allow or disable question caching

3. gdaoSlave

Learn-write separation operation entry level supporting the next functionalities:

  • Binding or unbinding packages, courses, and different properties to allow or disable read-write separation

4. gdaoMapper

Execute SQL instantly by calling Gdao’s CRUD interfaces or use XML file mappings and name by gdaoMapper by Mapper Id


Fast Begin

1. Set up

# import gdao
go get github.com/donnie4w/gdao

2. Configure Information Supply

gdao.Init(mysqlDB, gdao.MYSQL)
// gdao.MYSQL is the database kind

3. Generate Desk Entity Courses

Use the Gdao code technology software to generate standardized entity courses for database tables.

4. Entity Class Operations

// Set knowledge supply
gdao.Init(mysqlDB, gdao.MYSQL)

// Learn
hs := dao.NewHstest()
hs.The place(hs.Id.EQ(10))
h, _ := hs.Choose(hs.Id, hs.Worth, hs.Rowname)
logger.Debug(h)
//[DEBUG][SELECT ONE][ select id, value, rowname from hstest where id=?][10]

// Replace
hs := dao.NewHstest()
hs.SetRowname("hello10")
hs.The place(hs.Id.EQ(10))
hs.Replace()
//[DEBUG][UPDATE][update hstest set rowname=? where id=?][hello10 10]

// Delete
hs := dao.NewHstest()
hs.The place(hs.Id.EQ(10))
hs.Delete()
//[DEBUG][DELETE][delete from hstest where id=?][10]

// Insert
hs := dao.NewHstest()
hs.SetValue("hello123")
hs.SetLevel(12345)
hs.SetBody([]byte("good day"))
hs.SetRowname("hello1234")
hs.SetUpdatetime(time.Now())
hs.SetFloa(123456)
hs.SetAge(123)
hs.Insert()
//[DEBUG][INSERT][insert into hstest(floa, age, value, level, body, rowname, updatetime) values(?,?,?,?,?,?,?)][123456 123 hello123 12345 [104 101 108 108 111] hello1234 2024-07-17 19:36:44]

5. gdao api

CRUD Operations
// Question, return single file
bean, _ := gdao.ExecuteQueryBean("choose id, worth, rowname from hstest the place id=?", 10)
logger.Debug(bean)

// Insert
i := gdao.ExecuteUpdate("insert into hstest2(rowname, worth) values(?,?)", "helloWorld", "123456789")

// Replace
i := gdao.ExecuteUpdate("replace hstest set worth=? the place id=1", "good day")

// Delete
i := gdao.ExecuteUpdate("delete from hstest the place id = ?", 1)

6. gdaoCache

Configure Caching
// Bind Hstest to allow caching, cache expiration set to 300 seconds
gdaoCache.BindClass[dao.Hstest]()

// First question Hstest and set knowledge cache based mostly on situations
hs := dao.NewHstest()
hs.The place((hs.Id.Between(0, 2)).Or(hs.Id.Between(10, 15)))
hs.Restrict(3)
hs.Selects()

// For a similar situations, knowledge is instantly retrieved from cache
hs = dao.NewHstest()
hs.The place((hs.Id.Between(0, 2)).Or(hs.Id.Between(10, 15)))
hs.Restrict(3)
hs.Selects()
Execution Consequence
[DEBUG][SELECT LIST][ select id, age, rowname, value, updatetime, body, floa, level from hstest where id between ? and ? or (id between ? and ?) LIMIT ? ][0 2 10 15 3]
[DEBUG][SET CACHE][ select id, age, rowname, value, updatetime, body, floa, level from hstest where id between ? and ? or (id between ? and ?) LIMIT ? ][0 2 10 15 3]
[DEBUG][SELECT LIST][ select id, age, rowname, value, updatetime, body, floa, level from hstest where id between ? and ? or (id between ? and ?) LIMIT ? ][0 2 10 15 3]
[DEBUG][GET CACHE][ select id, age, rowname, value, updatetime, body, floa, level from hstest where id between ? and ? or (id between ? and ?) LIMIT ? ][0 2 10 15 3]

7. gdaoSlave

Learn-Write Separation
// Set slave knowledge supply: mysql
mysqlDB, _ := getDataSource("mysql.json")
gdaoSlave.BindClass[dao.Hstest](mysqlDB, gdao.MYSQL)
// Right here the principle database is sqlite and the slave database is mysql. Hstest reads knowledge from mysql
hs := dao.NewHstest()
hs.The place(hs.Id.Between(0, 5))
hs.OrderBy(hs.Id.Desc())
hs.Restrict(3)
hs.Selects()

8. gdaoMapper

Use XML to Map SQL
<!-- MyBatis type XML configuration file -->
<mapper namespace="consumer">
   <choose id="selectHstest1" parameterType="int64" resultType="hstest1">
      SELECT * FROM hstest1 ORDER BY id DESC LIMIT #{restrict}
   </choose>
</mapper>
// Set knowledge supply
if db, err := getDataSource("sqlite.json"); err == nil {
   gdao.Init(db, gdao.SQLITE)  
   gdao.SetLogger(true)
}

// Learn and parse XML configuration
hs1, _ := gdaoMapper.Choose[dao.Hstest1]("consumer.selectHstest1", 1)
fmt.Println(hs1)

id, _ := gdaoMapper.Choose[int64]("consumer.selectHstest1", 1)
fmt.Println(*id)
Execution Consequence
[DEBUG][Mapper Id] consumer.selectHstest1 
SELECTONE SQL[SELECT * FROM hstest1 ORDER BY id DESC LIMIT ?]ARGS[1]
Id:52, Rowname:rowname>>>123456789, Worth:[104 101 108 108 111 32 103 100 97 111], Goto:[49 50 51 52 53]
[DEBUG][Mapper Id] consumer.selectHstest1 
SELECTONE SQL[SELECT * FROM hstest1 ORDER BY id DESC LIMIT ?]ARGS[1]
52

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments