开始做clickhouse
This commit is contained in:
parent
0b563c8774
commit
d98469b30e
|
@ -0,0 +1,82 @@
|
|||
// Copyright 2020 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 dialects
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
|
||||
"xorm.io/xorm/core"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
type clickhouse struct {
|
||||
Base
|
||||
}
|
||||
|
||||
func (db *clickhouse) Init(uri *URI) error {
|
||||
return db.Base.Init(db, uri)
|
||||
}
|
||||
|
||||
func (db *clickhouse) IsReserved(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (db *clickhouse) SQLType(c *schemas.Column) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (db *clickhouse) SetQuotePolicy(quotePolicy QuotePolicy) {
|
||||
}
|
||||
|
||||
func (*clickhouse) AutoIncrStr() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (*clickhouse) CreateTableSQL(t *schemas.Table, tableName string) ([]string, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (*clickhouse) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (*clickhouse) Filters() []Filter {
|
||||
return []Filter{}
|
||||
}
|
||||
|
||||
func (*clickhouse) GetColumns(core.Queryer, context.Context, string) ([]string, map[string]*schemas.Column, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
func (db *clickhouse) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (db *clickhouse) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (db *clickhouse) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ParseClickHouse parsed clickhouse connection string
|
||||
// tcp://host1:9000?username=user&password=qwerty&database=clicks&read_timeout=10&write_timeout=20&alt_hosts=host2:9000,host3:9000
|
||||
func ParseClickHouse(connStr string) (*URI, error) {
|
||||
u, err := url.Parse(connStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
forms := u.Query()
|
||||
return &URI{
|
||||
DBType: schemas.CLICKHOUSE,
|
||||
Proto: u.Scheme,
|
||||
Host: u.Hostname(),
|
||||
Port: u.Port(),
|
||||
DBName: forms.Get("database"),
|
||||
User: forms.Get("username"),
|
||||
Passwd: forms.Get("password"),
|
||||
}, nil
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2020 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 dialects
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseClickHouse(t *testing.T) {
|
||||
uri, err := ParseClickHouse("tcp://122.224.233.66:9823?username=&password=&database=clicks&read_timeout=10&write_timeout=20&alt_hosts=host2:9000,host3:9000")
|
||||
assert.NoError(t, err)
|
||||
|
||||
//assert.EqualValues(t, &URI{
|
||||
// DBType: schemas.CLICKHOUSE,
|
||||
// Proto: "tcp",
|
||||
// Host: "host1",
|
||||
// Port: "9000",
|
||||
// DBName: "clicks",
|
||||
// User: "user",
|
||||
// Passwd: "qwerty",
|
||||
//}, uri)
|
||||
|
||||
println(uri)
|
||||
|
||||
}
|
|
@ -208,6 +208,7 @@ func regDrvsNDialects() bool {
|
|||
"sqlite3": {"sqlite3", func() Driver { return &sqlite3Driver{} }, func() Dialect { return &sqlite3{} }},
|
||||
"oci8": {"oracle", func() Driver { return &oci8Driver{} }, func() Dialect { return &oracle{} }},
|
||||
"goracle": {"oracle", func() Driver { return &goracleDriver{} }, func() Dialect { return &oracle{} }},
|
||||
"clickhouse": {"clickhouse", func() Driver { return &driverProxy{ParseClickHouse} }, func() Dialect { return &clickhouse{} }},
|
||||
}
|
||||
|
||||
for driverName, v := range providedDrvsNDialects {
|
||||
|
|
|
@ -55,3 +55,12 @@ func OpenDialect(driverName, connstr string) (Dialect, error) {
|
|||
|
||||
return dialect, nil
|
||||
}
|
||||
|
||||
|
||||
type driverProxy struct {
|
||||
parser func(connStr string) (*URI, error)
|
||||
}
|
||||
|
||||
func (p *driverProxy) Parse(driverName, dataSourceName string) (*URI, error) {
|
||||
return p.parser(dataSourceName)
|
||||
}
|
|
@ -19,6 +19,7 @@ const (
|
|||
MYSQL DBType = "mysql"
|
||||
MSSQL DBType = "mssql"
|
||||
ORACLE DBType = "oracle"
|
||||
CLICKHOUSE DBType = "clickhouse"
|
||||
)
|
||||
|
||||
// SQLType represents SQL types
|
||||
|
|
Loading…
Reference in New Issue