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
AliasedFieldProvides support for@dynamicMemberLookupto continue descending through arbitrary levels of nested projected properties values.BooleanPropertyA Fluent model property which represents a boolean (true/false) value.ChildrenPropertyCompositeChildrenPropertyDeclares a many-to-one relation between the referenced (“child”) model and the referencing (“parent”) model, where the parent model specifies its ID withCompositeIDProperty.CompositeIDPropertyCompositeOptionalChildPropertyDeclares an optional one-to-one relation between the referenced (“child”) model and the referencing (“parent”) model, where the parent model specifies its ID withCompositeIDProperty.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.CompositeParentPropertyDeclares a one-to-many relation between the referenced (“parent”) model and the referencing (“child”) model, where the parent model specifies its ID withCompositeIDProperty.DatabasesEnumBuilderEnumPropertyFieldPropertyGroupPropertyGroupPropertyPathIDPropertyMigrationLogStores information aboutMigrations that have been run.MigrationsOptionalBooleanPropertyA Fluent model property which represents an optional boolean (true/false) value.OptionalChildPropertyOptionalEnumPropertyOptionalFieldPropertyOptionalParentPropertyParentPropertyQueryBuilderQueryHistoryHolds the history of queries for a database.SchemaBuilderSiblingsPropertyTimestampProperty
Protocols
AnyAsyncModelResponderAnyCodablePropertyMarks 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.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.AnyEagerLoaderAnyModelAnyModelMiddlewareAnyModelResponderAnyOptionalTypeAnyPropertyThe 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.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.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.AsyncMigrationAsyncModelMiddlewareBooleanPropertyFormatA conversion betweenBooland an arbitrary alternative storage format, usually a string.DatabaseDatabaseConfigurationDatabaseDriverDatabaseErrorDatabaseInputA helper type for working with properties which conform to theAnyDatabasePropertyprotocol.DatabaseOutputEagerLoadBuilderEagerLoadableEagerLoaderFieldsA 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.MigrationFluent’sMigrationcan handle database migrations, which can include adding new table, changing existing tables or adding seed data. These actions are executed only once.ModelModelAliasDescribes a model whose schema has an alias.ModelMiddlewareOptionalTypePropertyA 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.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.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).RandomGeneratableRelationA protocol which designates a conforming type as representing a database relation of any kind. Intended for use only by FluentKit property wrappers.SchemaTimestampFormatTransactionControlDatabaseProtocol for describing a database that allows fine-grained control over transcactions when you need more control than provided byDatabase/transaction(_:)-1x3ds
Structures
BooleanPropertyFormatFactoryThis is a workaround for Swift 5.4’s inability to correctly infer the format type using theSelfconstraints on the various static properties.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.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.DatabaseConfigurationFactoryDatabaseContextDatabaseEnumDatabaseIDDatabaseQueryDatabaseSchemaDefaultBooleanPropertyFormatRepresent aBoolnatively, using the database’s underlying support (if any). This is the default.DefaultTimestampFormatISO8601TimestampFormatIntegerBooleanPropertyFormatRepresent aBoolas any integer type. Any value other than0or1is considered invalid.JoinFilterMigratorModelCompositeIDFilterModelFieldFilterModelValueFilterNestedEagerLoadBuilderOnOffBooleanPropertyFormatRepresent aBoolas the strings “OFF” and “ON”. Parsing is case-insensitive. Serialization always stores uppercase.OneZeroBooleanPropertyFormatRepresent aBoolas the strings “0” and “1”. Any other value is considered invalid.PageA single section of a larger, traversable result set.PageMetadataMetadata for a givenPage.PageRequestRepresents information needed to generate aPagefrom the full result set.TimestampFormatFactoryTrueFalseBooleanPropertyFormatRepresent aBoolas the strings “false” and “true”. Parsing is case-insensitive. Serialization always stores lowercase.UnixTimestampFormatYNBooleanPropertyFormatRepresent aBoolas the strings “N” and “Y”. Parsing is case-insensitive. Serialization always stores uppercase.YesNoBooleanPropertyFormatRepresent aBoolas the strings “NO” and “YES”. Parsing is case-insensitive. Serialization always stores uppercase.
Operators
!=(_:_:)!=~(_:_:)!~(_:_:)!~=(_:_:)&&(_:_:)a ==/!= b && c ==/!= d==(_:_:)=~(_:_:)<(_:_:)>(_:_:)>=(_:_:)<=(_:_:)~=(_:_:)~~(_:_:)
Enumerations
CompositeRelationParentKeyA helper type used byCompositeChildrenPropertyandCompositeOptionalChildPropertyto generically track the keypath of the property of the child model that defines the parent-child relationship.FieldKeyFluentErrorKeyPrefixingStrategyA strategy describing how to apply a prefix to aFieldKey.MiddlewareFailureHandlerModelEventRelationParentKeyA helper type used byChildrenPropertyandOptionalChildPropertyto generically track the keypath of the property of the child model that defines the parent-child relationship.SiblingsPropertyErrorAn error describing a failure during an an operation on anSiblingsProperty.TimestampTrigger