mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
This pull request introduces a new database driver for openGauss (GaussDB), integrating it into the GoFrame framework. The implementation includes connection handling, SQL execution, type conversion, and other driver-specific logic. Additionally, the CI workflow is updated to include an openGauss server for testing. The main themes are: new driver implementation, SQL and type handling, and CI integration. **GaussDB Driver Implementation:** * Added a new driver in `contrib/drivers/gaussdb` to support openGauss/GaussDB databases, including initialization, connection handling, and registration with GoFrame's database abstraction. (`gaussdb.go`, `gaussdb_open.go`) [[1]](diffhunk://#diff-4f0d2a9160a039ccdf1dc98205ed7cd9f3bb8d606fed57c5a4813937eecca81fL11-R49) [[2]](diffhunk://#diff-a0534a00c87159a3a3d2ea20a9779ead115cc7e38ab274484cfd4b2aa86b6055R1-R69) * Implemented custom SQL execution and result handling to support GaussDB's PostgreSQL-based features, including primary key handling on insert and custom result types. (`gaussdb_do_exec.go`, `gaussdb_result.go`) [[1]](diffhunk://#diff-528b2ec06651f4af022e0550526794a606bf257d59bc18b6bce58373c784a2f2R1-R110) [[2]](diffhunk://#diff-ad33dffe3bbccae20b113e3865aa491ef3b54c68ef586a89cf09a581a1c2abedR1-R24) **SQL and Type Handling:** * Added SQL filtering and placeholder conversion to support PostgreSQL-style parameterization and GaussDB-specific SQL quirks, such as handling `INSERT IGNORE` and JSONB syntax. (`gaussdb_do_filter.go`) * Implemented comprehensive type conversion logic for mapping PostgreSQL/GaussDB types to Go types, including arrays, UUIDs, and custom handling for JSON and numeric types. (`gaussdb_convert.go`) * Provided a function for random ordering (`ORDER BY RANDOM()`) and explicitly disabled upsert/ON CONFLICT support, as GaussDB does not support this feature. (`gaussdb_order.go`, `gaussdb_format_upsert.go`) [[1]](diffhunk://#diff-510fc9393899057fddacc7dd6d14f0ca2fff145b52341dd3cfa5db48c960e5c1R1-R12) [[2]](diffhunk://#diff-c89496520a15032be867e26861b248f11557cc45d683b5216ca1756949a7b9adR1-R94) **CI Integration:** * Updated the CI workflow to start an openGauss server in Docker, enabling automated tests against the new driver. (`.github/workflows/ci-main.yml`) --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
// Package gaussdb implements gdb.Driver, which supports operations for database GaussDB.
|
|
package gaussdb
|
|
|
|
import (
|
|
_ "gitee.com/opengauss/openGauss-connector-go-pq"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
)
|
|
|
|
// Driver is the driver for GaussDB database.
|
|
type Driver struct {
|
|
*gdb.Core
|
|
}
|
|
|
|
const (
|
|
internalPrimaryKeyInCtx gctx.StrKey = "primary_key"
|
|
defaultSchema string = "public"
|
|
quoteChar string = `"`
|
|
)
|
|
|
|
func init() {
|
|
if err := gdb.Register(`gaussdb`, New()); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// New create and returns a driver that implements gdb.Driver, which supports operations for PostgreSql.
|
|
func New() gdb.Driver {
|
|
return &Driver{}
|
|
}
|
|
|
|
// New creates and returns a database object for postgresql.
|
|
// It implements the interface of gdb.Driver for extra database driver installation.
|
|
func (d *Driver) New(core *gdb.Core, node *gdb.ConfigNode) (gdb.DB, error) {
|
|
return &Driver{
|
|
Core: core,
|
|
}, nil
|
|
}
|
|
|
|
// GetChars returns the security char for this type of database.
|
|
func (d *Driver) GetChars() (charLeft string, charRight string) {
|
|
return quoteChar, quoteChar
|
|
}
|