Framework
FluentKit
FluentKit is an ORM framework for Swift. It allows you to write type safe, database agnostic models and queries. It takes advantage of Swift’s type system to provide a powerful, yet easy to use API.
Overview
An example query looks like:
let planets = try await Planet.query(on: database)
.filter(\.$type == .gasGiant)
.sort(\.$name)
.with(\.$star)
.all()
For more information, see the Fluent documentation.
Topics
Classes
class AliasedFieldProvides support for@dynamicMemberLookupto continue descending through arbitrary levels of nested projected properties values.class BooleanPropertyA Fluent model property which represents a boolean (true/false) value.class ChildrenPropertyclass CompositeChildrenPropertyDeclares a many-to-one relation between the referenced (“child”) model and the referencing (“parent”) model, where the parent model specifies its ID withCompositeIDProperty.class CompositeIDPropertyclass CompositeOptionalChildPropertyDeclares an optional one-to-one relation between the referenced (“child”) model and the referencing (“parent”) model, where the parent model specifies its ID withCompositeIDProperty.class CompositeOptionalParentPropertyDeclares an optional one-to-many relation between the referenced (“parent”) model and the referencing (“child”) model, where the parent model specifies its ID withCompositeIDProperty.class CompositeParentPropertyDeclares a one-to-many relation between the referenced (“parent”) model and the referencing (“child”) model, where the parent model specifies its ID withCompositeIDProperty.class Databasesclass EnumBuilderclass EnumPropertyclass FieldPropertyclass GroupPropertyclass GroupPropertyPathclass IDPropertyclass MigrationLogStores information aboutMigrations that have been run.class Migrationsclass OptionalBooleanPropertyA Fluent model property which represents an optional boolean (true/false) value.class OptionalChildPropertyclass OptionalEnumPropertyclass OptionalFieldPropertyclass OptionalParentPropertyclass ParentPropertyclass QueryBuilderclass QueryHistoryHolds the history of queries for a database.class SchemaBuilderclass SiblingsPropertyclass TimestampProperty
Protocols
protocol AnyAsyncModelResponderprotocol AnyCodablePropertyMarks a property as participating in theFieldsprotocol’s (defaulted) implementation ofDecodableandEncodable. This allows the property to encode and decode to and from representations other than storage in a database, and to act as a container if it contains any additional properties which also wish to participate. Just about every property type is codable.protocol AnyDatabasePropertyMarks a property as having “database” capability - in other words, the property receives output from the results of read queries, provides input to write queries, and/or represents one or more model fields.protocol AnyEagerLoaderprotocol AnyModelprotocol AnyModelMiddlewareprotocol AnyModelResponderprotocol AnyOptionalTypeprotocol AnyPropertyThe type-erased form ofProperty(see below).AnyPropertyis used to access a model’s set of Fluent properties in a fully generic fashion (with a little help from runtime reflection). It is generally not meaningful to conform to this protocol without also at least conforming toProperty.protocol AnyQueryAddressablePropertyThe type-erased form ofQueryAddressableProperty(see below). Both protocols serve to bridge the gap betweenAnyQueryableProperty- which describes a property whose singularValuedirectly corresponds to the value stored in the database for that property - and property types whoseValueis a derivative of or expansion upon an underlying queryable property. See the discussion ofQueryAddressablePropertyitself for additional details.protocol AnyQueryablePropertyThe type-erased form ofQueryableProperty(see below).AnyQueryablePropertyis used most often as a type-generic check for whether or not a given property represents an actual database field.protocol AsyncMigrationprotocol AsyncModelMiddlewareprotocol BooleanPropertyFormatA conversion betweenBooland an arbitrary alternative storage format, usually a string.protocol Databaseprotocol DatabaseConfigurationprotocol DatabaseDriverprotocol DatabaseErrorprotocol DatabaseInputA helper type for working with properties which conform to theAnyDatabasePropertyprotocol.protocol DatabaseOutputprotocol EagerLoadBuilderprotocol EagerLoadableprotocol EagerLoaderprotocol FieldsA type conforming toFieldsis 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 MigrationFluent’sMigrationcan handle database migrations, which can include adding new table, changing existing tables or adding seed data. These actions are executed only once.protocol Modelprotocol ModelAliasDescribes a model whose schema has an alias.protocol ModelMiddlewareprotocol OptionalTypeprotocol PropertyA property wrapper type conforms to this protocol to participate in Fluent’s system for interfacing between the various properties of a model and the representations of those properties in a database. All properties whose wrappers conform to this protocol appear in Fluent’s list of the data items which exist on a given model - whether those items contain actual data, such as a property representing a field in a database table, or are means to access other data, such a list of associated models on the far side of a many-to-many relation.protocol QueryAddressablePropertyMarks a property as being “query addressable”, meaning that it is either itself queryable (QueryablePropertyimpliesQueryAddressableProperty), or it represents some other single property that is queryable. This allows properties whose purpose is to wrap or otherwise stand in for other properties to be handled generically without the need to add special case exceptions for those property types.protocol QueryablePropertyMarks a property as being “queryable”, meaning that it represents exactly one “real” database field (i.e. the database table will contain a “physical” field corresponding to the property, and it will be the only field that does so).protocol RandomGeneratableprotocol RelationA protocol which designates a conforming type as representing a database relation of any kind. Intended for use only by FluentKit property wrappers.protocol Schemaprotocol TimestampFormatprotocol TransactionControlDatabaseProtocol for describing a database that allows fine-grained control over transcactions when you need more control than provided byDatabase/transaction(_:)-1x3ds
Structures
struct BooleanPropertyFormatFactoryThis is a workaround for Swift 5.4’s inability to correctly infer the format type using theSelfconstraints on the various static properties.struct ComplexJoinFilterThis wrapper type allows the compiler to better constrain the overload set for global operators, reducing compile times and avoiding “this expression is too complex…” errors.struct ComplexJoinFilterGroupThis wrapper type allows the compiler to better constrain the overload set for global operators, reducing compile times and avoiding “this expression is too complex…” errors.struct DatabaseConfigurationFactorystruct DatabaseContextstruct DatabaseEnumstruct DatabaseIDstruct DatabaseQuerystruct DatabaseSchemastruct DefaultBooleanPropertyFormatRepresent aBoolnatively, using the database’s underlying support (if any). This is the default.struct DefaultTimestampFormatstruct ISO8601TimestampFormatstruct IntegerBooleanPropertyFormatRepresent aBoolas any integer type. Any value other than0or1is considered invalid.struct JoinFilterstruct Migratorstruct ModelCompositeIDFilterstruct ModelFieldFilterstruct ModelValueFilterstruct NestedEagerLoadBuilderstruct OnOffBooleanPropertyFormatRepresent aBoolas the strings “OFF” and “ON”. Parsing is case-insensitive. Serialization always stores uppercase.struct OneZeroBooleanPropertyFormatRepresent aBoolas the strings “0” and “1”. Any other value is considered invalid.struct PageA single section of a larger, traversable result set.struct PageMetadataMetadata for a givenPage.struct PageRequestRepresents information needed to generate aPagefrom the full result set.struct TimestampFormatFactorystruct TrueFalseBooleanPropertyFormatRepresent aBoolas the strings “false” and “true”. Parsing is case-insensitive. Serialization always stores lowercase.struct UnixTimestampFormatstruct YNBooleanPropertyFormatRepresent aBoolas the strings “N” and “Y”. Parsing is case-insensitive. Serialization always stores uppercase.struct YesNoBooleanPropertyFormatRepresent aBoolas the strings “NO” and “YES”. Parsing is case-insensitive. Serialization always stores uppercase.
Operators
func !=(_:_:)func !=~(_:_:)func !~(_:_:)func !~=(_:_:)func &&(_:_:)a ==/!= b && c ==/!= dfunc ==(_:_:)func =~(_:_:)func <(_:_:)func >(_:_:)func >=(_:_:)func <=(_:_:)func ~=(_:_:)func ~~(_:_:)
Enumerations
enum CompositeRelationParentKeyA helper type used byCompositeChildrenPropertyandCompositeOptionalChildPropertyto generically track the keypath of the property of the child model that defines the parent-child relationship.enum FieldKeyenum FluentErrorenum KeyPrefixingStrategyA strategy describing how to apply a prefix to aFieldKey.enum MiddlewareFailureHandlerenum ModelEventenum RelationParentKeyA helper type used byChildrenPropertyandOptionalChildPropertyto generically track the keypath of the property of the child model that defines the parent-child relationship.enum SiblingsPropertyErrorAn error describing a failure during an an operation on anSiblingsProperty.enum TimestampTrigger