github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/go-xorm/tidb/tidb_driver.go (about) 1 // Copyright 2015 The Xorm Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package tidb 6 7 import ( 8 "errors" 9 "net/url" 10 "path/filepath" 11 12 "github.com/insionng/yougam/libraries/go-xorm/core" 13 ) 14 15 var ( 16 _ core.Dialect = (*tidb)(nil) 17 18 DBType core.DbType = "tidb" 19 ) 20 21 func init() { 22 core.RegisterDriver(string(DBType), &tidbDriver{}) 23 core.RegisterDialect(DBType, func() core.Dialect { 24 return &tidb{} 25 }) 26 } 27 28 type tidbDriver struct { 29 } 30 31 func (p *tidbDriver) Parse(driverName, dataSourceName string) (*core.Uri, error) { 32 u, err := url.Parse(dataSourceName) 33 if err != nil { 34 return nil, err 35 } 36 if u.Scheme != "goleveldb" && u.Scheme != "memory" && u.Scheme != "boltdb" { 37 return nil, errors.New(u.Scheme + " is not supported yet.") 38 } 39 path := filepath.Join(u.Host, u.Path) 40 dbName := filepath.Clean(filepath.Base(path)) 41 42 uri := &core.Uri{ 43 DbType: DBType, 44 DbName: dbName, 45 } 46 47 return uri, nil 48 }