diff --git a/pkg/sqlite/gallery.go b/pkg/sqlite/gallery.go index ec9b7ae2e..9cfe38b1f 100644 --- a/pkg/sqlite/gallery.go +++ b/pkg/sqlite/gallery.go @@ -155,7 +155,7 @@ var ( }, fkColumn: "tag_id", foreignTable: tagTable, - orderBy: "COALESCE(tags.sort_name, tags.name) ASC", + orderBy: tagTableSortSQL, }, images: joinRepository{ repository: repository{ diff --git a/pkg/sqlite/gallery_test.go b/pkg/sqlite/gallery_test.go index be1edb687..06d7daf17 100644 --- a/pkg/sqlite/gallery_test.go +++ b/pkg/sqlite/gallery_test.go @@ -481,7 +481,7 @@ func Test_galleryQueryBuilder_UpdatePartial(t *testing.T) { CreatedAt: createdAt, UpdatedAt: updatedAt, SceneIDs: models.NewRelatedIDs([]int{sceneIDs[sceneIdxWithGallery]}), - TagIDs: models.NewRelatedIDs([]int{tagIDs[tagIdx1WithGallery], tagIDs[tagIdx1WithDupName]}), + TagIDs: models.NewRelatedIDs([]int{tagIDs[tagIdx1WithDupName], tagIDs[tagIdx1WithGallery]}), PerformerIDs: models.NewRelatedIDs([]int{performerIDs[performerIdx1WithGallery], performerIDs[performerIdx1WithDupName]}), }, false, diff --git a/pkg/sqlite/group.go b/pkg/sqlite/group.go index 7f0ff72ca..686bf4e1e 100644 --- a/pkg/sqlite/group.go +++ b/pkg/sqlite/group.go @@ -122,7 +122,7 @@ var ( }, fkColumn: tagIDColumn, foreignTable: tagTable, - orderBy: "COALESCE(tags.sort_name, tags.name) ASC", + orderBy: tagTableSortSQL, }, } ) diff --git a/pkg/sqlite/image.go b/pkg/sqlite/image.go index 840720c50..6575ebb91 100644 --- a/pkg/sqlite/image.go +++ b/pkg/sqlite/image.go @@ -177,7 +177,7 @@ var ( }, fkColumn: tagIDColumn, foreignTable: tagTable, - orderBy: "COALESCE(tags.sort_name, tags.name) ASC", + orderBy: tagTableSortSQL, }, } ) diff --git a/pkg/sqlite/performer.go b/pkg/sqlite/performer.go index bcb984ffd..1b1f103da 100644 --- a/pkg/sqlite/performer.go +++ b/pkg/sqlite/performer.go @@ -189,7 +189,7 @@ var ( }, fkColumn: tagIDColumn, foreignTable: tagTable, - orderBy: "COALESCE(tags.sort_name, tags.name) ASC", + orderBy: tagTableSortSQL, }, stashIDs: stashIDRepository{ repository{ diff --git a/pkg/sqlite/performer_test.go b/pkg/sqlite/performer_test.go index eb1dfbad2..d5d8ce2fa 100644 --- a/pkg/sqlite/performer_test.go +++ b/pkg/sqlite/performer_test.go @@ -282,7 +282,7 @@ func Test_PerformerStore_Update(t *testing.T) { Weight: &weight, IgnoreAutoTag: ignoreAutoTag, Aliases: models.NewRelatedStrings(aliases), - TagIDs: models.NewRelatedIDs([]int{tagIDs[tagIdx1WithPerformer], tagIDs[tagIdx1WithDupName]}), + TagIDs: models.NewRelatedIDs([]int{tagIDs[tagIdx1WithDupName], tagIDs[tagIdx1WithPerformer]}), StashIDs: models.NewRelatedStashIDs([]models.StashID{ { StashID: stashID1, @@ -516,7 +516,7 @@ func Test_PerformerStore_UpdatePartial(t *testing.T) { Weight: models.NewOptionalInt(weight), IgnoreAutoTag: models.NewOptionalBool(ignoreAutoTag), TagIDs: &models.UpdateIDs{ - IDs: []int{tagIDs[tagIdx1WithPerformer], tagIDs[tagIdx1WithDupName]}, + IDs: []int{tagIDs[tagIdx1WithDupName], tagIDs[tagIdx1WithPerformer]}, Mode: models.RelationshipUpdateModeSet, }, StashIDs: &models.UpdateStashIDs{ @@ -563,7 +563,7 @@ func Test_PerformerStore_UpdatePartial(t *testing.T) { HairColor: hairColor, Weight: &weight, IgnoreAutoTag: ignoreAutoTag, - TagIDs: models.NewRelatedIDs([]int{tagIDs[tagIdx1WithPerformer], tagIDs[tagIdx1WithDupName]}), + TagIDs: models.NewRelatedIDs([]int{tagIDs[tagIdx1WithDupName], tagIDs[tagIdx1WithPerformer]}), StashIDs: models.NewRelatedStashIDs([]models.StashID{ { StashID: stashID1, diff --git a/pkg/sqlite/scene.go b/pkg/sqlite/scene.go index c4a46b23c..0a7829f28 100644 --- a/pkg/sqlite/scene.go +++ b/pkg/sqlite/scene.go @@ -201,7 +201,7 @@ var ( }, fkColumn: tagIDColumn, foreignTable: tagTable, - orderBy: "COALESCE(tags.sort_name, tags.name) ASC", + orderBy: tagTableSortSQL, }, performers: joinRepository{ repository: repository{ diff --git a/pkg/sqlite/studio.go b/pkg/sqlite/studio.go index 9217fbcdb..7d93eee28 100644 --- a/pkg/sqlite/studio.go +++ b/pkg/sqlite/studio.go @@ -133,7 +133,7 @@ var ( }, fkColumn: tagIDColumn, foreignTable: tagTable, - orderBy: "COALESCE(tags.sort_name, tags.name) ASC", + orderBy: tagTableSortSQL, }, } ) diff --git a/pkg/sqlite/tables.go b/pkg/sqlite/tables.go index 8d798d913..35845d8f5 100644 --- a/pkg/sqlite/tables.go +++ b/pkg/sqlite/tables.go @@ -332,7 +332,8 @@ var ( } // formerly: goqu.COALESCE(tagTableMgr.table.Col("sort_name"), tagTableMgr.table.Col("name")).Asc() - tagTableSort = goqu.L("COALESCE(tags.sort_name, tags.name) COLLATE NATURAL_CI").Asc() + tagTableSort = goqu.L("COALESCE(tags.sort_name, tags.name) COLLATE NATURAL_CI").Asc() + tagTableSortSQL = "COALESCE(tags.sort_name, tags.name) COLLATE NATURAL_CI ASC" tagsAliasesTableMgr = &stringTable{ table: table{