Skip to content

Commit

Permalink
Intro TypedKey and TypedProperty
Browse files Browse the repository at this point in the history
Those are `Key`s and `Property`s that statically know the value type
they refer too. For example `CodeAttribute`'s.
  • Loading branch information
helje5 committed Dec 8, 2024
1 parent 75e1c87 commit d57a158
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/ZeeQL/Access/CodeAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Their primary feature over `ModelAttribute`s is that such are generic over
* the value type.
*/
open class CodeAttribute<T: AttributeValue> : ModelAttribute {
open class CodeAttribute<T: AttributeValue> : ModelAttribute, TypedProperty {

// Note: we remove the keyword
@inlinable
Expand Down
5 changes: 4 additions & 1 deletion Sources/ZeeQL/Access/CodeRelationship.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ open class CodeRelationshipBase<Target: SwiftObject>
}

open class CodeRelationship<Target: DatabaseObject>
: CodeRelationshipBase<Target>, CodeRelationshipType
: CodeRelationshipBase<Target>, CodeRelationshipType,
TypedProperty
{
public typealias T = Target

public var codeEntity : Entity? = nil
override open var entity : Entity {
set {
Expand Down
12 changes: 10 additions & 2 deletions Sources/ZeeQL/Access/Property.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// ZeeQL
//
// Created by Helge Heß on 18.02.17.
// Copyright © 2017-2021 ZeeZide GmbH. All rights reserved.
// Copyright © 2017-2024 ZeeZide GmbH. All rights reserved.
//

/**
* A property of an `Entity`: Either an `Attribute` or a `Relationship`.
* A property of an ``Entity``: Either an ``Attribute`` or a ``Relationship``.
*/
public protocol Property : AnyObject, EquatableType {
// `class` because we use identity in some places
Expand All @@ -16,3 +16,11 @@ public protocol Property : AnyObject, EquatableType {
var relationshipPath : String? { get }

}

/**
* A property of an ``Entity``: Either an ``Attribute`` or a ``Relationship``,
* that knows the static type of the property.
*/
public protocol TypedProperty<T>: Property {
associatedtype T
}
4 changes: 4 additions & 0 deletions Sources/ZeeQL/Control/Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public protocol Key : Expression, ExpressionEvaluation, EquatableType,
func append(_ key: Key) -> Key
}

public protocol TypedKey<T>: Key {
associatedtype T
}

public extension Key {

// MARK: - value
Expand Down

0 comments on commit d57a158

Please sign in to comment.