Path: redb/redb.Core/Models/Entities/RedbStructure.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.Core/Models/Entities/RedbStructure.cs
----
using redb.Core.Models.Contracts;
using System.Text.Json.Serialization;
namespace redb.Core.Models.Entities
{
///
/// REDB structure (field definition) entity with direct data storage.
/// Maps to _structures table in PostgreSQL.
///
public class RedbStructure : IRedbStructure
{
///
/// Unique structure identifier.
///
[JsonPropertyName("id")]
public long Id { get; set; }
///
/// Parent structure identifier (for nested fields).
///
[JsonPropertyName("id_parent")]
public long? IdParent { get; set; }
///
/// Scheme identifier this structure belongs to.
///
[JsonPropertyName("id_scheme")]
public long IdScheme { get; set; }
///
/// Override structure identifier (for inheritance).
///
[JsonPropertyName("id_override")]
public long? IdOverride { get; set; }
///
/// Type identifier for this field.
///
[JsonPropertyName("id_type")]
public long IdType { get; set; }
///
/// List identifier (for list-type fields).
///
[JsonPropertyName("id_list")]
public long? IdList { get; set; }
///
/// Field name.
///
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
///
/// Field alias (short name).
///
[JsonPropertyName("alias")]
public string? Alias { get; set; }
///
/// Field order in scheme.
///
[JsonPropertyName("order")]
public long? Order { get; set; }
///
/// Is field read-only.
///
[JsonPropertyName("readonly")]
public bool? Readonly { get; set; }
///
/// Is field required (not null).
///
[JsonPropertyName("allow_not_null")]
public bool? AllowNotNull { get; set; }
///
/// Collection type ID: Array (-9223372036854775668) or Dictionary (-9223372036854775667).
/// NULL for non-collection fields.
///
[JsonPropertyName("collection_type")]
public long? CollectionType { get; set; }
///
/// Key type ID for Dictionary fields. NULL for non-dictionary fields.
///
[JsonPropertyName("key_type")]
public long? KeyType { get; set; }
///
/// Compress field values.
///
[JsonPropertyName("is_compress")]
public bool? IsCompress { get; set; }
///
/// Store null values.
///
[JsonPropertyName("store_null")]
public bool? StoreNull { get; set; }
///
/// V4 (LAZY Л2): the reference is lazy - read from the `virtual` marker on the property at
/// synchronisation. Builders emit a stub for such a reference when the option is on.
///
[JsonPropertyName("lazy")]
public bool? Lazy { get; set; }
///
/// Unique key within the scheme ([RedbUnique]).
///
[JsonPropertyName("unique")]
public bool? Unique { get; set; }
///
/// Encoder version the stored keys were computed with.
///
[JsonPropertyName("unique_version")]
public long? UniqueVersion { get; set; }
///
/// S3: element-key scope of a collection key (NULL = default reading; 1 = element values
/// unique per scheme; 2 = no duplicate elements per collection). Values mirror
/// .
///
[JsonPropertyName("unique_scope")]
public long? UniqueScope { get; set; }
///
/// Free-form marker for future / custom extensions (450 chars). Written by
/// [RedbTags] at synchronisation when present; direct writes survive sync.
///
[JsonPropertyName("tags")]
public string? Tags { get; set; }
///
/// The previous names of the structure, oldest first, as a JSON array of strings; NULL when it was never
/// renamed. Written by the sync when it applies [RedbRename]; read by the sync to stop a class that predates
/// the rename.
///
[JsonPropertyName("renamed_from")]
public string? RenamedFrom { get; set; }
///
/// Default value (binary).
///
[JsonPropertyName("default_value")]
public byte[]? DefaultValue { get; set; }
///
/// Default editor for field.
///
[JsonPropertyName("default_editor")]
public string? DefaultEditor { get; set; }
///
/// Computed property: is this an array field.
///
[JsonIgnore]
public bool? IsArray => CollectionType != null;
///
/// Default constructor for deserialization and mapping.
///
public RedbStructure()
{
}
public override string ToString()
{
var alias = !string.IsNullOrEmpty(Alias) ? $" ({Alias})" : "";
var arrayIndicator = IsArray == true ? "[]" : "";
var requiredIndicator = AllowNotNull == true ? "*" : "";
return $"Structure {Id}: {Name}{alias}{arrayIndicator}{requiredIndicator} [Type: {IdType}]";
}
}
}