mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
This pull request adds first-class support for MariaDB, TiDB, OceanBase, and GaussDB as separate database drivers in the GoFrame ecosystem, rather than relying solely on MySQL compatibility. It introduces new driver packages for each database, updates documentation to reflect these additions, and adjusts dependency management files accordingly. The changes also deprecate the MariaDB-specific logic in the MySQL driver in favor of the new dedicated MariaDB driver. **New Database Driver Support** * Added new driver packages for MariaDB, TiDB, OceanBase, and GaussDB under `contrib/drivers/`, each with their own Go module files and driver implementation that wraps the MySQL driver for protocol compatibility and future extensibility. [[1]](diffhunk://#diff-0dd9dca0fb712c3691a95186853d1fc38a30a74ba34cbdc9aa6facee5457d681R1-R48) [[2]](diffhunk://#diff-23c6a84d45f3b30ae7ab1a95dec0b30329e702923cc74c5344b3606237ddd929R1-R44) [[3]](diffhunk://#diff-a8a6766c0d5b9c0788d0276b41b33fdbe786e0584fda19fd26db715bcf46fbcdR1-R48) [[4]](diffhunk://#diff-2cbf2f66d5cb77d9f4d00e4c0ce45055620fff50c941a588da31729f09a81f1bR1-R44) [[5]](diffhunk://#diff-4f0d2a9160a039ccdf1dc98205ed7cd9f3bb8d606fed57c5a4813937eecca81fR1-R47) [[6]](diffhunk://#diff-accbd2d37d45e51db3fcb0468043b1e1fd53eeac9e3d3558467ef24444188d2fR1-R44) [[7]](diffhunk://#diff-15fac9b8e76d2782594c91da72f6a6f42fc18e359c3be35bf6564ac3ca09f700R1-R44) * Registered these new drivers in the main module's `go.mod` and `go.work` files for proper dependency resolution and local development. [[1]](diffhunk://#diff-ee0abb9c50b9f91f424349123e31b7b1ba1e1e4f7497250422696c5bda2e74ceR12-R15) [[2]](diffhunk://#diff-a70c108de96ca9b56b7768254143b2b9f20ce1dcab51d92ce083fdfcba2efd6cR17-R20) **Documentation Updates** * Expanded the `contrib/drivers/README.MD` to include installation and import instructions for the new drivers, and clarified the supported drivers section with dedicated code examples for each. [[1]](diffhunk://#diff-d49f5bc3a34b11a6ccb82cc54675b06a7dea5f0a943ae91c4ca0d28bd5003299R12-R24) [[2]](diffhunk://#diff-d49f5bc3a34b11a6ccb82cc54675b06a7dea5f0a943ae91c4ca0d28bd5003299L46-R80) **MariaDB Driver Enhancements** * Implemented a MariaDB-specific `TableFields` method and SQL query in the new driver, improving the accuracy of table field retrieval for MariaDB databases. * Added unit test initialization code for MariaDB to ensure driver functionality. **Deprecation and Refactoring** * Marked the MariaDB-specific logic and SQL in the MySQL driver as deprecated, with a note to remove it in the next version, directing users to the new MariaDB driver instead. [[1]](diffhunk://#diff-9892cdfb158af82d92f3bfe9e418011bd47a0596638428e61c70993dd72b9c47R18-R20) [[2]](diffhunk://#diff-9892cdfb158af82d92f3bfe9e418011bd47a0596638428e61c70993dd72b9c47R74-R75) --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Lance Add <1196661499@qq.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
152 lines
3.1 KiB
Markdown
152 lines
3.1 KiB
Markdown
|
|
# Database drivers
|
|
|
|
Powerful database drivers for package gdb.
|
|
|
|
## Installation
|
|
|
|
Let's take `mysql` for example.
|
|
|
|
```shell
|
|
go get github.com/gogf/gf/contrib/drivers/mysql/v2@latest
|
|
|
|
# Easy for copying:
|
|
go get github.com/gogf/gf/contrib/drivers/clickhouse/v2@latest
|
|
go get github.com/gogf/gf/contrib/drivers/dm/v2@latest
|
|
go get github.com/gogf/gf/contrib/drivers/gaussdb/v2@latest
|
|
go get github.com/gogf/gf/contrib/drivers/mariadb/v2@latest
|
|
go get github.com/gogf/gf/contrib/drivers/mssql/v2@latest
|
|
go get github.com/gogf/gf/contrib/drivers/oceanbase/v2@latest
|
|
go get github.com/gogf/gf/contrib/drivers/oracle/v2@latest
|
|
go get github.com/gogf/gf/contrib/drivers/pgsql/v2@latest
|
|
go get github.com/gogf/gf/contrib/drivers/sqlite/v2@latest
|
|
go get github.com/gogf/gf/contrib/drivers/sqlitecgo/v2@latest
|
|
go get github.com/gogf/gf/contrib/drivers/tidb/v2@latest
|
|
```
|
|
|
|
Choose and import the driver to your project:
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
|
```
|
|
|
|
Commonly imported at top of `main.go`:
|
|
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
|
|
|
// Other imported packages.
|
|
)
|
|
|
|
func main() {
|
|
// Main logics.
|
|
}
|
|
```
|
|
|
|
## Supported Drivers
|
|
|
|
### MySQL
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
|
```
|
|
|
|
### MariaDB
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/mariadb/v2"
|
|
```
|
|
|
|
### TiDB
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/tidb/v2"
|
|
```
|
|
|
|
### OceanBase
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/oceanbase/v2"
|
|
```
|
|
|
|
### GaussDB
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/gaussdb/v2"
|
|
```
|
|
|
|
### SQLite
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
|
|
```
|
|
|
|
#### cgo version
|
|
|
|
When the target is a `32-bit` Windows system, the `cgo` version needs to be used.
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/sqlitecgo/v2"
|
|
```
|
|
|
|
### PostgreSQL
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
|
|
```
|
|
|
|
### SQL Server
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/mssql/v2"
|
|
```
|
|
|
|
Note:
|
|
|
|
- `InsertIgnore` returns error if there is no primary key or unique index submitted with record.
|
|
- It supports server version >= `SQL Server2005`
|
|
- It ONLY supports `datetime2` and `datetimeoffset` types for auto handling created_at/updated_at/deleted_at columns,
|
|
because datetime type does not support microseconds precision when column value is passed as string.
|
|
|
|
### Oracle
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/oracle/v2"
|
|
```
|
|
|
|
Note:
|
|
|
|
- It does not support `LastInsertId`.
|
|
- `InsertIgnore` returns error if there is no primary key or unique index submitted with record.
|
|
|
|
### ClickHouse
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
|
|
```
|
|
|
|
Note:
|
|
|
|
- It does not support `InsertIgnore/InsertAndGetId` features.
|
|
- It does not support `Save/Replace` features.
|
|
- It does not support `Transaction` feature.
|
|
- It does not support `RowsAffected` feature.
|
|
|
|
### DM
|
|
|
|
```go
|
|
import _ "github.com/gogf/gf/contrib/drivers/dm/v2"
|
|
```
|
|
|
|
Note:
|
|
|
|
- `InsertIgnore` returns error if there is no primary key or unique index submitted with record.
|
|
|
|
## Custom Drivers
|
|
|
|
It's quick and easy, please refer to current driver source.
|
|
It's quite appreciated if any PR for new drivers support into current repo.
|