|
4 | 4 | // </copyright> |
5 | 5 | namespace SharpCoreDB.Interfaces; |
6 | 6 |
|
| 7 | +using SharpCoreDB.Storage.Hybrid; |
| 8 | + |
7 | 9 | /// <summary> |
8 | 10 | /// Interface for a database table. |
9 | 11 | /// </summary> |
@@ -87,6 +89,66 @@ public interface ITable |
87 | 89 | /// </summary> |
88 | 90 | List<string?> ColumnLocaleNames { get; } |
89 | 91 |
|
| 92 | + // ── DDL lifecycle members ─────────────────────────────────────────────── |
| 93 | + // These have default implementations so existing test fakes that implement |
| 94 | + // ITable for read-only purposes do not need to be updated. |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// Gets or sets the storage engine mode for this table. |
| 98 | + /// Directory-mode tables use <see cref="StorageMode.Columnar"/> or <see cref="StorageMode.PageBased"/>. |
| 99 | + /// Single-file tables default to <see cref="StorageMode.Columnar"/> and the value is schema-only. |
| 100 | + /// </summary> |
| 101 | + StorageMode StorageMode { get => StorageMode.Columnar; set { } } |
| 102 | + |
| 103 | + /// <summary> |
| 104 | + /// Gets or sets the primary key B-tree index. |
| 105 | + /// Directory-mode tables use a full BTree; single-file tables use a no-op implementation. |
| 106 | + /// </summary> |
| 107 | + IIndex<string, long> Index { get => NullIndex.Instance; set { } } |
| 108 | + |
| 109 | + /// <summary> |
| 110 | + /// Gets or sets per-column DEFAULT expressions (SQL expression strings). |
| 111 | + /// </summary> |
| 112 | + List<string?> DefaultExpressions { get => []; set { } } |
| 113 | + |
| 114 | + /// <summary> |
| 115 | + /// Gets or sets per-column CHECK constraint expressions. |
| 116 | + /// </summary> |
| 117 | + List<string?> ColumnCheckExpressions { get => []; set { } } |
| 118 | + |
| 119 | + /// <summary> |
| 120 | + /// Gets or sets table-level CHECK constraint expressions. |
| 121 | + /// </summary> |
| 122 | + List<string> TableCheckConstraints { get => []; set { } } |
| 123 | + |
| 124 | + /// <summary> |
| 125 | + /// Initializes (or re-initializes) the underlying storage engine for this table. |
| 126 | + /// For directory-mode tables this opens or creates the columnar/page-based file. |
| 127 | + /// For single-file tables this is a no-op (storage is managed by the provider). |
| 128 | + /// </summary> |
| 129 | + void InitializeStorageEngine() { } |
| 130 | + |
| 131 | + /// <summary> |
| 132 | + /// Returns true if an index (by name or column name) exists on this table. |
| 133 | + /// Used by <c>CREATE INDEX IF NOT EXISTS</c> to avoid duplicate creation. |
| 134 | + /// Single-file tables without a real index registry always return false. |
| 135 | + /// </summary> |
| 136 | + /// <param name="nameOrColumn">Index name or column name to check.</param> |
| 137 | + /// <returns>True if the index exists.</returns> |
| 138 | + bool HasIndex(string nameOrColumn) => false; |
| 139 | + |
| 140 | + /// <summary> |
| 141 | + /// Applies the given <paramref name="schema"/> definition to this table instance. |
| 142 | + /// Called by <c>SqlParser.ExecuteCreateTable</c> after the factory creates the table |
| 143 | + /// object but before it is registered or its storage is initialised. |
| 144 | + /// The default implementation is a no-op; concrete classes override this to populate |
| 145 | + /// their internal schema fields without requiring individual property setters on the interface. |
| 146 | + /// </summary> |
| 147 | + /// <param name="schema">The full schema definition produced by DDL parsing.</param> |
| 148 | + void ApplySchema(TableSchemaDefinition schema) { } |
| 149 | + |
| 150 | + // ── Insert ────────────────────────────────────────────────────────────── |
| 151 | + |
90 | 152 | /// <summary> |
91 | 153 | /// Inserts a row into the table. |
92 | 154 | /// </summary> |
@@ -242,7 +304,7 @@ public interface ITable |
242 | 304 | /// This prevents stale/corrupt index data from being read after DDL operations. |
243 | 305 | /// </summary> |
244 | 306 | void ClearAllIndexes(); |
245 | | - |
| 307 | + |
246 | 308 | /// <summary> |
247 | 309 | /// Gets the cached row count (O(1) operation). |
248 | 310 | /// Returns -1 if cache is not initialized. |
@@ -279,7 +341,7 @@ public interface ITable |
279 | 341 | /// <param name="columnName">The column name.</param> |
280 | 342 | /// <returns>True if B-tree index exists.</returns> |
281 | 343 | bool HasBTreeIndex(string columnName); |
282 | | - |
| 344 | + |
283 | 345 | /// <summary> |
284 | 346 | /// Flushes all pending writes to disk. |
285 | 347 | /// Ensures INSERT/UPDATE/DELETE operations are persisted. |
@@ -314,4 +376,19 @@ public interface ITable |
314 | 376 | /// <param name="key">The metadata key.</param> |
315 | 377 | /// <returns>True if the entry was removed.</returns> |
316 | 378 | bool RemoveMetadata(string key); |
| 379 | + |
| 380 | + // ── Private helper singleton ───────────────────────────────────────────── |
| 381 | + |
| 382 | + /// <summary> |
| 383 | + /// No-op <see cref="IIndex{TKey,TValue}"/> singleton returned by the default |
| 384 | + /// <see cref="Index"/> property implementation. |
| 385 | + /// </summary> |
| 386 | + private sealed class NullIndex : IIndex<string, long> |
| 387 | + { |
| 388 | + internal static readonly NullIndex Instance = new(); |
| 389 | + public void Insert(string key, long value) { } |
| 390 | + public (bool Found, long Value) Search(string key) => (false, 0); |
| 391 | + public bool Delete(string key) => false; |
| 392 | + public void Clear() { } |
| 393 | + } |
317 | 394 | } |
0 commit comments