Skip to content

Commit

Permalink
added support for table specific column exclusion. #38
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicola Paro committed Jan 24, 2024
1 parent aba1053 commit 6d6339e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/DatabaseGpt.Npgsql/NpgsqlDatabaseGptProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ public async Task<string> GetCreateTablesScriptAsync(IEnumerable<string> tables,
CASE WHEN CHARACTER_MAXIMUM_LENGTH = -1 THEN 'MAX' ELSE CAST(CHARACTER_MAXIMUM_LENGTH AS VARCHAR(10)) END || ')','') || ' ' ||
CASE WHEN IS_NULLABLE = 'YES' THEN 'NULL' ELSE 'NOT NULL' END
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = @schema AND TABLE_NAME = @table AND COLUMN_NAME NOT IN (SELECT UNNEST(@excludedColumns));
WHERE TABLE_SCHEMA = @schema
AND TABLE_NAME = @table
AND COLUMN_NAME NOT IN (SELECT UNNEST(@excludedColumns))
AND TABLE_SCHEMA || '.' || TABLE_NAME || '.' || COLUMN_NAME NOT IN (SELECT UNNEST(@excludedColumns));
""";

var columns = await connection.QueryAsync<string>(query, new { schema = table.Schema, table = table.Name, ExcludedColumns = excludedColumns });
var columns = await connection.QueryAsync<string>(query, new { schema = table.Schema, table = table.Name, excludedColumns });
result.AppendLine($"CREATE TABLE [{table.Schema}].[{table.Name}] ({string.Join(", ", columns)});");
}

Expand Down

0 comments on commit 6d6339e

Please sign in to comment.