public ConcurrentDictionary <string, ConcurrentDictionary <string, RelationSchema> > GetRelationSchemas() { var schemaRelations = new ConcurrentDictionary <string, ConcurrentDictionary <string, RelationSchema> >(); foreach (var entity in RelationEntities) { if (!schemaRelations.ContainsKey(entity.SchemaName)) { schemaRelations[entity.SchemaName] = new ConcurrentDictionary <string, RelationSchema>(); } if (!schemaRelations[entity.SchemaName].ContainsKey(entity.RelationName)) { schemaRelations[entity.SchemaName][entity.RelationName] = new RelationSchema( entity.RelationName, entity.SchemaName, QuotedSchemaRelation(entity.RelationName, entity.SchemaName), ColumnEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName).ToImmutableArray(), ColumnEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName).Select(s => s.ColumnName).ToImmutableArray(), ColumnEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName && q.IsPrimaryKey).ToImmutableArray(), ColumnEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName && q.IsPrimaryKey).Select(s => s.ColumnName).ToImmutableArray(), UniqueIndexEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName).ToImmutableArray(), ForeignKeyEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName).ToImmutableArray() ); } } return(schemaRelations); }
public ImmutableArray <ColumnEntity> GetPrimaryKeyColumns(string relationName, string schemaName = DefaultSchema) { if (!RelationExists(relationName, schemaName)) { throw new DbException($"Relation does not exist: '{relationName}'.'{schemaName}'"); } return(ColumnEntities .Where(q => q.RelationName == relationName && q.SchemaName == schemaName && q.IsPrimaryKey) .OrderBy(o => o.Position) .ToImmutableArray()); }
public ImmutableArray <string> GetColumnNames(string relationName, string schemaName = IDbSchema.DefaultSchema) { if (!RelationExists(relationName, schemaName)) { throw new DbException($"Relation does not exist: '{relationName}'.'{schemaName}'"); } return(ColumnEntities .Where(q => q.RelationName == relationName && q.SchemaName == schemaName) .OrderBy(o => o.Position) .Select(s => s.ColumnName) .ToImmutableArray()); }