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
See moreDatabaseOptions.encryptionKey.Declaration
Swift
public enum KeyDerivationAlgorithm : Sendable -
Provides cryptographic helpers for generating and deriving database encryption keys.
Use
NyaruCryptoto:- Generate a random 256-bit AES key with
generateRandomKey()(store the result in the iOS Keychain). - Generate a random salt with
generateSalt()(persist the salt alongside the database — it is not secret). - Derive an encryption key from a password with
deriveKey(fromPassword:salt:using:).
The derived or generated key is then passed to
See moreDatabaseOptionsas theencryptionKeyparameter.Declaration
Swift
public enum NyaruCrypto - Generate a random 256-bit AES key with
-
Represents all errors that can be thrown by NyaruDB operations.
NyaruErrorcovers storage corruption, document validation failures, collection lifecycle issues, compression errors, and cryptographic failures. Each case carries contextual information to aid debugging.Conforms to
See moreCustomStringConvertibleto provide a human-readable description of each error case.Declaration
Swift
public enum NyaruError : Error, Sendable, CustomStringConvertible -
Describes the strategy that
QueryBuilderwill use to execute a query.The strategy is determined by
See moreexplain()based on the availability of indexes and partition key predicates. The query planner selects the most efficient access path automatically.Declaration
Swift
public enum QueryStrategy : Sendable, Equatable, CustomStringConvertible
-
A recursive predicate tree that represents complex boolean logic for filtering documents.
Predicates can be combined with
.and,.or, and.notto 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
See moreQueryBuilder.evaluate(_:in:), which walks the tree recursively for each candidate document.Declaration
Swift
public indirect enum Predicate : Sendable -
Describes the compression method applied to record payloads in shard files.
gzipis the recommended method. It is implemented on top of zlib and is portable to every platform NyaruDB may target, including Android and Linux.lzfseandlz4use 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 moreDeclaration
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.
FieldValuebridges 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 aFieldValue, and every predicate comparison operates onFieldValueinstances.Total ordering.
FieldValueguarantees 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 < stringWithin the same type, values are ordered naturally. The
intanddoublecases share the “number” rank and compare numerically against each other without lossy conversion throughDouble:int(5) == double(5.0)— exact integer equalityint(2^60 + 1) != double(2^60)— no silent rounding
ExpressibleBy literals.
See moreFieldValueconforms toExpressibleByIntegerLiteral,ExpressibleByStringLiteral,ExpressibleByBooleanLiteral,ExpressibleByFloatLiteral, andExpressibleByNilLiteral, allowing natural Swift syntax:let v: FieldValue = "hello".Declaration
Swift
public enum FieldValue: Codable, Sendable, CustomStringConvertible, ExpressibleByIntegerLiteral, ExpressibleByStringLiteral, ExpressibleByBooleanLiteral, ExpressibleByFloatLiteral, ExpressibleByNilLiteralextension FieldValue: Comparableextension FieldValue: Hashableextension FieldValue: FieldValueConvertible -
Specifies the wire format used to serialize and deserialize documents.
NyaruDB supports two formats:
.json: Standard JSON, produced and consumed byJSONEncoder/JSONDecoder..msgpack: MessagePack, a compact binary format, produced and consumed byMsgPackEncoder/MsgPackDecoderfrom 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 moreDeclaration
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
See moreFoundation.FileProtectionTypeand applied to every shard file at creation time.Declaration
Swift
public enum FileProtection : String, CaseIterable, Codable, Sendable
View on GitHub
Enumerations Reference