Skip to content

Commit

Permalink
Refactored FilterPatterns type to Filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMarr committed Aug 22, 2023
1 parent a57c476 commit 7113df7
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/SqlHydra.Cli/Console.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let newConfigWizard (args: Args) =
Config.ProviderDbTypeAttributes = true
Config.TableDeclarations = true
Config.Readers = Some { ReadersConfig.ReaderType = app.DefaultReaderType }
Config.Filters = FilterPatterns.Empty // User must manually configure filter in .toml file
Config.Filters = Filters.Empty // User must manually configure filter in .toml file
}
| OtherDataLibrary ->
{
Expand All @@ -79,7 +79,7 @@ let newConfigWizard (args: Args) =
Config.ProviderDbTypeAttributes = false
Config.TableDeclarations = false
Config.Readers = None
Config.Filters = FilterPatterns.Empty // User must manually configure filter in .toml file
Config.Filters = Filters.Empty // User must manually configure filter in .toml file
}
| Standalone ->
{
Expand All @@ -90,7 +90,7 @@ let newConfigWizard (args: Args) =
Config.ProviderDbTypeAttributes = false
Config.TableDeclarations = false
Config.Readers = Some { ReadersConfig.ReaderType = app.DefaultReaderType }
Config.Filters = FilterPatterns.Empty // User must manually configure filter in .toml file
Config.Filters = Filters.Empty // User must manually configure filter in .toml file
}

AnsiConsole.MarkupLine($"[green]-[/] {args.TomlFile.Name} has been created!")
Expand Down
6 changes: 4 additions & 2 deletions src/SqlHydra.Cli/SchemaFilters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module SqlHydra.SchemaFilters
open GlobExpressions
open SqlHydra.Domain

let inline filterTables (filters: FilterPatterns) (tables: 'Table seq when 'Table : (member Schema: string) and 'Table : (member Name: string)) =
/// Applies glob include and exclude patterns to filter schemas and tables.
let inline filterTables (filters: Filters) (tables: 'Table seq when 'Table : (member Schema: string) and 'Table : (member Name: string)) =
let isTableFilter (filter: string) = not (filter.Contains ".")
let includeFilters = filters.Includes |> List.filter isTableFilter
let excludeFilters = filters.Excludes |> List.filter isTableFilter
Expand All @@ -29,7 +30,8 @@ let inline filterTables (filters: FilterPatterns) (tables: 'Table seq when 'Tabl
let filteredTables = filteredPaths |> Seq.map (fun path -> tablesByPath.[path]) |> Seq.toList
filteredTables

let inline filterColumns (filters: FilterPatterns) (schema: string) (table: string) (columns: Column seq when 'Column : (member Name: string)) =
/// Applies glob include and exclude patterns to filter columns.
let inline filterColumns (filters: Filters) (schema: string) (table: string) (columns: Column seq when 'Column : (member Name: string)) =
let isColumnFilter (filter: string) = filter.Contains "."
let includeFilters = filters.Includes |> List.filter isColumnFilter
let excludeFilters = filters.Excludes |> List.filter isColumnFilter
Expand Down
8 changes: 4 additions & 4 deletions src/SqlHydra.Cli/TomlConfigParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ let read(toml: string) =
match filtersTableMaybe with
| Some filtersTable ->
{
FilterPatterns.Includes = filtersTable.Get "include" |> Seq.cast<string> |> Seq.toList
FilterPatterns.Excludes = filtersTable.Get "exclude" |> Seq.cast<string> |> Seq.toList
FilterPatterns.Restrictions =
Filters.Includes = filtersTable.Get "include" |> Seq.cast<string> |> Seq.toList
Filters.Excludes = filtersTable.Get "exclude" |> Seq.cast<string> |> Seq.toList
Filters.Restrictions =
match filtersTable.TryGet<TomlTable> "restrictions" with
| Some restrictions ->
restrictions
Expand All @@ -71,7 +71,7 @@ let read(toml: string) =
Map.empty
}
| None ->
FilterPatterns.Empty
Filters.Empty
}

/// Saves a Config to .toml file.
Expand Down
9 changes: 5 additions & 4 deletions src/SqlHydra.Domain/Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ type ReadersConfig =
ReaderType: string
}

type FilterPatterns =
type Filters =
{
/// Glob patterns to include "{schema}/{table}.{column}"
Includes: string list
Excludes: string list

/// Glob patterns to exclude "{schema}/{table}.{column}"
Excludes: string list
/// Restrictions applied to GetSchema() calls. Ex: Map [ "Tables", [| "dbo" |]; "Views", [||]; "Columns", [||] ]
Restrictions: Map<string, string array>
}
Expand Down Expand Up @@ -112,5 +113,5 @@ type Config =
Readers: ReadersConfig option

/// Filters: optional filters for schemas, tables and columns
Filters: FilterPatterns
Filters: Filters
}
2 changes: 1 addition & 1 deletion src/Tests/Npgsql/Generation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let cfg =
ProviderDbTypeAttributes = true
TableDeclarations = false
Readers = Some { ReadersConfig.ReaderType = AppInfo.info.DefaultReaderType }
Filters = FilterPatterns.Empty
Filters = Filters.Empty
}

[<Tests>]
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/SqlServer/Generation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let cfg =
ProviderDbTypeAttributes = true
TableDeclarations = false
Readers = Some { ReadersConfig.ReaderType = "Microsoft.Data.SqlClient.SqlDataReader" }
Filters = FilterPatterns.Empty
Filters = Filters.Empty
}

[<Tests>]
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Sqlite/Generation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let cfg =
ProviderDbTypeAttributes = true
TableDeclarations = false
Readers = Some { ReadersConfig.ReaderType = "System.Data.Common.DbDataReader" }
Filters = FilterPatterns.Empty
Filters = Filters.Empty
}

[<Tests>]
Expand Down
6 changes: 3 additions & 3 deletions src/Tests/UnitTests/TomlConfigParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let tests =
Config.ProviderDbTypeAttributes = true
Config.TableDeclarations = true
Config.Readers = Some { ReadersConfig.ReaderType = "Microsoft.Data.SqlClient.SqlDataReader" }
Config.Filters = FilterPatterns.Empty
Config.Filters = Filters.Empty
}

let toml = TomlConfigParser.save(cfg)
Expand Down Expand Up @@ -69,7 +69,7 @@ let tests =
Config.ProviderDbTypeAttributes = true
Config.TableDeclarations = false
Config.Readers = Some { ReadersConfig.ReaderType = "Microsoft.Data.SqlClient.SqlDataReader" }
Config.Filters = FilterPatterns.Empty
Config.Filters = Filters.Empty
}

let cfg = TomlConfigParser.read(toml)
Expand All @@ -96,7 +96,7 @@ let tests =
Config.ProviderDbTypeAttributes = true
Config.TableDeclarations = false
Config.Readers = None
Config.Filters = FilterPatterns.Empty
Config.Filters = Filters.Empty
}

let cfg = TomlConfigParser.read(toml)
Expand Down

0 comments on commit 7113df7

Please sign in to comment.