MutableModel

    The base specification of any readable Meow model, containing a collectionName and a _id. MutableModel must be implemented using Codable, and always implements ReadableModel. MutableModels can be saved, whereas Readableodels cannot

    Model.swift:98
    protocol MutableModel : ReadableModel, Encodable
    Browse conforming types

    Two models may share the same collection, allowing for constructions where both AdminUser

    Example:

    struct AnyUser: MutableModel {
        @Field var _id: ObjectId
        @Field var username: String
        @Field var role: Role
    
        // Populted only for admin users
        @Field var adminPowers: [AdminPrivilege]?
    }
    struct AdminUser: ReadableModel {
        let _id: ObjectId
        let username: String
        // Role is always admin for this model, so it's not decoded
        // Always populated
        let adminPowers: [AdminPrivilege]
    }
    struct User: ReadableModel {
        let _id: ObjectId
        let username: String
        @Field var role: Role
        // `adminPowers` are not relevant
    }

    All Meow models must have an identifier that is Codable and Hashable, as well as representable by a Primitive.

    When implementing PrimitiveEncodable using BSONEncoder, this allows you to use any struct as an _id so long as it’s not an “unkeyedContainer”. Array-like (sequence) types are rejected on insertion by MongoDB.

    Supertypes

    • protocol BaseModel

      The base specification of any Meow model, containing a collectionName and a _id

    • protocol Decodable

      A type that can decode itself from an external representation.

    • protocol Encodable

      A type that can encode itself to an external representation.

    • protocol ReadableModel

      The base specification of any readable Meow model, containing a collectionName and a _id. ReadableModel must be implemented using Decodable. ReadableModel is currently used for any entity that is queryable. MutableModels can be saved, whereas Readableodels cannot

    Requirements

    Type members

    Instance members

    Citizens in Meow

    Type members

    Instance members