3
0

Change state checks to use literal expressions

MSSQL doesn't like expressions in the lines of "column" IS @p1
which is how goqu generated the column.IsNull() part.
This commit is contained in:
Tomaž Jerman
2022-11-24 11:34:08 +01:00
committed by Jože Fortun
parent 878e5edddb
commit a026aeb790
4 changed files with 28 additions and 26 deletions
@@ -498,7 +498,7 @@ func (s *Store) Query{{ .expIdentPlural }}(
{{- end }}
{{- end }}
{{- range .nullConstraint }}
goqu.I({{ printf "%q" . }}).IsNull(),
stateNilComparison({{ printf "%q" . }}, filter.StateExcluded),
{{- end }}
).Limit(1)
)
+2 -2
View File
@@ -453,11 +453,11 @@ func (d *model) searchSql(f filter.Filter) *goqu.SelectDataset {
switch state {
case filter.StateExclusive:
// only not-null values
cnd = append(cnd, exp.NewBooleanExpression(exp.IsNotOp, attrExpr, nil))
cnd = append(cnd, exp.NewLiteralExpression("? IS NULL", attrExpr))
case filter.StateExcluded:
// exclude all non-null values
cnd = append(cnd, exp.NewBooleanExpression(exp.IsOp, attrExpr, nil))
cnd = append(cnd, exp.NewLiteralExpression("? IS NULL", attrExpr))
}
}
+8 -6
View File
@@ -158,15 +158,15 @@ func DefaultFilters() (f *extendedFilters) {
}
if f.ExcludeDismissed {
ee = append(ee, goqu.C("dismissed_at").IsNull())
ee = append(ee, stateNilComparison("dismissed_at", filter.StateExcluded))
}
if !f.IncludeDeleted {
ee = append(ee, goqu.C("deleted_at").IsNull())
ee = append(ee, stateNilComparison("deleted_at", filter.StateExcluded))
}
if f.ScheduledOnly {
ee = append(ee, goqu.C("remind_at").IsNotNull())
ee = append(ee, stateNilComparison("remind_at", filter.StateExclusive))
}
if f.Resource != "" {
@@ -320,7 +320,7 @@ func DefaultFilters() (f *extendedFilters) {
case filter.StateExcluded:
ee = append(ee, goqu.Or(
exp.NewBooleanExpression(exp.EqOp, expr, false),
exp.NewBooleanExpression(exp.IsOp, expr, nil),
exp.NewLiteralExpression("? IS NULL", expr),
))
case filter.StateExclusive:
ee = append(ee,
@@ -374,7 +374,8 @@ func stateNilComparison(lit string, fs filter.State) goqu.Expression {
switch fs {
case filter.StateExclusive:
// only not-null values
return goqu.Literal(lit).IsNotNull()
// @todo the NULL bit might be better of obtained from the dialect
return exp.NewLiteralExpression("? IS NOT NULL", goqu.Literal(lit))
case filter.StateInclusive:
// no filter
@@ -382,7 +383,8 @@ func stateNilComparison(lit string, fs filter.State) goqu.Expression {
default:
// exclude all non-null values
return goqu.Literal(lit).IsNull()
// @todo the NULL bit might be better of obtained from the dialect
return exp.NewLiteralExpression("? IS NULL", goqu.Literal(lit))
}
}
+17 -17
View File
@@ -3181,7 +3181,7 @@ func (s *Store) LookupAuthClientByHandle(ctx context.Context, handle string) (_
aux = new(auxAuthClient)
lookup = authClientSelectQuery(s.Dialect.GOQU()).Where(
s.Functions.LOWER(goqu.I("handle")).Eq(strings.ToLower(handle)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -6050,7 +6050,7 @@ func (s *Store) LookupAutomationWorkflowByHandle(ctx context.Context, handle str
aux = new(auxAutomationWorkflow)
lookup = automationWorkflowSelectQuery(s.Dialect.GOQU()).Where(
s.Functions.LOWER(goqu.I("handle")).Eq(strings.ToLower(handle)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -7230,7 +7230,7 @@ func (s *Store) LookupComposeChartByNamespaceIDHandle(ctx context.Context, names
lookup = composeChartSelectQuery(s.Dialect.GOQU()).Where(
goqu.I("rel_namespace").Eq(namespaceID),
s.Functions.LOWER(goqu.I("handle")).Eq(strings.ToLower(handle)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -7785,7 +7785,7 @@ func (s *Store) LookupComposeModuleByNamespaceIDHandle(ctx context.Context, name
lookup = composeModuleSelectQuery(s.Dialect.GOQU()).Where(
goqu.I("rel_namespace").Eq(namespaceID),
s.Functions.LOWER(goqu.I("handle")).Eq(strings.ToLower(handle)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -7827,7 +7827,7 @@ func (s *Store) LookupComposeModuleByNamespaceIDName(ctx context.Context, namesp
lookup = composeModuleSelectQuery(s.Dialect.GOQU()).Where(
goqu.I("rel_namespace").Eq(namespaceID),
goqu.I("name").Eq(name),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -8239,7 +8239,7 @@ func (s *Store) LookupComposeModuleFieldByModuleIDName(ctx context.Context, modu
lookup = composeModuleFieldSelectQuery(s.Dialect.GOQU()).Where(
goqu.I("rel_module").Eq(moduleID),
goqu.I("name").Eq(name),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -8870,7 +8870,7 @@ func (s *Store) LookupComposeNamespaceBySlug(ctx context.Context, slug string) (
aux = new(auxComposeNamespace)
lookup = composeNamespaceSelectQuery(s.Dialect.GOQU()).Where(
goqu.I("slug").Eq(slug),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -9493,7 +9493,7 @@ func (s *Store) LookupComposePageByNamespaceIDHandle(ctx context.Context, namesp
lookup = composePageSelectQuery(s.Dialect.GOQU()).Where(
goqu.I("rel_namespace").Eq(namespaceID),
s.Functions.LOWER(goqu.I("handle")).Eq(strings.ToLower(handle)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -9535,7 +9535,7 @@ func (s *Store) LookupComposePageByNamespaceIDModuleID(ctx context.Context, name
lookup = composePageSelectQuery(s.Dialect.GOQU()).Where(
goqu.I("rel_namespace").Eq(namespaceID),
goqu.I("rel_module").Eq(moduleID),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -10521,7 +10521,7 @@ func (s *Store) LookupDalConnectionByHandle(ctx context.Context, handle string)
aux = new(auxDalConnection)
lookup = dalConnectionSelectQuery(s.Dialect.GOQU()).Where(
s.Functions.LOWER(goqu.I("handle")).Eq(strings.ToLower(handle)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -18136,7 +18136,7 @@ func (s *Store) LookupReportByHandle(ctx context.Context, handle string) (_ *sys
aux = new(auxReport)
lookup = reportSelectQuery(s.Dialect.GOQU()).Where(
s.Functions.LOWER(goqu.I("handle")).Eq(strings.ToLower(handle)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -19573,7 +19573,7 @@ func (s *Store) LookupRoleByHandle(ctx context.Context, handle string) (_ *syste
aux = new(auxRole)
lookup = roleSelectQuery(s.Dialect.GOQU()).Where(
s.Functions.LOWER(goqu.I("handle")).Eq(strings.ToLower(handle)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -19616,7 +19616,7 @@ func (s *Store) LookupRoleByName(ctx context.Context, name string) (_ *systemTyp
aux = new(auxRole)
lookup = roleSelectQuery(s.Dialect.GOQU()).Where(
goqu.I("name").Eq(name),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -20892,7 +20892,7 @@ func (s *Store) LookupTemplateByHandle(ctx context.Context, handle string) (_ *s
aux = new(auxTemplate)
lookup = templateSelectQuery(s.Dialect.GOQU()).Where(
s.Functions.LOWER(goqu.I("handle")).Eq(strings.ToLower(handle)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -21527,7 +21527,7 @@ func (s *Store) LookupUserByEmail(ctx context.Context, email string) (_ *systemT
aux = new(auxUser)
lookup = userSelectQuery(s.Dialect.GOQU()).Where(
s.Functions.LOWER(goqu.I("email")).Eq(strings.ToLower(email)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -21570,7 +21570,7 @@ func (s *Store) LookupUserByHandle(ctx context.Context, handle string) (_ *syste
aux = new(auxUser)
lookup = userSelectQuery(s.Dialect.GOQU()).Where(
s.Functions.LOWER(goqu.I("handle")).Eq(strings.ToLower(handle)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)
@@ -21613,7 +21613,7 @@ func (s *Store) LookupUserByUsername(ctx context.Context, username string) (_ *s
aux = new(auxUser)
lookup = userSelectQuery(s.Dialect.GOQU()).Where(
s.Functions.LOWER(goqu.I("username")).Eq(strings.ToLower(username)),
goqu.I("deleted_at").IsNull(),
stateNilComparison("deleted_at", filter.StateExcluded),
).Limit(1)
)