|
1 | | -namespace WebNet.LiteGraphExtensions.GraphRepositories |
| 1 | +using System; |
| 2 | +using LiteGraph; |
| 3 | +using Stellar.Collections; |
| 4 | + |
| 5 | +namespace WebNet.LiteGraphExtensions.GraphRepositories |
2 | 6 | { |
3 | | - public class FastDBGraphRepository |
| 7 | + /// <summary> |
| 8 | + /// FastDB Graph Repository implementation. |
| 9 | + /// Provides high-performance graph storage using Stellar.FastDB with MessagePack serialization. |
| 10 | + /// FastDB is a key-value collection-based embedded database (~100x faster than similar products). |
| 11 | + /// </summary> |
| 12 | + /// <remarks> |
| 13 | + /// FastDB uses collection-based storage (similar to ConcurrentDictionary) with built-in persistence. |
| 14 | + /// It supports MessagePack serialization for optimal storage footprint and performance. |
| 15 | + /// Note: Implementation pending - LiteGraph interface requires additional parameters in method signatures. |
| 16 | + /// </remarks> |
| 17 | + public class FastDBGraphRepository : LiteGraph.GraphRepositories.GraphRepositoryBase |
4 | 18 | { |
| 19 | + #region Public-Members |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Admin methods. |
| 23 | + /// </summary> |
| 24 | + public override LiteGraph.GraphRepositories.Interfaces.IAdminMethods Admin { get; } |
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// Tenant methods. |
| 28 | + /// </summary> |
| 29 | + public override LiteGraph.GraphRepositories.Interfaces.ITenantMethods Tenant { get; } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// User methods. |
| 33 | + /// </summary> |
| 34 | + public override LiteGraph.GraphRepositories.Interfaces.IUserMethods User { get; } |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Credential methods. |
| 38 | + /// </summary> |
| 39 | + public override LiteGraph.GraphRepositories.Interfaces.ICredentialMethods Credential { get; } |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// Label methods. |
| 43 | + /// </summary> |
| 44 | + public override LiteGraph.GraphRepositories.Interfaces.ILabelMethods Label { get; } |
| 45 | + |
| 46 | + /// <summary> |
| 47 | + /// Tag methods. |
| 48 | + /// </summary> |
| 49 | + public override LiteGraph.GraphRepositories.Interfaces.ITagMethods Tag { get; } |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// Vector methods. |
| 53 | + /// </summary> |
| 54 | + public override LiteGraph.GraphRepositories.Interfaces.IVectorMethods Vector { get; } |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Graph methods. |
| 58 | + /// </summary> |
| 59 | + public override LiteGraph.GraphRepositories.Interfaces.IGraphMethods Graph { get; } |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// Node methods. |
| 63 | + /// </summary> |
| 64 | + public override LiteGraph.GraphRepositories.Interfaces.INodeMethods Node { get; } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Edge methods. |
| 68 | + /// </summary> |
| 69 | + public override LiteGraph.GraphRepositories.Interfaces.IEdgeMethods Edge { get; } |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// Batch methods. |
| 73 | + /// </summary> |
| 74 | + public override LiteGraph.GraphRepositories.Interfaces.IBatchMethods Batch { get; } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Vector index methods. |
| 78 | + /// </summary> |
| 79 | + public override LiteGraph.GraphRepositories.Interfaces.IVectorIndexMethods VectorIndex { get; } |
| 80 | + |
| 81 | + #endregion |
| 82 | + |
| 83 | + #region Private-Members |
| 84 | + |
| 85 | + private readonly FastDB _database; |
| 86 | + private readonly FastDBOptions _options; |
| 87 | + |
| 88 | + #endregion |
| 89 | + |
| 90 | + #region Constructors-and-Factories |
| 91 | + |
| 92 | + /// <summary> |
| 93 | + /// Initialize the FastDB graph repository with default options. |
| 94 | + /// </summary> |
| 95 | + /// <param name="databasePath">Path to the FastDB database directory.</param> |
| 96 | + public FastDBGraphRepository(string databasePath) |
| 97 | + : this(databasePath, new FastDBOptions()) |
| 98 | + { |
| 99 | + } |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// Initialize the FastDB graph repository with custom options. |
| 103 | + /// </summary> |
| 104 | + /// <param name="databasePath">Path to the FastDB database directory.</param> |
| 105 | + /// <param name="options">FastDB options for compression, encryption, serialization, etc.</param> |
| 106 | + public FastDBGraphRepository(string databasePath, FastDBOptions options) |
| 107 | + { |
| 108 | + if (string.IsNullOrEmpty(databasePath)) |
| 109 | + throw new ArgumentNullException(nameof(databasePath)); |
| 110 | + |
| 111 | + // Configure options for optimal graph storage |
| 112 | + // Note: FastDBOptions properties are init-only, so we need to create a new instance |
| 113 | + _options = options ?? new FastDBOptions |
| 114 | + { |
| 115 | + Serializer = SerializerType.MessagePack_Contract // Use MessagePack for compact storage (can reduce size by ~40%) |
| 116 | + }; |
| 117 | + |
| 118 | + _database = new FastDB(_options); |
| 119 | + |
| 120 | + // Initialize implementation classes |
| 121 | + Admin = new Implementations.FastDB.AdminMethods(this); |
| 122 | + Tenant = new Implementations.FastDB.TenantMethods(this); |
| 123 | + User = new Implementations.FastDB.UserMethods(this); |
| 124 | + Credential = new Implementations.FastDB.CredentialMethods(this); |
| 125 | + Label = new Implementations.FastDB.LabelMethods(this); |
| 126 | + Tag = new Implementations.FastDB.TagMethods(this); |
| 127 | + Vector = new Implementations.FastDB.VectorMethods(this); |
| 128 | + Graph = new Implementations.FastDB.GraphMethods(this); |
| 129 | + Node = new Implementations.FastDB.NodeMethods(this); |
| 130 | + Edge = new Implementations.FastDB.EdgeMethods(this); |
| 131 | + Batch = new Implementations.FastDB.BatchMethods(this); |
| 132 | + VectorIndex = new Implementations.FastDB.VectorIndexMethods(this); |
| 133 | + } |
| 134 | + |
| 135 | + #endregion |
| 136 | + |
| 137 | + #region Public-Methods |
| 138 | + |
| 139 | + /// <summary> |
| 140 | + /// Initialize the repository schema. |
| 141 | + /// Collections are created when first used via GetCollection<TKey, TValue>() |
| 142 | + /// </summary> |
| 143 | + public override void InitializeRepository() |
| 144 | + { |
| 145 | + // FastDB automatically creates collections on first access |
| 146 | + // No explicit initialization needed |
| 147 | + } |
| 148 | + |
| 149 | + /// <summary> |
| 150 | + /// Flush database contents to disk. |
| 151 | + /// </summary> |
| 152 | + public override void Flush() |
| 153 | + { |
| 154 | + // FastDB collections are automatically flushed |
| 155 | + // The database handles persistence internally |
| 156 | + } |
| 157 | + /// <summary> |
| 158 | + /// Get the FastDB database instance. |
| 159 | + /// </summary> |
| 160 | + /// <returns>FastDB database instance.</returns> |
| 161 | + internal FastDB GetDatabase() |
| 162 | + { |
| 163 | + return _database; |
| 164 | + } |
| 165 | + |
| 166 | + /// <summary> |
| 167 | + /// Dispose the repository and close database connection. |
| 168 | + /// </summary> |
| 169 | + public void Dispose() |
| 170 | + { |
| 171 | + _database?.Close(); |
| 172 | + } |
| 173 | + |
| 174 | + #endregion |
| 175 | + |
| 176 | + #region Private-Methods |
| 177 | + |
| 178 | + #endregion |
5 | 179 | } |
6 | 180 | } |
0 commit comments