1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-27 23:18:34 +02:00

сделал ReplaceSchemaName()

This commit is contained in:
Nikitin Aleksandr
2025-01-20 15:28:58 +03:00
parent d04cdcf7e1
commit 474c59aed5
2 changed files with 19 additions and 0 deletions

View File

@@ -562,6 +562,15 @@ func ReplaceSchema(TextSQL string) string {
return Otvet
}
// ReplaceSchemaName - заменяет имя схемы в тексте SQL
func ReplaceSchemaName(TextSQL, SchemaNameFrom string) string {
Otvet := TextSQL
Otvet = strings.ReplaceAll(Otvet, SchemaNameFrom+".", Settings.DB_SCHEMA+".")
return Otvet
}
// ReplaceTemporaryTableNamesToUnique - заменяет "public.TableName" на "public.TableName_UUID"
func ReplaceTemporaryTableNamesToUnique(TextSQL string) string {
Otvet := TextSQL

View File

@@ -336,3 +336,13 @@ func TestSetSingularTableNames(t *testing.T) {
t.Errorf("Expected SingularTable to be %v, but got %v", IsSingular, NamingStrategy.SingularTable)
}
}
func TestReplaceSchemaName(t *testing.T) {
TextSQL := "SELECT * FROM public.users"
Settings.DB_SCHEMA = "myschema"
ExpectedSQL := "SELECT * FROM myschema.users"
ActualSQL := ReplaceSchemaName(TextSQL, "public")
if ActualSQL != ExpectedSQL {
t.Errorf("Expected %v, but got %v", ExpectedSQL, ActualSQL)
}
}