mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-27 23:18:34 +02:00
сделал ReplaceSchemaName()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user