|
1 | | -# WebNet.LiteGraphExtensions.GraphRepositories |
| 1 | +# WebNet.LiteGraphExtensions.GraphRepositories |
| 2 | + |
| 3 | +Graph repository implementations for the LiteGraph library, providing persistent storage backends for graph data structures. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This library provides concrete implementations of the LiteGraph `GraphRepositoryBase` abstract class, enabling you to store and query graph data using various database backends. |
| 8 | + |
| 9 | +## Available Implementations |
| 10 | + |
| 11 | +### DuckDBGraphRepository |
| 12 | + |
| 13 | +A high-performance graph repository implementation using DuckDB, an in-process SQL OLAP database optimized for analytical queries. |
| 14 | + |
| 15 | +#### Features |
| 16 | + |
| 17 | +- **Full ACID Compliance**: Transactional support with DuckDB's built-in ACID guarantees |
| 18 | +- **Schema Management**: Automatic database schema initialization with foreign keys and indexes |
| 19 | +- **Backup Support**: Native backup functionality via DuckDB's EXPORT DATABASE |
| 20 | +- **Columnar Storage**: Efficient storage for large-scale graph analytics |
| 21 | +- **In-Memory or Persistent**: Supports both file-based and in-memory databases |
| 22 | + |
| 23 | +#### Usage |
| 24 | + |
| 25 | +```csharp |
| 26 | +using WebNet.LiteGraphExtensions.GraphRepositories; |
| 27 | + |
| 28 | +// Create repository with file-based storage |
| 29 | +var repository = new DuckDBGraphRepository("Data Source=mydb.duckdb"); |
| 30 | + |
| 31 | +// Initialize the database schema |
| 32 | +repository.InitializeRepository(); |
| 33 | + |
| 34 | +// Use the repository through LiteGraph interfaces |
| 35 | +var tenant = await repository.Tenant.Create(new TenantMetadata |
| 36 | +{ |
| 37 | + GUID = Guid.NewGuid(), |
| 38 | + Name = "My Tenant" |
| 39 | +}); |
| 40 | + |
| 41 | +var graph = await repository.Graph.Create(new Graph |
| 42 | +{ |
| 43 | + GUID = Guid.NewGuid(), |
| 44 | + TenantGUID = tenant.GUID, |
| 45 | + Name = "My Graph" |
| 46 | +}); |
| 47 | + |
| 48 | +// Flush changes to disk |
| 49 | +repository.Flush(); |
| 50 | + |
| 51 | +// Backup database |
| 52 | +await repository.Admin.Backup("./backup"); |
| 53 | + |
| 54 | +// Dispose when done |
| 55 | +repository.Dispose(); |
| 56 | +``` |
| 57 | + |
| 58 | +#### Connection Strings |
| 59 | + |
| 60 | +DuckDB supports standard ADO.NET connection string format: |
| 61 | + |
| 62 | +- **File-based**: `Data Source=path/to/database.duckdb` |
| 63 | +- **In-memory**: `Data Source=:memory:` |
| 64 | +- **Read-only**: `Data Source=database.duckdb;Read Only=true` |
| 65 | + |
| 66 | +#### Database Schema |
| 67 | + |
| 68 | +The DuckDB implementation creates the following tables: |
| 69 | + |
| 70 | +- **tenants** - Tenant metadata |
| 71 | +- **graphs** - Graph definitions |
| 72 | +- **nodes** - Graph nodes with properties |
| 73 | +- **edges** - Graph edges connecting nodes |
| 74 | +- **labels** - Labels for graphs, nodes, and edges |
| 75 | +- **tags** - Key-value tags for graphs, nodes, and edges |
| 76 | +- **vectors** - Vector embeddings for similarity search |
| 77 | +- **users** - User accounts and authentication |
| 78 | +- **credentials** - API credentials for programmatic access |
| 79 | + |
| 80 | +All tables include appropriate foreign keys, indexes, and constraints for data integrity. |
| 81 | + |
| 82 | +#### Implementation Status |
| 83 | + |
| 84 | +The DuckDB repository provides: |
| 85 | +- ✅ **Admin Methods**: Backup operations implemented |
| 86 | +- ✅ **Connection Management**: Full lifecycle support with proper disposal |
| 87 | +- ✅ **Schema Initialization**: Automatic table creation with relationships |
| 88 | +- ⚠️ **CRUD Operations**: Interface methods defined, implementation in progress |
| 89 | + |
| 90 | +Note: Most CRUD operations currently throw `NotImplementedException` and require implementation based on your specific use case. |
| 91 | + |
| 92 | +### LiteDBGraphRepository |
| 93 | + |
| 94 | +*(Documentation pending)* |
| 95 | + |
| 96 | +### FastDBGraphRepository |
| 97 | + |
| 98 | +*(Documentation pending)* |
| 99 | + |
| 100 | +## Installation |
| 101 | + |
| 102 | +```bash |
| 103 | +dotnet add package WebNet.LiteGraphExtensions.GraphRepositories |
| 104 | +``` |
| 105 | + |
| 106 | +## Requirements |
| 107 | + |
| 108 | +- .NET 10.0 or later |
| 109 | +- LiteGraph 5.0.2 |
| 110 | +- DuckDB.NET.Data.Full 1.4.3 (for DuckDB implementation) |
| 111 | + |
| 112 | +## Testing |
| 113 | + |
| 114 | +The library includes comprehensive unit tests: |
| 115 | + |
| 116 | +```bash |
| 117 | +dotnet test |
| 118 | +``` |
| 119 | + |
| 120 | +All 13 tests validate: |
| 121 | +- Repository construction and initialization |
| 122 | +- Connection string validation |
| 123 | +- Schema creation |
| 124 | +- Method implementation instantiation |
| 125 | +- Resource disposal |
| 126 | +- Backup functionality |
| 127 | + |
| 128 | +## Contributing |
| 129 | + |
| 130 | +Contributions are welcome! Please ensure all tests pass before submitting pull requests. |
| 131 | + |
| 132 | +## License |
| 133 | + |
| 134 | +See [LICENSE.txt](LICENSE.txt) for details. |
0 commit comments