
- 和Select方法不同的是,Scan方法仅仅影响输出,类似GoRedis的Scan的思想,依然需要指定table,只是最后的Get或者Find方法换成本方法即可 - 传入struct{}可以解析单条,类似Find方法 - 传入[]struct{}将会解析成多条,类似Get方法 注意需要传入指针值,例如传入:&User{},而不是:User{} 避免(不是禁止的意思)使用这个方法传入Map[string]interface{} 如果你全程使用struct方法,建议你可以直接使用table().select()这样原版框架支持的模式来操作数据库,因为从代码思想和洁净度角度来看,保持业务代码风格统一也是很重要的
7.0 KiB
GoRose-ORM-Pro A Free Go MySQL ORM
██████╗ ██████╗ ██████╗ ██████╗ ███████╗███████╗ ██████╗ ██████╗ ██████╗
██╔════╝ ██╔═══██╗██╔══██╗██╔═══██╗██╔════╝██╔════╝ ██╔══██╗██╔══██╗██╔═══██╗
██║ ███╗██║ ██║██████╔╝██║ ██║███████╗█████╗█████╗██████╔╝██████╔╝██║ ██║
██║ ██║██║ ██║██╔══██╗██║ ██║╚════██║██╔══╝╚════╝██╔═══╝ ██╔══██╗██║ ██║
╚██████╔╝╚██████╔╝██║ ██║╚██████╔╝███████║███████╗ ██║ ██║ ██║╚██████╔╝
╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝
What the difference between this than the OriginalVer.
- All functionality was updated to the latest version from the original version
- Intuition Coding
- Nested Transactions functionality
- Simple update without any hesitation ,fully compatible with earlier versions
- Fully support MySQL and MariaDB
- Document support as detail as possible
- 100% compatible with original function
- Dealing PR & Bug fix much more sooner
- All function has been tested and verified by commercial projects
- Support complexity and/or sql in Where/OrWhere function
- Paginator is now able to return the correct TOTAL number
- Add CountGroup to return correct row count from sql sentence
- SubQuery: Highly security parameterized query under prepared condition
- SubWhere: Full Prepared condition parameterized where sql searching
- Fixed original framework's Executor might have unintentionally error or deleted data
- Oracle support "Replace()" function like MyBatis when a good performance
Purpose of this project
- Fee: Totally Free but only need your star
- Avoid the risk of the deprecation of the original ver
- To solve the shortage during coding in the real life
- Massive demos from the document, what ever the skill you are, you still able to find a solution here
Bug Fix
- Dirty Read under concurrency circumstances(this will be only and easily triggered by using *db mode)
- Paginate fixed, this function finally come back to life, new "Paginator" function make it much more easier to use
- Fix the row_count(Total in Paginator mode) when using GroupBy function
- Fix Oracle unable to connect & use problem, Fixed arm MacM1 chip's compatibility with Oracle
Docs and Demos(Wiki)
Notice:'*' means Only Support In GorosePro
- CUD functions
- Read the first line data and return in map[string]any
- Read multiple data in array by []map[string]any
- Raw SQL sentence mode
- Nested Transaction(only support in GorosePro)
- subQuery
- Security and Performance
- Single/Multiple data to struct(Struct)
Introduction
Gorosepro is an upgrade and revision project of GOORM. It fixes bugs on the basis of supporting all functions of the original framework and is more suitable for complex commercial projects
Support decoupling development and intuitive programming, greatly reduce your trial and error cost, make small projects develop faster, and make large projects easier to maintain
Installation
- Add in go.mod
require github.com/tobycroft/gorose-pro v1.2.5
- go get
go get -u github.com/tobycroft/gorose-pro
Driver support
- mysql : https://github.com/go-sql-driver/mysql
- sqlite3 : https://github.com/mattn/go-sqlite3
- postgres : https://github.com/lib/pq
- oracle : https://github.com/sijms/go-ora
- mssql : https://github.com/denisenkom/go-mssqldb
- clickhouse : https://github.com/kshvakov/clickhouse
Initializing
For more configurations, you can configure the cluster, or even configure different databases at the same time. In a cluster, the database will randomly select the database of the cluster to complete the corresponding read-write operations. The master is the write database, and the slave is the read database. You need to do master-slave replication. Here, you are only responsible for reading and writing
var config1 = gorose.Config{Dsn: 上面的dsn}
var config2 = gorose.Config{Dsn: 上面的dsn}
var config3 = gorose.Config{Dsn: 上面的dsn}
var config4 = gorose.Config{Dsn: 上面的dsn}
var configCluster = &gorose.ConfigCluster{
Master: []gorose.Config{config3, config4},
Slave: []gorose.Config{config1, config2},
Driver: "sqlite3",
}
Initialize then use
var engin *gorose.Engin
engin, err := Open(config)
//engin, err := Open(configCluster)
if err != nil {
panic(err.Error())
}