Path: redb/redb.Export/Flat/Model/FlatTable.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Export/Flat/Model/FlatTable.cs
----
namespace redb.Export.Flat.Model;
///
/// One flat table: its columns and constraints, plus where its rows come from in redb.
///
public sealed class FlatTable
{
private readonly List _columns = [];
private readonly List _foreignKeys = [];
private readonly List _uniqueConstraints = [];
private readonly List _indexes = [];
/// Creates a table; is shortened to the identifier limit when needed.
public FlatTable(string fullName)
{
FullName = fullName;
Name = FlatNaming.Shorten(fullName);
PrimaryKeyName = FlatNaming.Shorten($"PK_{fullName}");
}
/// Table name as it goes into DDL.
public string Name { get; }
/// Name before shortening: the class name or the full property path.
public string FullName { get; }
/// What the table holds.
public FlatTableKind Kind { get; init; }
/// The Props type of the scheme the table belongs to; null for service tables.
public Type? PropsType { get; init; }
/// The class whose properties are the columns: the Props type, a nested class, or the element class of a collection.
public Type? ClassType { get; init; }
/// Property path from the Props type (HomeAddress.Building); null for scheme and service tables.
public string? PropertyPath { get; init; }
/// Name of the table whose rows own the rows of this one; null for scheme and service tables.
public string? OwnerTable { get; init; }
///
/// _structures._id of the field the table is built from: the class field of a nested
/// table, the collection field of a collection table. Null for scheme and service tables, and
/// when the model was built without a structure tree.
///
public long? StructureId { get; init; }
/// Array or dictionary, for a collection table.
public FlatCollectionKind CollectionKind { get; init; }
/// What one element is, for a collection table.
public FlatElementKind ElementKind { get; init; }
/// CLR type of one element (the value type of a dictionary), for a collection table.
public Type? ElementType { get; init; }
/// CLR type of the key, for a dictionary table.
public Type? KeyType { get; init; }
/// How the key is laid out, for a dictionary table.
public FlatKeyKind KeyKind { get; init; }
/// Name of the primary key column.
public string PrimaryKey { get; init; } = FlatNaming.IdColumn;
/// Name of the primary key constraint.
public string PrimaryKeyName { get; }
/// Columns in declaration order.
public IReadOnlyList Columns => _columns;
/// Foreign keys. They are meant to be created after every table exists: a reference may point to a table that comes later.
public IReadOnlyList ForeignKeys => _foreignKeys;
/// Unique constraints.
public IReadOnlyList UniqueConstraints => _uniqueConstraints;
internal void Add(FlatColumn column) => _columns.Add(column);
internal void Add(FlatForeignKey foreignKey) => _foreignKeys.Add(foreignKey);
/// Plain indexes. Like foreign keys, they are meant to be created after the data is loaded.
public IReadOnlyList Indexes => _indexes;
internal void Add(FlatUniqueConstraint uniqueConstraint) => _uniqueConstraints.Add(uniqueConstraint);
internal void Add(FlatIndex index) => _indexes.Add(index);
}
///
/// The whole flat model: the three service tables followed by the tables of every scheme, each
/// owner before the tables it owns.
///
public sealed class FlatDatabaseModel
{
/// Creates the model over an ordered list of tables.
public FlatDatabaseModel(IReadOnlyList tables)
{
Tables = tables;
}
/// Tables in creation order.
public IReadOnlyList Tables { get; }
}