1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-09 19:54:25 +00:00
gitea/vendor/github.com/go-xorm/tidb/tidb_driver.go

49 lines
960 B
Go
Raw Normal View History

// Copyright 2015 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tidb
import (
"errors"
"net/url"
"path/filepath"
"github.com/go-xorm/core"
)
var (
_ core.Dialect = (*tidb)(nil)
DBType core.DbType = "tidb"
)
func init() {
core.RegisterDriver(string(DBType), &tidbDriver{})
core.RegisterDialect(DBType, func() core.Dialect {
return &tidb{}
})
}
type tidbDriver struct {
}
func (p *tidbDriver) Parse(driverName, dataSourceName string) (*core.Uri, error) {
u, err := url.Parse(dataSourceName)
if err != nil {
return nil, err
}
if u.Scheme != "goleveldb" && u.Scheme != "memory" && u.Scheme != "boltdb" {
return nil, errors.New(u.Scheme + " is not supported yet.")
}
path := filepath.Join(u.Host, u.Path)
dbName := filepath.Clean(filepath.Base(path))
uri := &core.Uri{
DbType: DBType,
DbName: dbName,
}
return uri, nil
}