/// <summary>
 ///
 /// </summary>
 /// <param name="table"></param>
 /// <param name="postgresTable"></param>
 /// <returns></returns>
 private List <UniqueKeyInfo> GetUniques(TableInfo table, PostgresTable postgresTable)
 {
     return(PostgresUniqueKeyManager
            .GetUniqueKeys(postgresTable)
            .Select(s => GetUnique(table, s))
            .ToList());
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sqlTable"></param>
        /// <returns></returns>
        public List <PostgresColumn> GetSqlColumns(PostgresTable sqlTable)
        {
            if (PostgresColumns == null)
            {
                return(new List <PostgresColumn>());
            }

            return(PostgresColumns.Where(w =>
                                         w.TableSchema == sqlTable.Schema &&
                                         w.TableName == sqlTable.Name).ToList());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="postgresTable"></param>
        /// <returns></returns>
        private TableInfo ConvertToTableInfo(PostgresTable postgresTable)
        {
            var table = new TableInfo();

            table.Schema     = postgresTable.Schema;
            table.Name       = postgresTable.Name;
            table.Columns    = GetColumns(table, postgresTable);
            table.PrimaryKey = GetPrimaryKeyInfo(table, postgresTable);
            table.UniqueKeys = GetUniques(table, postgresTable);

            return(table);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <param name="postgresTable"></param>
        /// <returns></returns>
        private PrimaryKeyInfo GetPrimaryKeyInfo(TableInfo table, PostgresTable postgresTable)
        {
            var sqlPrimaryKey = PostgresPrimaryKeyManager.GetPrimaryKey(postgresTable);

            if (sqlPrimaryKey == null)
            {
                return(null);
            }

            var primaryKey = new PrimaryKeyInfo();

            primaryKey.Name          = sqlPrimaryKey.ConstraintName;
            primaryKey.Table         = table;
            primaryKey.PrimaryColumn = table.GetColumn(sqlPrimaryKey.ColumnName);
            return(primaryKey);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="table"></param>
 /// <returns></returns>
 public PostgresPrimaryKey GetPrimaryKey(PostgresTable table)
 {
     return(PostgresPrimaryKeys?.FirstOrDefault(f =>
                                                f.TableSchema == table.Schema &&
                                                f.TableName == table.Name));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public List <PostgresUniqueKeyInfo> GetUniqueKeys(PostgresTable table)
        {
            var keys = PostgresUniqueKeys.ToList(w => w.TableName == table.Name && w.TableSchema == table.Schema);

            return(keys.GroupBy(g => g.ConstraintName).Select(s => new PostgresUniqueKeyInfo(s)).ToList());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <param name="postgresTable"></param>
        /// <returns></returns>
        private List <ColumnInfo> GetColumns(TableInfo table, PostgresTable postgresTable)
        {
            var columns = PostgresColumnManager.GetSqlColumns(postgresTable);

            return(columns.Select(s => ConvertToColumnInfo(table, s)).ToList());
        }