-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathPersistable_AnyWithValueMetadata.swift
More file actions
62 lines (51 loc) · 2.01 KB
/
Persistable_AnyWithValueMetadata.swift
File metadata and controls
62 lines (51 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// Persistable_AnyWithValueMetadata.swift
// YapDatabaseExtensions
//
// Created by Daniel Thorpe on 13/10/2015.
//
//
import Foundation
import ValueCoding
// MARK: - Readable
extension Readable where
ItemType: Persistable,
ItemType.MetadataType: ValueCoding,
ItemType.MetadataType.Coder: NSCoding,
ItemType.MetadataType.Coder.ValueType == ItemType.MetadataType {
func metadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType.MetadataType? {
return transaction.readMetadataAtIndex(index)
}
func metadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> ItemType.MetadataType? {
return { self.metadataInTransaction($0, atIndex: index) }
}
func metadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> ItemType.MetadataType? {
return { self.metadataInTransaction(transaction, atIndex: $0) }
}
func metadataAtIndexesInTransaction<
Indexes where
Indexes: SequenceType,
Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [ItemType.MetadataType] {
let atIndex = metadataInTransactionAtIndex
return { indexes.flatMap(atIndex($0)) }
}
/**
Reads the metadata at a given index.
- parameter index: a YapDB.Index
- returns: an optional `ItemType.MetadataType`
*/
public func metadataAtIndex(index: YapDB.Index) -> ItemType.MetadataType? {
return sync(metadataAtIndexInTransaction(index))
}
/**
Reads the metadata at the indexes.
- parameter indexes: a SequenceType of YapDB.Index values
- returns: an array of `ItemType.MetadataType`
*/
public func metadataAtIndexes<
Indexes where
Indexes: SequenceType,
Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> [ItemType.MetadataType] {
return sync(metadataAtIndexesInTransaction(indexes))
}
}