mirror of
https://github.com/zitadel/zitadel.git
synced 2025-06-08 04:28:33 +00:00
cleanup
This commit is contained in:
parent
1a530953a7
commit
477cb4ad79
@ -1,7 +1,6 @@
|
|||||||
package crdb
|
package crdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -299,7 +298,7 @@ func NewTextArrayContainsCond(column string, value string) handler.Condition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not is a function instead of a method, so that calling it is well readable
|
// Not is a function and not a method, so that calling it is well readable
|
||||||
// For example conditions := []handler.Condition{ Not(NewTextArrayContainsCond())}
|
// For example conditions := []handler.Condition{ Not(NewTextArrayContainsCond())}
|
||||||
func Not(condition handler.Condition) handler.Condition {
|
func Not(condition handler.Condition) handler.Condition {
|
||||||
return func(param string) (string, interface{}) {
|
return func(param string) (string, interface{}) {
|
||||||
@ -412,7 +411,7 @@ func conditionsToWhere(conditions []handler.Condition, paramOffset int) (wheres
|
|||||||
values = make([]interface{}, 0, len(conditions))
|
values = make([]interface{}, 0, len(conditions))
|
||||||
for i, conditionFunc := range conditions {
|
for i, conditionFunc := range conditions {
|
||||||
condition, value := conditionFunc("$" + strconv.Itoa(i+1+paramOffset))
|
condition, value := conditionFunc("$" + strconv.Itoa(i+1+paramOffset))
|
||||||
wheres[i] = fmt.Sprintf("(%s)", condition)
|
wheres[i] = "(" + condition + ")"
|
||||||
if value != nil {
|
if value != nil {
|
||||||
values = append(values, value)
|
values = append(values, value)
|
||||||
}
|
}
|
||||||
|
@ -420,7 +420,9 @@ func TestNewUpdateStatement(t *testing.T) {
|
|||||||
Value: "val",
|
Value: "val",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
conditions: []handler.Condition{handler.NewCond("col2", 1)},
|
conditions: []handler.Condition{
|
||||||
|
handler.NewCond("col2", 1),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
table: "",
|
table: "",
|
||||||
@ -445,7 +447,9 @@ func TestNewUpdateStatement(t *testing.T) {
|
|||||||
previousSequence: 0,
|
previousSequence: 0,
|
||||||
},
|
},
|
||||||
values: []handler.Column{},
|
values: []handler.Column{},
|
||||||
conditions: []handler.Condition{handler.NewCond("col2", 1)},
|
conditions: []handler.Condition{
|
||||||
|
handler.NewCond("col2", 1),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
table: "my_table",
|
table: "my_table",
|
||||||
@ -505,7 +509,9 @@ func TestNewUpdateStatement(t *testing.T) {
|
|||||||
Value: "val",
|
Value: "val",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
conditions: []handler.Condition{handler.NewCond("col2", 1)},
|
conditions: []handler.Condition{
|
||||||
|
handler.NewCond("col2", 1),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
table: "my_table",
|
table: "my_table",
|
||||||
@ -545,7 +551,9 @@ func TestNewUpdateStatement(t *testing.T) {
|
|||||||
Value: "val5",
|
Value: "val5",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
conditions: []handler.Condition{handler.NewCond("col2", 1)},
|
conditions: []handler.Condition{
|
||||||
|
handler.NewCond("col2", 1),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
table: "my_table",
|
table: "my_table",
|
||||||
@ -610,7 +618,9 @@ func TestNewDeleteStatement(t *testing.T) {
|
|||||||
sequence: 1,
|
sequence: 1,
|
||||||
previousSequence: 0,
|
previousSequence: 0,
|
||||||
},
|
},
|
||||||
conditions: []handler.Condition{handler.NewCond("col2", 1)},
|
conditions: []handler.Condition{
|
||||||
|
handler.NewCond("col2", 1),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
table: "",
|
table: "",
|
||||||
@ -658,7 +668,9 @@ func TestNewDeleteStatement(t *testing.T) {
|
|||||||
previousSequence: 0,
|
previousSequence: 0,
|
||||||
aggregateType: "agg",
|
aggregateType: "agg",
|
||||||
},
|
},
|
||||||
conditions: []handler.Condition{handler.NewCond("col1", 1)},
|
conditions: []handler.Condition{
|
||||||
|
handler.NewCond("col1", 1),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
table: "my_table",
|
table: "my_table",
|
||||||
@ -812,7 +824,9 @@ func TestNewMultiStatement(t *testing.T) {
|
|||||||
},
|
},
|
||||||
execs: []func(eventstore.Event) Exec{
|
execs: []func(eventstore.Event) Exec{
|
||||||
AddDeleteStatement(
|
AddDeleteStatement(
|
||||||
[]handler.Condition{handler.NewCond("col1", 1)},
|
[]handler.Condition{
|
||||||
|
handler.NewCond("col1", 1),
|
||||||
|
},
|
||||||
),
|
),
|
||||||
AddCreateStatement(
|
AddCreateStatement(
|
||||||
[]handler.Column{
|
[]handler.Column{
|
||||||
@ -842,7 +856,9 @@ func TestNewMultiStatement(t *testing.T) {
|
|||||||
Value: 1,
|
Value: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[]handler.Condition{handler.NewCond("col1", 1)},
|
[]handler.Condition{
|
||||||
|
handler.NewCond("col1", 1),
|
||||||
|
},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -929,10 +945,12 @@ func TestNewCopyStatement(t *testing.T) {
|
|||||||
sequence: 1,
|
sequence: 1,
|
||||||
previousSequence: 0,
|
previousSequence: 0,
|
||||||
},
|
},
|
||||||
conds: []handler.Column{{
|
conds: []handler.Column{
|
||||||
Name: "col1",
|
{
|
||||||
|
Name: "col2",
|
||||||
Value: 1,
|
Value: 1,
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
table: "",
|
table: "",
|
||||||
@ -1027,9 +1045,11 @@ func TestNewCopyStatement(t *testing.T) {
|
|||||||
sequence: 1,
|
sequence: 1,
|
||||||
previousSequence: 0,
|
previousSequence: 0,
|
||||||
},
|
},
|
||||||
conds: []handler.Column{{
|
conds: []handler.Column{
|
||||||
Name: "col1",
|
{
|
||||||
}},
|
Name: "col",
|
||||||
|
},
|
||||||
|
},
|
||||||
from: []handler.Column{},
|
from: []handler.Column{},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
@ -1354,7 +1374,7 @@ func Test_columnsToQuery(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_columnsToWhere(t *testing.T) {
|
func Test_conditionsToWhere(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
conds []handler.Condition
|
conds []handler.Condition
|
||||||
paramOffset int
|
paramOffset int
|
||||||
@ -1379,7 +1399,9 @@ func Test_columnsToWhere(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "no offset",
|
name: "no offset",
|
||||||
args: args{
|
args: args{
|
||||||
conds: []handler.Condition{handler.NewCond("col1", "val1")},
|
conds: []handler.Condition{
|
||||||
|
handler.NewCond("col1", "val1"),
|
||||||
|
},
|
||||||
paramOffset: 0,
|
paramOffset: 0,
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
@ -1404,7 +1426,9 @@ func Test_columnsToWhere(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "2 offset",
|
name: "2 offset",
|
||||||
args: args{
|
args: args{
|
||||||
conds: []handler.Condition{handler.NewCond("col1", "val1")},
|
conds: []handler.Condition{
|
||||||
|
handler.NewCond("col1", "val1"),
|
||||||
|
},
|
||||||
paramOffset: 2,
|
paramOffset: 2,
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
@ -1415,7 +1439,9 @@ func Test_columnsToWhere(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "less than",
|
name: "less than",
|
||||||
args: args{
|
args: args{
|
||||||
conds: []handler.Condition{NewLessThanCond("col1", "val1")},
|
conds: []handler.Condition{
|
||||||
|
NewLessThanCond("col1", "val1"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
wheres: []string{"(col1 < $1)"},
|
wheres: []string{"(col1 < $1)"},
|
||||||
@ -1425,7 +1451,9 @@ func Test_columnsToWhere(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "is null",
|
name: "is null",
|
||||||
args: args{
|
args: args{
|
||||||
conds: []handler.Condition{NewIsNullCond("col1")},
|
conds: []handler.Condition{
|
||||||
|
NewIsNullCond("col1"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
wheres: []string{"(col1 IS NULL)"},
|
wheres: []string{"(col1 IS NULL)"},
|
||||||
@ -1435,7 +1463,9 @@ func Test_columnsToWhere(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "text array contains",
|
name: "text array contains",
|
||||||
args: args{
|
args: args{
|
||||||
conds: []handler.Condition{NewTextArrayContainsCond("col1", "val1")},
|
conds: []handler.Condition{
|
||||||
|
NewTextArrayContainsCond("col1", "val1"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
wheres: []string{"(col1 @> $1)"},
|
wheres: []string{"(col1 @> $1)"},
|
||||||
@ -1445,7 +1475,9 @@ func Test_columnsToWhere(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "not",
|
name: "not",
|
||||||
args: args{
|
args: args{
|
||||||
conds: []handler.Condition{Not(handler.NewCond("col1", "val1"))},
|
conds: []handler.Condition{
|
||||||
|
Not(handler.NewCond("col1", "val1")),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
want: want{
|
want: want{
|
||||||
wheres: []string{"(NOT (col1 = $1))"},
|
wheres: []string{"(NOT (col1 = $1))"},
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/zitadel/logging"
|
"github.com/zitadel/logging"
|
||||||
|
|
||||||
@ -67,6 +66,6 @@ type Condition func(param string) (string, interface{})
|
|||||||
|
|
||||||
func NewCond(name string, value interface{}) Condition {
|
func NewCond(name string, value interface{}) Condition {
|
||||||
return func(param string) (string, interface{}) {
|
return func(param string) (string, interface{}) {
|
||||||
return fmt.Sprintf("%s = %s", name, param), value
|
return name + " = " + param, value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user