mirror of
https://gitee.com/johng/gf.git
synced 2024-11-29 18:57:44 +08:00
56 lines
1.4 KiB
Go
56 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 mysql implements gdb.Driver, which supports operations for database MySQL.
|
|
package mysql
|
|
|
|
import (
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
// Driver is the driver for mysql database.
|
|
type Driver struct {
|
|
*gdb.Core
|
|
}
|
|
|
|
const (
|
|
quoteChar = "`"
|
|
)
|
|
|
|
func init() {
|
|
var (
|
|
err error
|
|
driverObj = New()
|
|
driverNames = g.SliceStr{"mysql", "mariadb", "tidb"}
|
|
)
|
|
for _, driverName := range driverNames {
|
|
if err = gdb.Register(driverName, driverObj); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// New create and returns a driver that implements gdb.Driver, which supports operations for MySQL.
|
|
func New() gdb.Driver {
|
|
return &Driver{}
|
|
}
|
|
|
|
// New creates and returns a database object for mysql.
|
|
// 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
|
|
}
|