{"id":21530677,"url":"https://github.com/kei-k23/keyboxdb","last_synced_at":"2025-03-17T19:20:52.748Z","repository":{"id":263962231,"uuid":"891926976","full_name":"Kei-K23/KeyBoxDB","owner":"Kei-K23","description":"A thread-safe, high-performance key-vale storage database written in C#","archived":false,"fork":false,"pushed_at":"2024-11-21T08:06:10.000Z","size":15,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-24T06:26:36.580Z","etag":null,"topics":["csharp","dotnet","keyvaluestore"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kei-K23.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-21T07:53:54.000Z","updated_at":"2025-01-09T18:35:13.000Z","dependencies_parsed_at":"2024-11-21T08:40:19.569Z","dependency_job_id":null,"html_url":"https://github.com/Kei-K23/KeyBoxDB","commit_stats":null,"previous_names":["kei-k23/keyboxdb"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kei-K23%2FKeyBoxDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kei-K23%2FKeyBoxDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kei-K23%2FKeyBoxDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kei-K23%2FKeyBoxDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kei-K23","download_url":"https://codeload.github.com/Kei-K23/KeyBoxDB/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244094266,"owners_count":20397020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","keyvaluestore"],"created_at":"2024-11-24T02:09:41.142Z","updated_at":"2025-03-17T19:20:52.720Z","avatar_url":"https://github.com/Kei-K23.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KeyBoxDB 📦: Lightweight Key-Value Storage\n\n**KeyBoxDB** 📦 is a lightweight, in-memory, and file-persisted key-value storage database for .NET applications. It supports basic CRUD operations, time-to-live (TTL) for keys, batch operations with transactions, and automatic cleanup of expired keys.\n\n## Features\n\n- **CRUD Operations**: Add, retrieve, update, and delete key-value pairs.\n- **Persistent Storage**: Data is stored in a compressed file and automatically reloaded on startup.\n- **TTL (Time-to-Live)**: Automatically expire keys after a specified duration.\n- **Transactions**: Support for batch operations with commit and rollback.\n- **Concurrency**: Thread-safe operations with efficient locking mechanisms.\n- **Background Cleanup**: Automatic removal of expired keys.\n- **In-Memory Indexing**: Fast lookups using in-memory indexing.\n\n---\n\n## Getting Started\n\n### Prerequisites\n\n- **.NET 6.0 or later**\n- Add a reference to `System.Collections.Concurrent` and `System.IO.Compression`.\n\n---\n\n### Installation\n\nClone the repository and add the `KeyBoxDB` project to your solution. Alternatively, include the source files directly in your project.\n\n---\n\n### Usage\n\n#### Initializing the Key-Value Store\n\n```csharp\nusing KeyBoxDB.Database;\n\n// Initialize with a path for persistent storage\nvar kvStore = new KeyValueStore(\"path/to/database.db\");\n```\n\n---\n\n#### Basic Operations\n\n##### Add a Key\n\n```csharp\nkvStore.Add(\"exampleKey\", \"exampleValue\", TimeSpan.FromMinutes(5)); // Optional TTL\n```\n\n##### Get a Key\n\n```csharp\ntry\n{\n    var value = kvStore.Get(\"exampleKey\");\n    Console.WriteLine($\"Value: {value}\");\n}\ncatch (KeyNotFoundException ex)\n{\n    Console.WriteLine(ex.Message);\n}\n```\n\n##### Update a Key\n\n```csharp\nkvStore.Update(\"exampleKey\", \"newValue\", TimeSpan.FromHours(1));\n```\n\n##### Delete a Key\n\n```csharp\nkvStore.Delete(\"exampleKey\");\n```\n\n##### Get All Keys\n\n```csharp\nforeach (var record in kvStore.GetAll())\n{\n    Console.WriteLine($\"{record.Key}: {record.Value}\");\n}\n```\n\n---\n\n#### Transactions\n\n##### Begin a Transaction\n\n```csharp\nkvStore.BeginTransaction();\n```\n\n##### Perform Batch Operations\n\n```csharp\nkvStore.Add(\"key1\", \"value1\");\nkvStore.Update(\"key2\", \"newValue2\");\nkvStore.Delete(\"key3\");\n```\n\n##### Commit the Transaction\n\n```csharp\nkvStore.CommitTransaction();\n```\n\n##### Rollback the Transaction\n\n```csharp\nkvStore.RollbackTransaction();\n```\n\n---\n\n#### Graceful Shutdown\n\nAlways dispose of the store to stop background tasks and release resources.\n\n```csharp\nkvStore.Dispose();\n```\n\n---\n\n## Internals\n\n### Record Structure\n\nEach key-value pair is stored as a `Record`:\n\n```csharp\npublic class Record\n{\n    public string Key { get; set; }\n    public string Value { get; set; }\n    public DateTime Timestamp { get; set; } = DateTime.UtcNow;\n    public DateTime? ExpirationDate { get; set; }\n\n    public bool IsExpired() =\u003e ExpirationDate.HasValue \u0026\u0026 ExpirationDate.Value \u003c= DateTime.UtcNow;\n}\n```\n\n---\n\n### Persistent Storage\n\nThe database uses a compressed JSON file to persist the data:\n\n- **Save**: Data is serialized to JSON and compressed using GZip.\n- **Load**: Data is decompressed and deserialized on startup.\n\n---\n\n## Contributing\n\n1. Fork the repository.\n2. Create a feature branch (`git checkout -b feature/your-feature`).\n3. Commit your changes (`git commit -m 'Add feature'`).\n4. Push the branch (`git push origin feature/your-feature`).\n5. Open a pull request.\n\n---\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkei-k23%2Fkeyboxdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkei-k23%2Fkeyboxdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkei-k23%2Fkeyboxdb/lists"}