mirror of
https://gitee.com/johng/gf
synced 2026-06-26 17:35:40 +08:00
## Summary - Port 5 feature tests: duplicate-key handling (OnDuplicate/OnDuplicateEx/Save), JSON field operations, row-level locking (Lock/LockUpdate/LockShared with transactions), master-slave configuration, table metadata inspection - Port 1 partition test: RANGE partitioning with Partition() clause (adapted from MySQL baseline) - Port 30 issue regression tests from MySQL baseline - Includes 14 testdata SQL files for issue-specific table schemas Layer 3 tests cover MariaDB-specific adaptations where needed (e.g., SKIP LOCKED requires MariaDB 10.6+ — commented out for compatibility, LOCK IN SHARE MODE instead of FOR SHARE for older versions). All tests are structurally aligned with the MySQL driver baseline. Package and import references are adapted for MariaDB. ref #4689 Co-authored-by: John Guo <claymore1986@gmail.com>
Database drivers
Powerful database drivers for package gdb.
Installation
Let's take mysql for example.
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:
import _ "github.com/gogf/gf/contrib/drivers/mysql/v2"
Commonly imported at top of main.go:
package main
import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
// Other imported packages.
)
func main() {
// Main logics.
}
Supported Drivers
MySQL
import _ "github.com/gogf/gf/contrib/drivers/mysql/v2"
MariaDB
import _ "github.com/gogf/gf/contrib/drivers/mariadb/v2"
TiDB
import _ "github.com/gogf/gf/contrib/drivers/tidb/v2"
OceanBase
import _ "github.com/gogf/gf/contrib/drivers/oceanbase/v2"
GaussDB
import _ "github.com/gogf/gf/contrib/drivers/gaussdb/v2"
SQLite
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.
import _ "github.com/gogf/gf/contrib/drivers/sqlitecgo/v2"
PostgreSQL
import _ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
SQL Server
import _ "github.com/gogf/gf/contrib/drivers/mssql/v2"
Note:
InsertIgnorereturns error if there is no primary key or unique index submitted with record.- It supports server version >=
SQL Server2005 - It ONLY supports
datetime2anddatetimeoffsettypes 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
import _ "github.com/gogf/gf/contrib/drivers/oracle/v2"
Note:
- It does not support
LastInsertId. InsertIgnorereturns error if there is no primary key or unique index submitted with record.
ClickHouse
import _ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
Note:
- It does not support
InsertIgnore/InsertAndGetIdfeatures. - It does not support
Save/Replacefeatures. - It does not support
Transactionfeature. - It does not support
RowsAffectedfeature.
DM
import _ "github.com/gogf/gf/contrib/drivers/dm/v2"
Note:
InsertIgnorereturns 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.