Skip to content

Protocol

Fields

A type conforming to Fields is able to use FluentKit’s various property wrappers to declare name, type, and semantic information for individual properties corresponding to fields in a generic database storage system.
protocol Fields : AnyObject, Decodable, Encodable, Sendable

Overview

Fields is usually only used directly when in conjunction with the @Group and @CompositeID property types. The Schema and Model protocols build on Fields to provide additional capabilities and semantics.

Most of the protocol requirements of Fields are implemented in FluentKit. A conformant type needs only to provide the definition of init(), which will in turn almost always be empty. (In fact, FluentKit would provide this implementation as well if the language permitted.) Providing custom implementations of any other requirements is strongly discouraged; under most circumstances, such implementations will not be invoked in any event. They are only declared on the base protocol rather than solely in extensions because static dispatch improves performance.

Topics

Initializers

Instance Properties

  • var hasChanges: Bool
    Returns true if a model has fields whose values have been explicitly set or modified since the most recent load from and/or save to the database (if any).
  • var properties: [any AnyProperty]
    Returns a fully generic list of every property on the given instance of the type which uses any of the FluentKit property wrapper types (e.g. any wrapper conforming to AnyProperty). This accessor is not static because FluentKit depends upon access to the backing storage of the property wrappers, which is specific to each instance.

Instance Methods

  • func input(to: any DatabaseInput)
    For each property declared on the type, if that property is marked as having changed since the type was either loaded or created, add the key-value pair for said property to the given database input object. This prepares data in memory to be written to the database.
  • func output(from: any DatabaseOutput) throws
    For each property declared on the type, if that property’s key is available in the given database output object, attempt to load the corresponding value into the property. This transfers data received from the database into memory.

Type Aliases

Type Properties

  • static var keys: [FieldKey]
    Return an array of all database keys (i.e. non-nested field names) defined by all properties declared on the type. This includes properties which may contain multiple fields at once, such as @Group.

Type Methods

Default Implementations

Relationships

Inherits From

  • Swift.Decodable
  • Swift.Encodable
  • Swift.Sendable
  • Swift.SendableMetatype

Inherited By

Conforming Types