From a026aeb790ea8669e812bb10a6c96b8ed93d9db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Thu, 24 Nov 2022 11:34:08 +0100 Subject: [PATCH] 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. --- .../templates/gocode/store/rdbms/rdbms.go.tpl | 2 +- server/store/adapters/rdbms/dal/model.go | 4 +-- server/store/adapters/rdbms/filter.go | 14 ++++---- server/store/adapters/rdbms/rdbms.gen.go | 34 +++++++++---------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/server/codegen/assets/templates/gocode/store/rdbms/rdbms.go.tpl b/server/codegen/assets/templates/gocode/store/rdbms/rdbms.go.tpl index afb6889ce..53b3d1150 100644 --- a/server/codegen/assets/templates/gocode/store/rdbms/rdbms.go.tpl +++ b/server/codegen/assets/templates/gocode/store/rdbms/rdbms.go.tpl @@ -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) ) diff --git a/server/store/adapters/rdbms/dal/model.go b/server/store/adapters/rdbms/dal/model.go index fe0b449e9..18534343c 100644 --- a/server/store/adapters/rdbms/dal/model.go +++ b/server/store/adapters/rdbms/dal/model.go @@ -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)) } } diff --git a/server/store/adapters/rdbms/filter.go b/server/store/adapters/rdbms/filter.go index 2de146f6f..613a2ce16 100644 --- a/server/store/adapters/rdbms/filter.go +++ b/server/store/adapters/rdbms/filter.go @@ -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)) } } diff --git a/server/store/adapters/rdbms/rdbms.gen.go b/server/store/adapters/rdbms/rdbms.gen.go index 51d9461f2..f1cdb76e0 100644 --- a/server/store/adapters/rdbms/rdbms.gen.go +++ b/server/store/adapters/rdbms/rdbms.gen.go @@ -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) )