You've already forked go-clickhouse
mirror of
https://github.com/uptrace/go-clickhouse.git
synced 2025-06-16 23:47:39 +02:00
fix: escape cluster name
This commit is contained in:
@ -31,6 +31,10 @@ func (f Formatter) AppendIdent(b []byte, ident string) []byte {
|
|||||||
return AppendIdent(b, ident)
|
return AppendIdent(b, ident)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f Formatter) AppendFQN(b []byte, ident string) []byte {
|
||||||
|
return AppendFQN(b, ident)
|
||||||
|
}
|
||||||
|
|
||||||
func (f Formatter) WithArg(arg NamedArgAppender) Formatter {
|
func (f Formatter) WithArg(arg NamedArgAppender) Formatter {
|
||||||
return Formatter{
|
return Formatter{
|
||||||
args: f.args.WithArg(arg),
|
args: f.args.WithArg(arg),
|
||||||
|
@ -34,7 +34,7 @@ type FQN string
|
|||||||
var _ QueryAppender = (*FQN)(nil)
|
var _ QueryAppender = (*FQN)(nil)
|
||||||
|
|
||||||
func (s FQN) AppendQuery(fmter Formatter, b []byte) ([]byte, error) {
|
func (s FQN) AppendQuery(fmter Formatter, b []byte) ([]byte, error) {
|
||||||
return fmter.AppendIdent(b, string(s)), nil
|
return fmter.AppendFQN(b, string(s)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AppendFQN(b []byte, field string) []byte {
|
func AppendFQN(b []byte, field string) []byte {
|
||||||
|
@ -69,8 +69,8 @@ func (q *CreateTableQuery) IfNotExists() *CreateTableQuery {
|
|||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *CreateTableQuery) OnCluster(query string, args ...any) *CreateTableQuery {
|
func (q *CreateTableQuery) OnCluster(cluster string) *CreateTableQuery {
|
||||||
q.onCluster = chschema.SafeQuery(query, args)
|
q.onCluster = chschema.UnsafeIdent(cluster)
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +57,8 @@ func (q *DropTableQuery) IfExists() *DropTableQuery {
|
|||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *DropTableQuery) OnCluster(query string, args ...any) *DropTableQuery {
|
func (q *DropTableQuery) OnCluster(cluster string) *DropTableQuery {
|
||||||
q.onCluster = chschema.SafeQuery(query, args)
|
q.onCluster = chschema.UnsafeIdent(cluster)
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ type CreateViewQuery struct {
|
|||||||
materialized bool
|
materialized bool
|
||||||
ifNotExists bool
|
ifNotExists bool
|
||||||
view chschema.QueryWithArgs
|
view chschema.QueryWithArgs
|
||||||
cluster chschema.QueryWithArgs
|
onCluster chschema.QueryWithArgs
|
||||||
to chschema.QueryWithArgs
|
to chschema.QueryWithArgs
|
||||||
where whereQuery
|
where whereQuery
|
||||||
group []chschema.QueryWithArgs
|
group []chschema.QueryWithArgs
|
||||||
@ -53,12 +53,12 @@ func (q *CreateViewQuery) ViewExpr(query string, args ...any) *CreateViewQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *CreateViewQuery) OnCluster(cluster string) *CreateViewQuery {
|
func (q *CreateViewQuery) OnCluster(cluster string) *CreateViewQuery {
|
||||||
q.cluster = chschema.UnsafeIdent(cluster)
|
q.onCluster = chschema.UnsafeIdent(cluster)
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *CreateViewQuery) OnClusterExpr(query string, args ...any) *CreateViewQuery {
|
func (q *CreateViewQuery) OnClusterExpr(query string, args ...any) *CreateViewQuery {
|
||||||
q.cluster = chschema.SafeQuery(query, args)
|
q.onCluster = chschema.SafeQuery(query, args)
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,9 +197,9 @@ func (q *CreateViewQuery) AppendQuery(fmter chschema.Formatter, b []byte) (_ []b
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !q.cluster.IsEmpty() {
|
if !q.onCluster.IsEmpty() {
|
||||||
b = append(b, " ON CLUSTER "...)
|
b = append(b, " ON CLUSTER "...)
|
||||||
b, err = q.cluster.AppendQuery(fmter, b)
|
b, err = q.onCluster.AppendQuery(fmter, b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ type DropViewQuery struct {
|
|||||||
|
|
||||||
ifExists bool
|
ifExists bool
|
||||||
view chschema.QueryWithArgs
|
view chschema.QueryWithArgs
|
||||||
cluster chschema.QueryWithArgs
|
onCluster chschema.QueryWithArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Query = (*DropViewQuery)(nil)
|
var _ Query = (*DropViewQuery)(nil)
|
||||||
@ -54,12 +54,12 @@ func (q *DropViewQuery) ViewExpr(query string, args ...any) *DropViewQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *DropViewQuery) OnCluster(cluster string) *DropViewQuery {
|
func (q *DropViewQuery) OnCluster(cluster string) *DropViewQuery {
|
||||||
q.cluster = chschema.UnsafeIdent(cluster)
|
q.onCluster = chschema.UnsafeIdent(cluster)
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *DropViewQuery) OnClusterExpr(query string, args ...any) *DropViewQuery {
|
func (q *DropViewQuery) OnClusterExpr(query string, args ...any) *DropViewQuery {
|
||||||
q.cluster = chschema.SafeQuery(query, args)
|
q.onCluster = chschema.SafeQuery(query, args)
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,9 +84,9 @@ func (q *DropViewQuery) AppendQuery(fmter chschema.Formatter, b []byte) (_ []byt
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !q.cluster.IsEmpty() {
|
if !q.onCluster.IsEmpty() {
|
||||||
b = append(b, " ON CLUSTER "...)
|
b = append(b, " ON CLUSTER "...)
|
||||||
b, err = q.cluster.AppendQuery(fmter, b)
|
b, err = q.onCluster.AppendQuery(fmter, b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func WithOnCluster(cluster string) MigratorOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithMarkAppliedOnSuccess sets the migrator to only mark migrations as applied/unapplied
|
// WithMarkAppliedOnSuccess sets the migrator to only mark migrations as applied/unapplied
|
||||||
// when their up/down is successful
|
// when their up/down is successful.
|
||||||
func WithMarkAppliedOnSuccess(enabled bool) MigratorOption {
|
func WithMarkAppliedOnSuccess(enabled bool) MigratorOption {
|
||||||
return func(m *Migrator) {
|
return func(m *Migrator) {
|
||||||
m.markAppliedOnSuccess = enabled
|
m.markAppliedOnSuccess = enabled
|
||||||
|
Reference in New Issue
Block a user