mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Cleanup
This commit is contained in:
1 parent
cdad6fa313
commit
264bceee2a
4 files changed
+47
-86
No files matched your search
@@ -1,10 +1,5 @@
|
||||
public struct BelongsToAssociation<Origin, Destination> : Association, TableRequest where
|
||||
Origin: TableRecord,
|
||||
Destination: TableRecord
|
||||
{
|
||||
fileprivate let foreignKeyRequest: ForeignKeyRequest
|
||||
|
||||
// Association conformance
|
||||
public struct BelongsToAssociation<Origin, Destination>: Association {
|
||||
fileprivate let joinConditionRequest: ForeignKeyJoinConditionRequest
|
||||
|
||||
/// :nodoc:
|
||||
public typealias OriginRowDecoder = Origin
|
||||
@@ -25,7 +20,7 @@ public struct BelongsToAssociation<Origin, Destination> : Association, TableRequ
|
||||
|
||||
/// :nodoc:
|
||||
public func joinCondition(_ db: Database) throws -> JoinCondition {
|
||||
return try ForeignKeyJoinConditionRequest(foreignKeyRequest: foreignKeyRequest, originIsLeft: true).fetch(db)
|
||||
return try joinConditionRequest.fetch(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@@ -34,17 +29,17 @@ public struct BelongsToAssociation<Origin, Destination> : Association, TableRequ
|
||||
association.request = transform(request)
|
||||
return association
|
||||
}
|
||||
|
||||
// TableRequest conformance
|
||||
|
||||
}
|
||||
|
||||
extension BelongsToAssociation: TableRequest where Destination: TableRecord {
|
||||
/// :nodoc:
|
||||
public var databaseTableName: String { return Destination.databaseTableName }
|
||||
}
|
||||
|
||||
extension TableRecord {
|
||||
// TODO: Make it public if and only if we really want to build an association from any request
|
||||
static func belongsTo<Destination>(
|
||||
_ request: QueryInterfaceRequest<Destination>,
|
||||
/// TODO
|
||||
public static func belongsTo<Destination>(
|
||||
_ destination: Destination.Type,
|
||||
key: String? = nil,
|
||||
using foreignKey: ForeignKey? = nil)
|
||||
-> BelongsToAssociation<Self, Destination>
|
||||
@@ -55,20 +50,13 @@ extension TableRecord {
|
||||
destinationTable: Destination.databaseTableName,
|
||||
foreignKey: foreignKey)
|
||||
|
||||
return BelongsToAssociation(
|
||||
let joinConditionRequest = ForeignKeyJoinConditionRequest(
|
||||
foreignKeyRequest: foreignKeyRequest,
|
||||
originIsLeft: true)
|
||||
|
||||
return BelongsToAssociation(
|
||||
joinConditionRequest: joinConditionRequest,
|
||||
key: key ?? Destination.databaseTableName,
|
||||
request: AssociationRequest(request))
|
||||
}
|
||||
|
||||
/// TODO
|
||||
public static func belongsTo<Destination>(
|
||||
_ destination: Destination.Type,
|
||||
key: String? = nil,
|
||||
using foreignKey: ForeignKey? = nil)
|
||||
-> BelongsToAssociation<Self, Destination>
|
||||
where Destination: TableRecord
|
||||
{
|
||||
return belongsTo(Destination.all(), key: key, using: foreignKey)
|
||||
request: AssociationRequest(Destination.all()))
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
public struct HasManyAssociation<Origin, Destination> : Association, TableRequest where
|
||||
Origin: TableRecord,
|
||||
Destination: TableRecord
|
||||
{
|
||||
fileprivate let foreignKeyRequest: ForeignKeyRequest
|
||||
|
||||
// Association conformance
|
||||
public struct HasManyAssociation<Origin, Destination>: Association {
|
||||
fileprivate let joinConditionRequest: ForeignKeyJoinConditionRequest
|
||||
|
||||
/// :nodoc:
|
||||
public typealias OriginRowDecoder = Origin
|
||||
@@ -25,7 +20,7 @@ public struct HasManyAssociation<Origin, Destination> : Association, TableReques
|
||||
|
||||
/// :nodoc:
|
||||
public func joinCondition(_ db: Database) throws -> JoinCondition {
|
||||
return try ForeignKeyJoinConditionRequest(foreignKeyRequest: foreignKeyRequest, originIsLeft: false).fetch(db)
|
||||
return try joinConditionRequest.fetch(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@@ -34,17 +29,17 @@ public struct HasManyAssociation<Origin, Destination> : Association, TableReques
|
||||
association.request = transform(request)
|
||||
return association
|
||||
}
|
||||
|
||||
// TableRequest conformance
|
||||
|
||||
}
|
||||
|
||||
extension HasManyAssociation: TableRequest where Destination: TableRecord {
|
||||
/// :nodoc:
|
||||
public var databaseTableName: String { return Destination.databaseTableName }
|
||||
}
|
||||
|
||||
extension TableRecord {
|
||||
// TODO: Make it public if and only if we really want to build an association from any request
|
||||
static func hasMany<Destination>(
|
||||
_ request: QueryInterfaceRequest<Destination>,
|
||||
/// TODO
|
||||
public static func hasMany<Destination>(
|
||||
_ destination: Destination.Type,
|
||||
key: String? = nil,
|
||||
using foreignKey: ForeignKey? = nil)
|
||||
-> HasManyAssociation<Self, Destination>
|
||||
@@ -55,20 +50,13 @@ extension TableRecord {
|
||||
destinationTable: databaseTableName,
|
||||
foreignKey: foreignKey)
|
||||
|
||||
return HasManyAssociation(
|
||||
let joinConditionRequest = ForeignKeyJoinConditionRequest(
|
||||
foreignKeyRequest: foreignKeyRequest,
|
||||
originIsLeft: false)
|
||||
|
||||
return HasManyAssociation(
|
||||
joinConditionRequest: joinConditionRequest,
|
||||
key: key ?? Destination.databaseTableName,
|
||||
request: AssociationRequest(request))
|
||||
}
|
||||
|
||||
/// TODO
|
||||
public static func hasMany<Destination>(
|
||||
_ destination: Destination.Type,
|
||||
key: String? = nil,
|
||||
using foreignKey: ForeignKey? = nil)
|
||||
-> HasManyAssociation<Self, Destination>
|
||||
where Destination: TableRecord
|
||||
{
|
||||
return hasMany(Destination.all(), key: key, using: foreignKey)
|
||||
request: AssociationRequest(Destination.all()))
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,6 @@
|
||||
public struct HasOneAssociation<Origin, Destination> : Association, TableRequest where
|
||||
Origin: TableRecord,
|
||||
Destination: TableRecord
|
||||
{
|
||||
fileprivate let foreignKeyRequest: ForeignKeyRequest
|
||||
|
||||
// Association conformance
|
||||
|
||||
public struct HasOneAssociation<Origin, Destination> : Association {
|
||||
fileprivate let joinConditionRequest: ForeignKeyJoinConditionRequest
|
||||
|
||||
/// :nodoc:
|
||||
public typealias OriginRowDecoder = Origin
|
||||
|
||||
@@ -25,7 +20,7 @@ public struct HasOneAssociation<Origin, Destination> : Association, TableRequest
|
||||
|
||||
/// :nodoc:
|
||||
public func joinCondition(_ db: Database) throws -> JoinCondition {
|
||||
return try ForeignKeyJoinConditionRequest(foreignKeyRequest: foreignKeyRequest, originIsLeft: false).fetch(db)
|
||||
return try joinConditionRequest.fetch(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@@ -34,17 +29,17 @@ public struct HasOneAssociation<Origin, Destination> : Association, TableRequest
|
||||
association.request = transform(request)
|
||||
return association
|
||||
}
|
||||
|
||||
// TableRequest conformance
|
||||
|
||||
}
|
||||
|
||||
extension HasOneAssociation: TableRequest where Destination: TableRecord {
|
||||
/// :nodoc:
|
||||
public var databaseTableName: String { return Destination.databaseTableName }
|
||||
}
|
||||
|
||||
extension TableRecord {
|
||||
// TODO: Make it public if and only if we really want to build an association from any request
|
||||
static func hasOne<Destination>(
|
||||
_ request: QueryInterfaceRequest<Destination>,
|
||||
/// TODO
|
||||
public static func hasOne<Destination>(
|
||||
_ destination: Destination.Type,
|
||||
key: String? = nil,
|
||||
using foreignKey: ForeignKey? = nil)
|
||||
-> HasOneAssociation<Self, Destination>
|
||||
@@ -55,20 +50,13 @@ extension TableRecord {
|
||||
destinationTable: databaseTableName,
|
||||
foreignKey: foreignKey)
|
||||
|
||||
return HasOneAssociation(
|
||||
let joinConditionRequest = ForeignKeyJoinConditionRequest(
|
||||
foreignKeyRequest: foreignKeyRequest,
|
||||
originIsLeft: false)
|
||||
|
||||
return HasOneAssociation(
|
||||
joinConditionRequest: joinConditionRequest,
|
||||
key: key ?? Destination.databaseTableName,
|
||||
request: AssociationRequest(request))
|
||||
}
|
||||
|
||||
/// TODO
|
||||
public static func hasOne<Destination>(
|
||||
_ destination: Destination.Type,
|
||||
key: String? = nil,
|
||||
using foreignKey: ForeignKey? = nil)
|
||||
-> HasOneAssociation<Self, Destination>
|
||||
where Destination: TableRecord
|
||||
{
|
||||
return hasOne(Destination.all(), key: key, using: foreignKey)
|
||||
request: AssociationRequest(Destination.all()))
|
||||
}
|
||||
}
|
||||
@@ -324,10 +324,7 @@ extension OrderedRequest {
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// The base protocol for all requests that can be refined:
|
||||
///
|
||||
/// extension DerivableRequest where RowDecoder: Player {
|
||||
/// }
|
||||
/// The base protocol for all requests that can be refined.
|
||||
public protocol DerivableRequest: SelectionRequest, FilteredRequest, OrderedRequest {
|
||||
associatedtype RowDecoder
|
||||
}
|
||||
Reference in new issue
Block a user