public Get ( |
||
db | Database | |
key | byte | Key byte array. |
Résultat | byte[] |
public static TValue Get <TKey, TValue>(this LightningTransaction txn, LightningDatabase db, TKey key) { var keyBytes = db.ToBytes(key); var valueBytes = txn.Get(db, keyBytes); return(db.FromBytes <TValue>(valueBytes)); }
public static bool TryGet(this LightningTransaction tx, LightningDatabase db, ReadOnlySpan <byte> key, out byte[] value) { var(resultCode, _, mdbValue) = tx.Get(db, key); if (resultCode == MDBResultCode.Success) { value = mdbValue.CopyToNewArray(); return(true); } value = default; return(false); }
public static bool TryGet(this LightningTransaction tx, LightningDatabase db, ReadOnlySpan <byte> key, byte[] destinationValueBuffer) { var(resultCode, _, mdbValue) = tx.Get(db, key); if (resultCode != MDBResultCode.Success) { return(false); } var valueSpan = mdbValue.AsSpan(); if (valueSpan.TryCopyTo(destinationValueBuffer)) { return(true); } throw new LightningException("Incorrect buffer size given in destinationValueBuffer", (int)MDBResultCode.BadValSize); }
public static byte[] GetRawValue <TKey>(this LightningTransaction txn, LightningDatabase db, TKey key) { var keyBytes = db.ToBytes(key); return(txn.Get(db, keyBytes)); }
public static TType Get <TType>(this LightningTransaction txn, LightningDatabase db, TType key) { return(txn.Get <TType, TType>(db, key)); }
public static bool ContainsKey(this LightningTransaction tx, LightningDatabase db, ReadOnlySpan <byte> key) { var(resultCode, _, _) = tx.Get(db, key); return(resultCode == MDBResultCode.Success); }
/// <summary> /// Gets a value by its key. /// </summary> /// <typeparam name="TKey">Key type.</typeparam> /// <typeparam name="TValue">Value type.</typeparam> /// <param name="txn">Transaction.</param> /// <param name="key">Key.</param> /// <returns>Value or default(TValue) if not exists.</returns> public static TValue Get <TKey, TValue>(this LightningTransaction txn, TKey key) { return(txn.Get <TKey, TValue>(txn.OpenDatabase(), key)); }
/// <summary> /// Gets and converts a value by its key for key-value pairs of a single type. /// </summary> /// <typeparam name="TType">Key and value type.</typeparam> /// <param name="txn">Transaction.</param> /// <param name="key">Key.</param> /// <returns>Value or default(TType) if not exists.</returns> public static TType Get <TType>(this LightningTransaction txn, TType key) { return(txn.Get(txn.OpenDatabase(), key)); }
/// <summary> /// Get value from a database. /// </summary> /// <param name="txn">A transaction</param> /// <param name="key">Key byte array.</param> /// <returns>Requested value's byte array if exists, or null if not.</returns> public static byte[] Get(this LightningTransaction txn, byte[] key) { return(txn.Get(txn.OpenDatabase(), key)); }