### Basic SlateDB .NET Usage Source: https://github.com/pulsy-global/slatedb-dotnet/blob/master/README.md Demonstrates basic operations like building a SlateDB instance, putting, getting, and deleting key-value pairs. It requires configuring an object store and specifying database and bucket names. ```csharp using var db = SlateDb.Builder("my-db", new ObjectStoreConfig { Bucket = "my-bucket", Region = "us-east-1", Endpoint = "http://localhost:9000", }) .Build(); db.Put("deck", "steam"); db.GetString("deck"); // "steam" db.Get("score"); // null db.Delete("deck"); ``` -------------------------------- ### Get Operations in C# Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt This code snippet demonstrates the `Get` methods to retrieve values from the database, including type conversion and read options for durability filtering. It shows how to get values as strings, typed values, raw bytes, and how to handle non-existent keys. ```csharp using Pulsy.SlateDB; using Pulsy.SlateDB.Options; using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-get").Build(); db.Put("name", "Bob"); db.Put("score", 42); db.Put("ratio", 3.14); // Get as string string? name = db.GetString("name"); Console.WriteLine(name ?? "not found"); // Output: Bob // Get as typed value (returns nullable) int? score = db.Get("score"); double? ratio = db.Get("ratio"); Console.WriteLine($"Score: {score}, Ratio: {ratio}"); // Output: Score: 42, Ratio: 3.14 // Get non-existent key returns null string? missing = db.GetString("nonexistent"); Console.WriteLine(missing ?? "null"); // Output: null // Get raw bytes byte[]? rawData = db.Get("name"); Console.WriteLine(rawData != null ? $"Length: {rawData.Length}" : "null"); // Output: Length: 3 // Get with read options var readOpts = new ReadOptions { DurabilityFilter = Durability.Remote, // Only return remotely persisted data CacheBlocks = true, Dirty = false }; byte[]? durableValue = db.Get("name", readOpts); ``` -------------------------------- ### Load Settings from External Sources in C# Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt Illustrates how to load SlateDB configuration settings from various external sources using static methods on the `SlateDb` class. This includes getting default settings, loading from TOML files, environment variables, and combining these sources. Requires the Pulsy.SlateDB namespace. ```csharp using Pulsy.SlateDB; // Get default settings as JSON string defaultSettings = SlateDb.SettingsDefault(); Console.WriteLine($"Default settings: {defaultSettings}"); // Load settings from TOML file // string fileSettings = SlateDb.SettingsFromFile("/path/to/slatedb.toml"); // Load settings from environment variables with prefix // e.g., MYAPP_FLUSH_INTERVAL, MYAPP_WAL_ENABLED // string envSettings = SlateDb.SettingsFromEnv("MYAPP_"); // Combined loading (file + env overrides) // string loadedSettings = SlateDb.SettingsLoad(); ``` -------------------------------- ### Install SlateDB .NET Package Source: https://github.com/pulsy-global/slatedb-dotnet/blob/master/README.md Installs the Pulsy.SlateDB NuGet package using the .NET CLI. This is the first step to using SlateDB in your .NET project. ```bash dotnet add package Pulsy.SlateDB ``` -------------------------------- ### Put with TTL and Durability in C# Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt This code snippet demonstrates how to use the `Put` method with `PutOptions` to set time-to-live (TTL) expiration and `WriteOptions` for durability guarantees. It shows examples of setting different TTLs and using durability options. ```csharp using Pulsy.SlateDB; using Pulsy.SlateDB.Options; using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-ttl").Build(); // Key that expires after 1 hour db.Put("session:abc123", "user-data", PutOptions.ExpireAfter(TimeSpan.FromHours(1)), WriteOptions.Default); // Key that never expires (overrides database default TTL) db.Put("permanent-key", "permanent-value", PutOptions.NoExpiry, new WriteOptions { AwaitDurable = true }); // Key using database default TTL db.Put("default-ttl-key", "some-value", PutOptions.DefaultTtl, WriteOptions.Default); Console.WriteLine(db.GetString("session:abc123")); // Output: user-data Console.WriteLine(db.GetString("permanent-key")); // Output: permanent-value ``` -------------------------------- ### Database Maintenance Operations in C# Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt Provides examples of database maintenance operations using SlateDB, specifically `Flush` for manual persistence and `Metrics` for performance monitoring. These methods are part of the core SlateDB functionality and require the Pulsy.SlateDB namespace. ```csharp using Pulsy.SlateDB; using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-maintenance").Build(); // Perform writes for (int i = 0; i < 100; i++) { db.Put($"key:{i}", $"value:{i}"); } // Force flush to persistent storage db.Flush(); Console.WriteLine("Data flushed to storage"); // Get database metrics (returns JSON) string metricsJson = db.Metrics(); Console.WriteLine($"Metrics: {metricsJson}"); // Output: JSON with stats like write_count, read_count, cache_hits, etc. ``` -------------------------------- ### Perform Range Scans in Slatedb .NET Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt The Scan method iterates over key-value pairs within a specified key range (start inclusive, end exclusive). It supports custom scan options for fine-grained control over read behavior. The method returns an iterator that can be used to traverse the matching key-value pairs. ```csharp using Pulsy.SlateDB; using Pulsy.SlateDB.Options; using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-scan").Build(); // Populate test data db.Put("key:001", "first"); db.Put("key:002", "second"); db.Put("key:003", "third"); db.Put("key:004", "fourth"); db.Put("key:005", "fifth"); db.Put("other:001", "other"); // Scan range [start, end) - start inclusive, end exclusive Console.WriteLine("Range scan key:002 to key:004:"); using (var iterator = db.Scan("key:002", "key:004")) { foreach (var kv in iterator) { Console.WriteLine($" {kv.KeyString} = {kv.ValueString}"); } } // Output: // key:002 = second // key:003 = third // Scan from beginning (null start) to specific end Console.WriteLine("\nScan from start to key:003:"); using (var iterator = db.Scan(null, "key:003")) { foreach (var kv in iterator) { Console.WriteLine($" {kv.KeyString} = {kv.ValueString}"); } } // Output: // key:001 = first // key:002 = second // Scan with options var scanOpts = new ScanOptions { DurabilityFilter = Durability.Memory, CacheBlocks = true, ReadAheadBytes = 1024 * 1024, // 1MB read-ahead MaxFetchTasks = 4 }; using (var iterator = db.Scan("key:001", "key:006", scanOpts)) { while (true) { var kv = iterator.Next(); if (kv == null) break; Console.WriteLine($" {kv.KeyString} = {kv.ValueString}"); } } ``` -------------------------------- ### Open Database with ObjectStoreConfig (C#) Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt Demonstrates opening a SlateDB database connection configured for S3-compatible object storage, such as MinIO. It requires explicit credentials and endpoint configuration. This method is suitable for cloud-native or self-hosted object storage solutions. ```csharp using Pulsy.SlateDB; using Pulsy.SlateDB.Options; // Open database connected to S3-compatible storage (e.g., MinIO) using var db = SlateDb.Builder("my-database", new ObjectStoreConfig { Bucket = "my-bucket", Region = "us-east-1", Endpoint = "http://localhost:9000", AccessKeyId = "minioadmin", SecretAccessKey = "minioadmin", AllowHttp = true // Required for non-HTTPS endpoints }) .Build(); // Database is now ready for operations db.Put("greeting", "Hello, SlateDB!"); Console.WriteLine(db.GetString("greeting")); // Output: Hello, SlateDB! ``` -------------------------------- ### Configure Database Settings (C#) Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt Illustrates how to customize SlateDB's behavior using the `WithSettings` method. This allows fine-tuning of compression, compaction, caching, and write-ahead logging parameters for performance optimization. ```csharp using Pulsy.SlateDB; using Pulsy.SlateDB.Options; using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-configured") .WithSettings(new SlateDbSettings { CompressionCodec = CompressionCodec.Zstd, FlushInterval = TimeSpan.FromSeconds(5), WalEnabled = true, L0SstSizeBytes = 64 * 1024 * 1024, // 64MB SST files MaxUnflushedBytes = 128 * 1024 * 1024, CompactorOptions = new CompactorOptions { PollInterval = TimeSpan.FromSeconds(10), MaxSstSize = 128 * 1024 * 1024, MaxConcurrentCompactions = 4 }, CacheOptions = new CacheOptions { RootFolder = "/tmp/slatedb-cache", MaxCacheSizeBytes = 512 * 1024 * 1024 }, DefaultTtlMs = 3600000 // 1 hour default TTL }) .Build(); db.Put("config-test", "working"); Console.WriteLine(db.GetString("config-test")); // Output: working ``` -------------------------------- ### Open Database with URL (C#) Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt Shows how to open a SlateDB database connection using a URL string. This simplifies configuration for local filesystem storage or cloud storage where credentials can be inferred from environment variables (e.g., AWS_*). ```csharp using Pulsy.SlateDB; // Local filesystem storage using var localDb = SlateDb.Builder("my-db", "file:///tmp/slatedb-data").Build(); // S3 storage (uses AWS_* environment variables for credentials) using var s3Db = SlateDb.Builder("my-db", "s3://my-bucket/prefix").Build(); localDb.Put("key", "value"); Console.WriteLine(localDb.GetString("key")); // Output: value ``` -------------------------------- ### Initialize and Use SlateDB for Session Management in C# Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt This C# code initializes SlateDB with specific configurations for a session database, demonstrates storing user sessions and profiles, performing batch updates for user activity, retrieving session data, scanning user-related keys, and cleaning up session data. It uses `ObjectStoreConfig` for MinIO integration and `SlateDbSettings` for performance tuning. ```csharp using System.Text.Json; using Pulsy.SlateDB; using Pulsy.SlateDB.Options; // Initialize logging SlateDb.InitLogging(LogLevel.Info); // Open database with full configuration using var db = SlateDb.Builder("sessions-db", new ObjectStoreConfig { Bucket = "app-data", Region = "us-east-1", Endpoint = "http://localhost:9000", AccessKeyId = "minioadmin", SecretAccessKey = "minioadmin", AllowHttp = true }) .WithSettings(new SlateDbSettings { CompressionCodec = CompressionCodec.Lz4, FlushInterval = TimeSpan.FromSeconds(5), DefaultTtlMs = (ulong)TimeSpan.FromHours(24).TotalMilliseconds }) .Build(); // Create user session var session = new { UserId = "user123", Token = "abc123", CreatedAt = DateTime.UtcNow }; string sessionJson = JsonSerializer.Serialize(session); db.Put("session:abc123", sessionJson, PutOptions.ExpireAfter(TimeSpan.FromHours(1)), WriteOptions.Default); // Store user profile (permanent) db.Put("user:user123:profile", "{\"name\":\"Alice\",\"role\":\"admin\"}", PutOptions.NoExpiry, WriteOptions.Default); // Batch update user activity using (var batch = SlateDb.NewWriteBatch()) { batch.Put("user:user123:lastLogin", DateTime.UtcNow.ToString("O")); batch.Put("user:user123:loginCount", 42); db.Write(batch); } // Retrieve session string? sessionData = db.GetString("session:abc123"); if (sessionData != null) { Console.WriteLine($"Session found: {sessionData}"); } // List all user data Console.WriteLine("\nUser data:"); using (var iterator = db.ScanPrefix("user:user123:")) { foreach (var kv in iterator) { Console.WriteLine($" {kv.KeyString} = {kv.ValueString}"); } } // Cleanup and flush db.Delete("session:abc123"); db.Flush(); Console.WriteLine("\nSession cleanup complete"); ``` -------------------------------- ### Configure Logging in C# Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt Shows how to initialize and configure logging for the SlateDB native library using `InitLogging`. This is crucial for debugging and monitoring internal operations. Logging levels can be set from Trace to Error, and it should be called before opening any database instances. Requires Pulsy.SlateDB and Pulsy.SlateDB.Options. ```csharp using Pulsy.SlateDB; using Pulsy.SlateDB.Options; // Initialize logging before opening any database // Log levels: Trace, Debug, Info, Warn, Error SlateDb.InitLogging(LogLevel.Info); using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-logging").Build(); db.Put("test", "value"); // Logs will now appear showing internal operations // For production, use Warn or Error // SlateDb.InitLogging(LogLevel.Warn); // For debugging, use Debug or Trace // SlateDb.InitLogging(LogLevel.Debug); ``` -------------------------------- ### Build SlateDB .NET Native Binaries Source: https://github.com/pulsy-global/slatedb-dotnet/blob/master/README.md Builds the native SlateDB binaries for the current platform or all supported platforms. Requires .NET 9 SDK, Rust nightly, and optionally zig + cargo-zigbuild for cross-platform builds. ```bash ./build-native.sh # current platform ./build-native.sh --all # all 6 platforms dotnet build Pulsy.SlateDB/Pulsy.SlateDB.csproj dotnet test ``` -------------------------------- ### Batch Write Operations in C# Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt This code snippet demonstrates the `SlateDbWriteBatch` class for atomic writes of multiple keys using Put and Delete operations. It shows how to create a batch, add operations, and execute them atomically, including setting TTLs within a batch. ```csharp using Pulsy.SlateDB; using Pulsy.SlateDB.Options; using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-batch").Build(); // Create a write batch for atomic operations using var batch = SlateDb.NewWriteBatch(); // Add multiple puts to the batch batch.Put("user:1:name", "Alice"); batch.Put("user:1:email", "alice@example.com"); batch.Put("user:1:role", "admin"); batch.Put("user:2:name", "Bob"); batch.Put("user:2:email", "bob@example.com"); batch.Put("user:2:role", "viewer"); // Delete in same batch batch.Delete("old-key"); // Put with TTL in batch batch.Put("session:xyz", "session-data", PutOptions.ExpireAfter(TimeSpan.FromMinutes(30))); // Execute all operations atomically db.Write(batch); // Or with write options // db.Write(batch, new WriteOptions { AwaitDurable = true }); Console.WriteLine(db.GetString("user:1:name")); // Output: Alice Console.WriteLine(db.GetString("user:2:role")); // Output: viewer ``` -------------------------------- ### Put Operations for Various Data Types (C#) Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt Demonstrates the `Put` method in SlateDB .NET for storing different data types, including strings, numeric primitives, booleans, and raw byte arrays. This covers basic data insertion into the key-value store. ```csharp using System.Text; using Pulsy.SlateDB; using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-put").Build(); // String values db.Put("username", "alice"); db.Put("email", "alice@example.com"); // Numeric values db.Put("age", 30); db.Put("balance", 1000.50); db.Put("active", true); // Raw byte arrays db.Put("binary-data", Encoding.UTF8.GetBytes("raw bytes")); Console.WriteLine(db.GetString("username")); // Output: alice Console.WriteLine(db.Get("age")); // Output: 30 Console.WriteLine(db.Get("balance")); // Output: 1000.5 Console.WriteLine(db.Get("active")); // Output: True ``` -------------------------------- ### Open Read-Only Database Reader in C# Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt Demonstrates how to open a read-only SlateDB database reader. This is useful for analytics or replication scenarios where data modification is not intended. It requires the Pulsy.SlateDB and Pulsy.SlateDB.Options namespaces. The reader can be opened concurrently with a writer. ```csharp using Pulsy.SlateDB; using Pulsy.SlateDB.Options; // First, create and populate a database using (var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-reader").Build()) { db.Put("user:alice", "admin"); db.Put("user:bob", "viewer"); db.Put("user:charlie", "editor"); db.Flush(); // Ensure data is persisted } // Open read-only reader (separate process or concurrent access) using var reader = SlateDb.OpenReader( path: "my-db", url: "file:///tmp/slatedb-reader", envFile: null, checkpointId: null, // Use latest checkpoint options: new ReaderOptions { ManifestPollInterval = TimeSpan.FromSeconds(1), CheckpointLifetime = TimeSpan.FromMinutes(10), SkipWalReplay = false }); // Read operations Console.WriteLine(reader.GetString("user:alice")); // Output: admin Console.WriteLine(reader.Get("nonexistent") ?? 0); // Output: 0 // Scan with reader Console.WriteLine("\nAll users via reader:"); using (var iterator = reader.ScanPrefix("user:")) { foreach (var kv in iterator) { Console.WriteLine($" {kv.KeyString} = {kv.ValueString}"); } } // Output: // user:alice = admin // user:bob = viewer // user:charlie = editor ``` -------------------------------- ### Delete Operations in C# Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt This code snippet demonstrates the `Delete` method to remove keys from the database, including optional durability settings. It shows how to perform simple deletes and deletes with durability options. ```csharp using Pulsy.SlateDB; using Pulsy.SlateDB.Options; using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-delete").Build(); db.Put("temp1", "value1"); db.Put("temp2", "value2"); db.Put("keep", "important"); Console.WriteLine(db.GetString("temp1") ?? "null"); // Output: value1 // Simple delete db.Delete("temp1"); Console.WriteLine(db.GetString("temp1") ?? "null"); // Output: null // Delete with durability option (wait for remote persistence) db.Delete("temp2", new WriteOptions { AwaitDurable = true }); Console.WriteLine(db.GetString("temp2") ?? "null"); // Output: null Console.WriteLine(db.GetString("keep") ?? "null"); // Output: important ``` -------------------------------- ### Perform Prefix Scans in Slatedb .NET Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt The ScanPrefix method iterates over all key-value pairs matching a given key prefix. This is useful for accessing hierarchical data structures stored in the database. It returns an iterator to traverse the matching entries. ```csharp using Pulsy.SlateDB; using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-prefix").Build(); // Populate hierarchical data using var batch = SlateDb.NewWriteBatch(); batch.Put("users:alice:name", "Alice Smith"); batch.Put("users:alice:email", "alice@example.com"); batch.Put("users:bob:name", "Bob Jones"); batch.Put("users:bob:email", "bob@example.com"); batch.Put("orders:1001", "order-data-1"); batch.Put("orders:1002", "order-data-2"); db.Write(batch); // Scan all users Console.WriteLine("All users:"); using (var iterator = db.ScanPrefix("users:")) { foreach (var kv in iterator) { Console.WriteLine($" {kv.KeyString} = {kv.ValueString}"); } } // Output: // users:alice:email = alice@example.com // users:alice:name = Alice Smith // users:bob:email = bob@example.com // users:bob:name = Bob Jones // Scan specific user's data Console.WriteLine("\nAlice's data:"); using (var iterator = db.ScanPrefix("users:alice:")) { foreach (var kv in iterator) { Console.WriteLine($" {kv.KeyString} = {kv.ValueString}"); } } // Output: // users:alice:email = alice@example.com // users:alice:name = Alice Smith // Scan orders Console.WriteLine("\nAll orders:"); using (var iterator = db.ScanPrefix("orders:")) { foreach (var kv in iterator) { Console.WriteLine($" {kv.KeyString} = {kv.ValueString}"); } } // Output: // orders:1001 = order-data-1 // orders:1002 = order-data-2 ``` -------------------------------- ### Reposition Scan Iterator with Seek in Slatedb .NET Source: https://context7.com/pulsy-global/slatedb-dotnet/llms.txt The Seek method repositions a scan iterator to a specific key position within the current scan range. This allows for efficient navigation within a dataset without restarting the scan. It's particularly useful when you need to jump to a particular point in the data. ```csharp using Pulsy.SlateDB; using var db = SlateDb.Builder("my-db", "file:///tmp/slatedb-seek").Build(); // Populate data for (int i = 1; i <= 10; i++) { db.Put($"item:{i:D3}", $"value-{i}"); } using var iterator = db.Scan("item:001", "item:999"); // Read first two items Console.WriteLine("First two items:"); Console.WriteLine($" {iterator.Next()?.KeyString}"); // item:001 Console.WriteLine($" {iterator.Next()?.KeyString}"); // item:002 // Seek to item:007 iterator.Seek("item:007"); Console.WriteLine("\nAfter seeking to item:007:"); Console.WriteLine($" {iterator.Next()?.KeyString}"); // item:007 Console.WriteLine($" {iterator.Next()?.KeyString}"); // item:008 // Seek back to item:004 iterator.Seek("item:004"); Console.WriteLine("\nAfter seeking back to item:004:"); Console.WriteLine($" {iterator.Next()?.KeyString}"); // item:004 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.