-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
1,734 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using Microsoft.Extensions.FileSystemGlobbing.Internal; | ||
using Norm; | ||
|
||
namespace PgRoutiner.Builder; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,76 @@ | ||
using System.Data; | ||
using Norm; | ||
using PgRoutiner.DataAccess.Models; | ||
|
||
namespace PgRoutiner.DataAccess; | ||
|
||
|
||
public static partial class DataAccessConnectionExtensions | ||
{ | ||
|
||
public static IEnumerable<PgItem> FilterTypes(this NpgsqlConnection connection, List<PgItem> types, Current settings, string skipSimilar = null) | ||
{ | ||
if (!types.Any()) | ||
{ | ||
return Enumerable.Empty<PgItem>(); | ||
} | ||
return connection | ||
.WithParameters( | ||
(settings.SchemaSimilarTo, DbType.AnsiString), | ||
(settings.SchemaNotSimilarTo, DbType.AnsiString), | ||
(skipSimilar, DbType.AnsiString)) | ||
.Read<(string Schema, string Name)>(@$" | ||
select | ||
schema, name | ||
from | ||
( | ||
{string.Join(" union all ", types.Select(t => $"select '{t.Schema}' as schema, '{t.Name}' as name"))} | ||
) sub | ||
where | ||
( $1 is null or (sub.schema similar to $1) ) | ||
and ( $2 is null or sub.schema not similar to $2 ) | ||
and ( {GetSchemaExpression("sub.schema")} ) | ||
and ( $3 is null or (sub.name not similar to $3) ) | ||
|
||
return connection.Read<(string Schema, string Name)>( | ||
[ | ||
(settings.SchemaSimilarTo, DbType.AnsiString, null), | ||
(settings.SchemaNotSimilarTo, DbType.AnsiString, null), | ||
(skipSimilar, DbType.AnsiString, null) | ||
], | ||
@$" | ||
select | ||
schema, name | ||
from | ||
( | ||
{string.Join(" union all ", types.Select(t => $"select '{t.Schema}' as schema, '{t.Name}' as name"))} | ||
) sub | ||
where | ||
( $1 is null or (sub.schema similar to $1) ) | ||
and ( $2 is null or sub.schema not similar to $2 ) | ||
and ( {GetSchemaExpression("sub.schema")} ) | ||
and ( $3 is null or (sub.name not similar to $3) ) | ||
") | ||
.Select(t => new PgItem | ||
{ | ||
Schema = t.Schema, | ||
Name = t.Name, | ||
TypeName = "TYPE", | ||
Type = PgType.Type | ||
}); | ||
", r => (r.Val<string>(0), r.Val<string>(1)) | ||
).Select(t => new PgItem | ||
{ | ||
Schema = t.Schema, | ||
Name = t.Name, | ||
TypeName = "TYPE", | ||
Type = PgType.Type | ||
}); | ||
|
||
//return connection | ||
// .WithParameters( | ||
// (settings.SchemaSimilarTo, DbType.AnsiString), | ||
// (settings.SchemaNotSimilarTo, DbType.AnsiString), | ||
// (skipSimilar, DbType.AnsiString)) | ||
// .Read<(string Schema, string Name)>(@$" | ||
|
||
// select | ||
// schema, name | ||
// from | ||
// ( | ||
// {string.Join(" union all ", types.Select(t => $"select '{t.Schema}' as schema, '{t.Name}' as name"))} | ||
// ) sub | ||
|
||
// where | ||
// ( $1 is null or (sub.schema similar to $1) ) | ||
// and ( $2 is null or sub.schema not similar to $2 ) | ||
// and ( {GetSchemaExpression("sub.schema")} ) | ||
// and ( $3 is null or (sub.name not similar to $3) ) | ||
|
||
// ") | ||
// .Select(t => new PgItem | ||
// { | ||
// Schema = t.Schema, | ||
// Name = t.Name, | ||
// TypeName = "TYPE", | ||
// Type = PgType.Type | ||
// }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,48 @@ | ||
using Norm; | ||
|
||
namespace PgRoutiner.DataAccess; | ||
namespace PgRoutiner.DataAccess; | ||
|
||
public static partial class DataAccessConnectionExtensions | ||
{ | ||
public static IEnumerable<(string schema, string name, string[] values, string comment)> GetAllEnums(this NpgsqlConnection connection) | ||
{ | ||
return connection.Read<(string schema, string name, string[] values, string comment)>(@$" | ||
|
||
select | ||
ns.nspname, | ||
t.typname as name, | ||
array_agg(e.enumlabel order by e.enumsortorder) as values, | ||
pgdesc.description as comment | ||
from | ||
pg_type t | ||
inner join pg_enum e on t.oid = e.enumtypid | ||
inner join pg_namespace ns on t.typnamespace = ns.oid | ||
left outer join pg_catalog.pg_description pgdesc on t.oid = pgdesc.objoid | ||
group by | ||
ns.nspname, | ||
t.typname, | ||
pgdesc.description | ||
return connection.Read<(string schema, string name, string[] values, string comment)>( | ||
[ | ||
], | ||
@$" | ||
select | ||
ns.nspname, | ||
t.typname as name, | ||
array_agg(e.enumlabel order by e.enumsortorder) as values, | ||
pgdesc.description as comment | ||
from | ||
pg_type t | ||
inner join pg_enum e on t.oid = e.enumtypid | ||
inner join pg_namespace ns on t.typnamespace = ns.oid | ||
left outer join pg_catalog.pg_description pgdesc on t.oid = pgdesc.objoid | ||
group by | ||
ns.nspname, | ||
t.typname, | ||
pgdesc.description | ||
", | ||
r => (r.Val<string>(0), r.Val<string>(1), r.Val<string[]>(2), r.Val<string>(3))); | ||
|
||
//return connection.Read<(string schema, string name, string[] values, string comment)>(@$" | ||
|
||
// select | ||
// ns.nspname, | ||
// t.typname as name, | ||
// array_agg(e.enumlabel order by e.enumsortorder) as values, | ||
// pgdesc.description as comment | ||
// from | ||
// pg_type t | ||
// inner join pg_enum e on t.oid = e.enumtypid | ||
// inner join pg_namespace ns on t.typnamespace = ns.oid | ||
// left outer join pg_catalog.pg_description pgdesc on t.oid = pgdesc.objoid | ||
// group by | ||
// ns.nspname, | ||
// t.typname, | ||
// pgdesc.description | ||
|
||
"); | ||
// "); | ||
} | ||
} |
Oops, something went wrong.