Enumerations

The following enumerations are available globally.

  • Defines the supported key derivation algorithms for deriving database encryption keys from user-provided secrets.

    Choose the algorithm based on the entropy level of the secret:

    • PBKDF2: For low-entropy secrets such as user passwords. It applies a configurable number of iterations to slow down brute-force attacks.
    • HKDF: For high-entropy secrets such as random Keychain material. It is lightweight and does not need iteration counts.

    Both algorithms produce a 256-bit AES key suitable for use with DatabaseOptions.encryptionKey.

    See more

    Declaration

    Swift

    public enum KeyDerivationAlgorithm : Sendable
  • Provides cryptographic helpers for generating and deriving database encryption keys.

    Use NyaruCrypto to:

    1. Generate a random 256-bit AES key with generateRandomKey() (store the result in the iOS Keychain).
    2. Generate a random salt with generateSalt() (persist the salt alongside the database — it is not secret).
    3. Derive an encryption key from a password with deriveKey(fromPassword:salt:using:).

    The derived or generated key is then passed to DatabaseOptions as the encryptionKey parameter.

    See more

    Declaration

    Swift

    public enum NyaruCrypto
  • Represents all errors that can be thrown by NyaruDB operations.

    NyaruError covers storage corruption, document validation failures, collection lifecycle issues, compression errors, and cryptographic failures. Each case carries contextual information to aid debugging.

    Conforms to CustomStringConvertible to provide a human-readable description of each error case.

    See more

    Declaration

    Swift

    public enum NyaruError : Error, Sendable, CustomStringConvertible
  • Describes the strategy that QueryBuilder will use to execute a query.

    The strategy is determined by explain() based on the availability of indexes and partition key predicates. The query planner selects the most efficient access path automatically.

    See more

    Declaration

    Swift

    public enum QueryStrategy : Sendable, Equatable, CustomStringConvertible

Predicate Tree

  • A recursive predicate tree that represents complex boolean logic for filtering documents.

    Predicates can be combined with .and, .or, and .not to build arbitrary boolean expressions. Leaf predicates compare a document field against a value using operators such as equals, less-than, range, substring, and regex.

    The predicate tree is evaluated bottom-up by QueryBuilder.evaluate(_:in:), which walks the tree recursively for each candidate document.

    See more

    Declaration

    Swift

    public indirect enum Predicate : Sendable
  • Describes the compression method applied to record payloads in shard files.

    • gzip is the recommended method. It is implemented on top of zlib and is portable to every platform NyaruDB may target, including Android and Linux.
    • lzfse and lz4 use Apple’s Compression framework and are only available on Apple platforms. Using them ties the data files to Apple devices.

    The method is stored in the record header flags (bits 1-3) and is also persisted in the collection manifest so that every shard file can be decompressed independently of external configuration.

    See more

    Declaration

    Swift

    public enum CompressionMethod : String, CaseIterable, Codable, Sendable
  • Represents a scalar value extracted from a document field, providing a total ordering for use as an index key and in range queries.

    FieldValue bridges the gap between dynamically-typed document data (JSON or MessagePack) and the statically-typed index and query systems. Every value stored in an index is a FieldValue, and every predicate comparison operates on FieldValue instances.

    Total ordering. FieldValue guarantees a total order across all variants, which is essential for binary-search-based indexes and correct range-scan semantics. The ordering is defined first by type rank:

    null < bool < number < string
    

    Within the same type, values are ordered naturally. The int and double cases share the “number” rank and compare numerically against each other without lossy conversion through Double:

    • int(5) == double(5.0) — exact integer equality
    • int(2^60 + 1) != double(2^60) — no silent rounding

    ExpressibleBy literals. FieldValue conforms to ExpressibleByIntegerLiteral, ExpressibleByStringLiteral, ExpressibleByBooleanLiteral, ExpressibleByFloatLiteral, and ExpressibleByNilLiteral, allowing natural Swift syntax: let v: FieldValue = "hello".

    See more

    Declaration

    Swift

    public enum FieldValue: Codable, Sendable, CustomStringConvertible,
      ExpressibleByIntegerLiteral, ExpressibleByStringLiteral,
      ExpressibleByBooleanLiteral, ExpressibleByFloatLiteral,
      ExpressibleByNilLiteral
    extension FieldValue: Comparable
    extension FieldValue: Hashable
    extension FieldValue: FieldValueConvertible
  • Specifies the wire format used to serialize and deserialize documents.

    NyaruDB supports two formats:

    • .json: Standard JSON, produced and consumed by JSONEncoder/JSONDecoder.
    • .msgpack: MessagePack, a compact binary format, produced and consumed by MsgPackEncoder/MsgPackDecoder from the SwiftMsgpack package.

    The format is stored in the collection manifest and is immutable after collection creation — changing it would make existing records unreadable.

    See more

    Declaration

    Swift

    public enum SerializationFormat : String, CaseIterable, Codable, Sendable
  • Describes the file protection level applied to shard files on iOS.

    This is a no-op on non-Apple platforms. On iOS, the value is mapped to the corresponding Foundation.FileProtectionType and applied to every shard file at creation time.

    See more

    Declaration

    Swift

    public enum FileProtection : String, CaseIterable, Codable, Sendable