mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
Back to block-based database accesses.
Rationale: https://medium.com/@gwendal.roue/four-different-ways-to-handle-sqlite-concurrency-db3bcc74d00e
This commit is contained in:
1 parent
783da0c45d
commit
4bcff181c7
34 files changed
+504
-2457
No files matched your search
@@ -133,28 +133,25 @@
|
||||
560FC56B1CB00B880014AA8E /* CollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A50C61BFF4B7F00B3A3A2 /* CollationTests.swift */; };
|
||||
560FC56C1CB00B880014AA8E /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238221B9C74A90082EB20 /* UpdateStatementTests.swift */; };
|
||||
560FC56D1CB00B880014AA8E /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */; };
|
||||
560FC56E1CB00B880014AA8E /* DatabasePoolPersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AC1C933FF8000BE133 /* DatabasePoolPersistableTests.swift */; };
|
||||
560FC56F1CB00B880014AA8E /* RecordAwakeFromFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238301B9C74A90082EB20 /* RecordAwakeFromFetchTests.swift */; };
|
||||
560FC5701CB00B880014AA8E /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */; };
|
||||
560FC5711CB00B880014AA8E /* PrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382B1B9C74A90082EB20 /* PrimaryKeySingleTests.swift */; };
|
||||
560FC5721CB00B880014AA8E /* SQLiteStatementConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EE573C1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift */; };
|
||||
560FC5731CB00B880014AA8E /* RecordFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238311B9C74A90082EB20 /* RecordFetchTests.swift */; };
|
||||
560FC5741CB00B880014AA8E /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */; };
|
||||
560FC5751CB00B880014AA8E /* DatabaseQueueMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AD1C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift */; };
|
||||
560FC5761CB00B880014AA8E /* DetachedRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381F1B9C74A90082EB20 /* DetachedRowTests.swift */; };
|
||||
560FC5771CB00B880014AA8E /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531231C90878D00CF1A2B /* DatabaseQueueSchemaCacheTests.swift */; };
|
||||
560FC5781CB00B880014AA8E /* MetalRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FDECE11BB32DFD009AD709 /* MetalRowTests.swift */; };
|
||||
560FC5791CB00B880014AA8E /* PrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238281B9C74A90082EB20 /* PrimaryKeyMultipleTests.swift */; };
|
||||
560FC57A1CB00B880014AA8E /* DatabasePoolFileAttributesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363DE1C959295000BE133 /* DatabasePoolFileAttributesTests.swift */; };
|
||||
560FC57B1CB00B880014AA8E /* DatabasePoolMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AB1C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift */; };
|
||||
560FC57C1CB00B880014AA8E /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */; };
|
||||
560FC57D1CB00B880014AA8E /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */; };
|
||||
560FC57E1CB00B880014AA8E /* DatabaseMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* DatabaseMutablePersistableTests.swift */; };
|
||||
560FC57E1CB00B880014AA8E /* MutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* MutablePersistableTests.swift */; };
|
||||
560FC57F1CB00B880014AA8E /* RowConvertible+FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B601C53C42C005A543B /* RowConvertible+FetchRequestTests.swift */; };
|
||||
560FC5801CB00B880014AA8E /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */; };
|
||||
560FC5811CB00B880014AA8E /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382D1B9C74A90082EB20 /* RecordCopyTests.swift */; };
|
||||
560FC5821CB00B880014AA8E /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */; };
|
||||
560FC5841CB00B880014AA8E /* DatabasePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* DatabasePersistableTests.swift */; };
|
||||
560FC5841CB00B880014AA8E /* PersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* PersistableTests.swift */; };
|
||||
560FC5851CB00B880014AA8E /* ManagedDataControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC78651BBAEB8C00CA1285 /* ManagedDataControllerTests.swift */; };
|
||||
560FC5861CB00B880014AA8E /* MappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC78641BBAEB8C00CA1285 /* MappingTests.swift */; };
|
||||
560FC5871CB00B880014AA8E /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */; };
|
||||
@@ -162,7 +159,6 @@
|
||||
560FC5891CB00B880014AA8E /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */; };
|
||||
560FC58A1CB00B880014AA8E /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */; };
|
||||
560FC58B1CB00B880014AA8E /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */; };
|
||||
560FC58C1CB00B880014AA8E /* DatabaseQueuePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AE1C933FF8000BE133 /* DatabaseQueuePersistableTests.swift */; };
|
||||
560FC58D1CB00B880014AA8E /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; };
|
||||
560FC58E1CB00B880014AA8E /* PrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382A1B9C74A90082EB20 /* PrimaryKeyRowIDTests.swift */; };
|
||||
560FC58F1CB00B880014AA8E /* DatabaseReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */; };
|
||||
@@ -204,18 +200,10 @@
|
||||
56300B791C53F592005A543B /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6F1C53F592005A543B /* FetchRequest.swift */; };
|
||||
56300B851C54DC95005A543B /* Record+FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B841C54DC95005A543B /* Record+FetchRequestTests.swift */; };
|
||||
56300B861C54DC95005A543B /* Record+FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B841C54DC95005A543B /* Record+FetchRequestTests.swift */; };
|
||||
563363AF1C933FF8000BE133 /* DatabaseMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* DatabaseMutablePersistableTests.swift */; };
|
||||
563363B01C933FF8000BE133 /* DatabaseMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* DatabaseMutablePersistableTests.swift */; };
|
||||
563363B11C933FF8000BE133 /* DatabasePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* DatabasePersistableTests.swift */; };
|
||||
563363B21C933FF8000BE133 /* DatabasePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* DatabasePersistableTests.swift */; };
|
||||
563363B31C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AB1C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift */; };
|
||||
563363B41C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AB1C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift */; };
|
||||
563363B51C933FF8000BE133 /* DatabasePoolPersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AC1C933FF8000BE133 /* DatabasePoolPersistableTests.swift */; };
|
||||
563363B61C933FF8000BE133 /* DatabasePoolPersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AC1C933FF8000BE133 /* DatabasePoolPersistableTests.swift */; };
|
||||
563363B71C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AD1C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift */; };
|
||||
563363B81C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AD1C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift */; };
|
||||
563363B91C933FF8000BE133 /* DatabaseQueuePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AE1C933FF8000BE133 /* DatabaseQueuePersistableTests.swift */; };
|
||||
563363BA1C933FF8000BE133 /* DatabaseQueuePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AE1C933FF8000BE133 /* DatabaseQueuePersistableTests.swift */; };
|
||||
563363AF1C933FF8000BE133 /* MutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* MutablePersistableTests.swift */; };
|
||||
563363B01C933FF8000BE133 /* MutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* MutablePersistableTests.swift */; };
|
||||
563363B11C933FF8000BE133 /* PersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* PersistableTests.swift */; };
|
||||
563363B21C933FF8000BE133 /* PersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* PersistableTests.swift */; };
|
||||
563363BD1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363BC1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift */; };
|
||||
563363BE1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363BC1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift */; };
|
||||
563363C01C942C04000BE133 /* DatabaseReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363BF1C942C04000BE133 /* DatabaseReader.swift */; };
|
||||
@@ -265,28 +253,25 @@
|
||||
567156291CB16729007DC145 /* CollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A50C61BFF4B7F00B3A3A2 /* CollationTests.swift */; };
|
||||
5671562A1CB16729007DC145 /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238221B9C74A90082EB20 /* UpdateStatementTests.swift */; };
|
||||
5671562B1CB16729007DC145 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */; };
|
||||
5671562C1CB16729007DC145 /* DatabasePoolPersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AC1C933FF8000BE133 /* DatabasePoolPersistableTests.swift */; };
|
||||
5671562D1CB16729007DC145 /* RecordAwakeFromFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238301B9C74A90082EB20 /* RecordAwakeFromFetchTests.swift */; };
|
||||
5671562E1CB16729007DC145 /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */; };
|
||||
5671562F1CB16729007DC145 /* PrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382B1B9C74A90082EB20 /* PrimaryKeySingleTests.swift */; };
|
||||
567156301CB16729007DC145 /* SQLiteStatementConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EE573C1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift */; };
|
||||
567156311CB16729007DC145 /* RecordFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238311B9C74A90082EB20 /* RecordFetchTests.swift */; };
|
||||
567156321CB16729007DC145 /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */; };
|
||||
567156331CB16729007DC145 /* DatabaseQueueMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AD1C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift */; };
|
||||
567156341CB16729007DC145 /* DetachedRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381F1B9C74A90082EB20 /* DetachedRowTests.swift */; };
|
||||
567156351CB16729007DC145 /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531231C90878D00CF1A2B /* DatabaseQueueSchemaCacheTests.swift */; };
|
||||
567156361CB16729007DC145 /* MetalRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FDECE11BB32DFD009AD709 /* MetalRowTests.swift */; };
|
||||
567156371CB16729007DC145 /* PrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238281B9C74A90082EB20 /* PrimaryKeyMultipleTests.swift */; };
|
||||
567156381CB16729007DC145 /* DatabasePoolFileAttributesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363DE1C959295000BE133 /* DatabasePoolFileAttributesTests.swift */; };
|
||||
567156391CB16729007DC145 /* DatabasePoolMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AB1C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift */; };
|
||||
5671563A1CB16729007DC145 /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */; };
|
||||
5671563B1CB16729007DC145 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */; };
|
||||
5671563C1CB16729007DC145 /* DatabaseMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* DatabaseMutablePersistableTests.swift */; };
|
||||
5671563C1CB16729007DC145 /* MutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* MutablePersistableTests.swift */; };
|
||||
5671563D1CB16729007DC145 /* RowConvertible+FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B601C53C42C005A543B /* RowConvertible+FetchRequestTests.swift */; };
|
||||
5671563E1CB16729007DC145 /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */; };
|
||||
5671563F1CB16729007DC145 /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382D1B9C74A90082EB20 /* RecordCopyTests.swift */; };
|
||||
567156401CB16729007DC145 /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */; };
|
||||
567156411CB16729007DC145 /* DatabasePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* DatabasePersistableTests.swift */; };
|
||||
567156411CB16729007DC145 /* PersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* PersistableTests.swift */; };
|
||||
567156421CB16729007DC145 /* ManagedDataControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC78651BBAEB8C00CA1285 /* ManagedDataControllerTests.swift */; };
|
||||
567156431CB16729007DC145 /* MappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC78641BBAEB8C00CA1285 /* MappingTests.swift */; };
|
||||
567156441CB16729007DC145 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */; };
|
||||
@@ -294,7 +279,6 @@
|
||||
567156461CB16729007DC145 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */; };
|
||||
567156471CB16729007DC145 /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */; };
|
||||
567156481CB16729007DC145 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */; };
|
||||
567156491CB16729007DC145 /* DatabaseQueuePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AE1C933FF8000BE133 /* DatabaseQueuePersistableTests.swift */; };
|
||||
5671564A1CB16729007DC145 /* ReadOnlyDatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156151CB142AA007DC145 /* ReadOnlyDatabaseTests.swift */; };
|
||||
5671564B1CB16729007DC145 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; };
|
||||
5671564C1CB16729007DC145 /* InMemoryDatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238141B9C74A90082EB20 /* InMemoryDatabaseTests.swift */; };
|
||||
@@ -480,36 +464,32 @@
|
||||
56AFCA391CB1AA9900F48B96 /* SelectStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238211B9C74A90082EB20 /* SelectStatementTests.swift */; };
|
||||
56AFCA3A1CB1AA9900F48B96 /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238221B9C74A90082EB20 /* UpdateStatementTests.swift */; };
|
||||
56AFCA3B1CB1AA9900F48B96 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */; };
|
||||
56AFCA3C1CB1AA9900F48B96 /* DatabasePoolPersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AC1C933FF8000BE133 /* DatabasePoolPersistableTests.swift */; };
|
||||
56AFCA3D1CB1AA9900F48B96 /* RecordAwakeFromFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238301B9C74A90082EB20 /* RecordAwakeFromFetchTests.swift */; };
|
||||
56AFCA3E1CB1AA9900F48B96 /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */; };
|
||||
56AFCA3F1CB1AA9900F48B96 /* PrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382B1B9C74A90082EB20 /* PrimaryKeySingleTests.swift */; };
|
||||
56AFCA401CB1AA9900F48B96 /* RecordFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238311B9C74A90082EB20 /* RecordFetchTests.swift */; };
|
||||
56AFCA411CB1AA9900F48B96 /* SQLiteStatementConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EE573C1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift */; };
|
||||
56AFCA421CB1AA9900F48B96 /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */; };
|
||||
56AFCA431CB1AA9900F48B96 /* DatabaseQueueMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AD1C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift */; };
|
||||
56AFCA441CB1AA9900F48B96 /* DetachedRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381F1B9C74A90082EB20 /* DetachedRowTests.swift */; };
|
||||
56AFCA451CB1AA9900F48B96 /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531231C90878D00CF1A2B /* DatabaseQueueSchemaCacheTests.swift */; };
|
||||
56AFCA461CB1AA9900F48B96 /* PrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238281B9C74A90082EB20 /* PrimaryKeyMultipleTests.swift */; };
|
||||
56AFCA471CB1AA9900F48B96 /* MetalRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FDECE11BB32DFD009AD709 /* MetalRowTests.swift */; };
|
||||
56AFCA481CB1AA9900F48B96 /* DatabasePoolMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AB1C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift */; };
|
||||
56AFCA491CB1AA9900F48B96 /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */; };
|
||||
56AFCA4A1CB1AA9900F48B96 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */; };
|
||||
56AFCA4B1CB1AA9900F48B96 /* DatabaseMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* DatabaseMutablePersistableTests.swift */; };
|
||||
56AFCA4B1CB1AA9900F48B96 /* MutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* MutablePersistableTests.swift */; };
|
||||
56AFCA4C1CB1AA9900F48B96 /* RowConvertible+FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B601C53C42C005A543B /* RowConvertible+FetchRequestTests.swift */; };
|
||||
56AFCA4D1CB1AA9900F48B96 /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */; };
|
||||
56AFCA4E1CB1AA9900F48B96 /* DatabasePoolFileAttributesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363DE1C959295000BE133 /* DatabasePoolFileAttributesTests.swift */; };
|
||||
56AFCA4F1CB1AA9900F48B96 /* NSDataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EB0AB11BCD787300A3DC55 /* NSDataMemoryTests.swift */; };
|
||||
56AFCA501CB1AA9900F48B96 /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382D1B9C74A90082EB20 /* RecordCopyTests.swift */; };
|
||||
56AFCA511CB1AA9900F48B96 /* ManagedDataControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC78651BBAEB8C00CA1285 /* ManagedDataControllerTests.swift */; };
|
||||
56AFCA521CB1AA9900F48B96 /* DatabasePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* DatabasePersistableTests.swift */; };
|
||||
56AFCA521CB1AA9900F48B96 /* PersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* PersistableTests.swift */; };
|
||||
56AFCA531CB1AA9900F48B96 /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */; };
|
||||
56AFCA541CB1AA9900F48B96 /* MappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC78641BBAEB8C00CA1285 /* MappingTests.swift */; };
|
||||
56AFCA551CB1AA9900F48B96 /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */; };
|
||||
56AFCA561CB1AA9900F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37AA1C90085D00949E71 /* DatabasePoolConcurrencyTests.swift */; };
|
||||
56AFCA571CB1AA9900F48B96 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */; };
|
||||
56AFCA581CB1AA9900F48B96 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; };
|
||||
56AFCA591CB1AA9900F48B96 /* DatabaseQueuePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AE1C933FF8000BE133 /* DatabaseQueuePersistableTests.swift */; };
|
||||
56AFCA5A1CB1AA9900F48B96 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */; };
|
||||
56AFCA5B1CB1AA9900F48B96 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */; };
|
||||
56AFCA5C1CB1AA9900F48B96 /* ReadOnlyDatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156151CB142AA007DC145 /* ReadOnlyDatabaseTests.swift */; };
|
||||
@@ -554,36 +534,32 @@
|
||||
56AFCA921CB1ABC800F48B96 /* SelectStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238211B9C74A90082EB20 /* SelectStatementTests.swift */; };
|
||||
56AFCA931CB1ABC800F48B96 /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238221B9C74A90082EB20 /* UpdateStatementTests.swift */; };
|
||||
56AFCA941CB1ABC800F48B96 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */; };
|
||||
56AFCA951CB1ABC800F48B96 /* DatabasePoolPersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AC1C933FF8000BE133 /* DatabasePoolPersistableTests.swift */; };
|
||||
56AFCA961CB1ABC800F48B96 /* RecordAwakeFromFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238301B9C74A90082EB20 /* RecordAwakeFromFetchTests.swift */; };
|
||||
56AFCA971CB1ABC800F48B96 /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */; };
|
||||
56AFCA981CB1ABC800F48B96 /* PrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382B1B9C74A90082EB20 /* PrimaryKeySingleTests.swift */; };
|
||||
56AFCA991CB1ABC800F48B96 /* RecordFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238311B9C74A90082EB20 /* RecordFetchTests.swift */; };
|
||||
56AFCA9A1CB1ABC800F48B96 /* SQLiteStatementConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EE573C1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift */; };
|
||||
56AFCA9B1CB1ABC800F48B96 /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */; };
|
||||
56AFCA9C1CB1ABC800F48B96 /* DatabaseQueueMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AD1C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift */; };
|
||||
56AFCA9D1CB1ABC800F48B96 /* DetachedRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381F1B9C74A90082EB20 /* DetachedRowTests.swift */; };
|
||||
56AFCA9E1CB1ABC800F48B96 /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531231C90878D00CF1A2B /* DatabaseQueueSchemaCacheTests.swift */; };
|
||||
56AFCA9F1CB1ABC800F48B96 /* PrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238281B9C74A90082EB20 /* PrimaryKeyMultipleTests.swift */; };
|
||||
56AFCAA01CB1ABC800F48B96 /* MetalRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FDECE11BB32DFD009AD709 /* MetalRowTests.swift */; };
|
||||
56AFCAA11CB1ABC800F48B96 /* DatabasePoolMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AB1C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift */; };
|
||||
56AFCAA21CB1ABC800F48B96 /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */; };
|
||||
56AFCAA31CB1ABC800F48B96 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */; };
|
||||
56AFCAA41CB1ABC800F48B96 /* DatabaseMutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* DatabaseMutablePersistableTests.swift */; };
|
||||
56AFCAA41CB1ABC800F48B96 /* MutablePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* MutablePersistableTests.swift */; };
|
||||
56AFCAA51CB1ABC800F48B96 /* RowConvertible+FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B601C53C42C005A543B /* RowConvertible+FetchRequestTests.swift */; };
|
||||
56AFCAA61CB1ABC800F48B96 /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */; };
|
||||
56AFCAA71CB1ABC800F48B96 /* DatabasePoolFileAttributesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363DE1C959295000BE133 /* DatabasePoolFileAttributesTests.swift */; };
|
||||
56AFCAA81CB1ABC800F48B96 /* NSDataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EB0AB11BCD787300A3DC55 /* NSDataMemoryTests.swift */; };
|
||||
56AFCAA91CB1ABC800F48B96 /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382D1B9C74A90082EB20 /* RecordCopyTests.swift */; };
|
||||
56AFCAAA1CB1ABC800F48B96 /* ManagedDataControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC78651BBAEB8C00CA1285 /* ManagedDataControllerTests.swift */; };
|
||||
56AFCAAB1CB1ABC800F48B96 /* DatabasePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* DatabasePersistableTests.swift */; };
|
||||
56AFCAAB1CB1ABC800F48B96 /* PersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* PersistableTests.swift */; };
|
||||
56AFCAAC1CB1ABC800F48B96 /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */; };
|
||||
56AFCAAD1CB1ABC800F48B96 /* MappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC78641BBAEB8C00CA1285 /* MappingTests.swift */; };
|
||||
56AFCAAE1CB1ABC800F48B96 /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentableTests.swift */; };
|
||||
56AFCAAF1CB1ABC800F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37AA1C90085D00949E71 /* DatabasePoolConcurrencyTests.swift */; };
|
||||
56AFCAB01CB1ABC800F48B96 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */; };
|
||||
56AFCAB11CB1ABC800F48B96 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; };
|
||||
56AFCAB21CB1ABC800F48B96 /* DatabaseQueuePersistableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AE1C933FF8000BE133 /* DatabaseQueuePersistableTests.swift */; };
|
||||
56AFCAB31CB1ABC800F48B96 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */; };
|
||||
56AFCAB41CB1ABC800F48B96 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */; };
|
||||
56AFCAB51CB1ABC800F48B96 /* ReadOnlyDatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156151CB142AA007DC145 /* ReadOnlyDatabaseTests.swift */; };
|
||||
@@ -846,12 +822,8 @@
|
||||
56300B6A1C53D3E8005A543B /* TableMapping+FetchRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableMapping+FetchRequestTests.swift"; sourceTree = "<group>"; };
|
||||
56300B6F1C53F592005A543B /* FetchRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequest.swift; sourceTree = "<group>"; };
|
||||
56300B841C54DC95005A543B /* Record+FetchRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Record+FetchRequestTests.swift"; sourceTree = "<group>"; };
|
||||
563363A91C933FF8000BE133 /* DatabaseMutablePersistableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseMutablePersistableTests.swift; sourceTree = "<group>"; };
|
||||
563363AA1C933FF8000BE133 /* DatabasePersistableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePersistableTests.swift; sourceTree = "<group>"; };
|
||||
563363AB1C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolMutablePersistableTests.swift; sourceTree = "<group>"; };
|
||||
563363AC1C933FF8000BE133 /* DatabasePoolPersistableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolPersistableTests.swift; sourceTree = "<group>"; };
|
||||
563363AD1C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueMutablePersistableTests.swift; sourceTree = "<group>"; };
|
||||
563363AE1C933FF8000BE133 /* DatabaseQueuePersistableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueuePersistableTests.swift; sourceTree = "<group>"; };
|
||||
563363A91C933FF8000BE133 /* MutablePersistableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableTests.swift; sourceTree = "<group>"; };
|
||||
563363AA1C933FF8000BE133 /* PersistableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistableTests.swift; sourceTree = "<group>"; };
|
||||
563363BC1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueConcurrencyTests.swift; sourceTree = "<group>"; };
|
||||
563363BF1C942C04000BE133 /* DatabaseReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseReader.swift; sourceTree = "<group>"; };
|
||||
563363C31C942C37000BE133 /* DatabaseWriter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseWriter.swift; sourceTree = "<group>"; };
|
||||
@@ -1164,12 +1136,8 @@
|
||||
560B3FA41C19DFF800C58EC7 /* Persistable */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
563363A91C933FF8000BE133 /* DatabaseMutablePersistableTests.swift */,
|
||||
563363AA1C933FF8000BE133 /* DatabasePersistableTests.swift */,
|
||||
563363AB1C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift */,
|
||||
563363AC1C933FF8000BE133 /* DatabasePoolPersistableTests.swift */,
|
||||
563363AD1C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift */,
|
||||
563363AE1C933FF8000BE133 /* DatabaseQueuePersistableTests.swift */,
|
||||
563363A91C933FF8000BE133 /* MutablePersistableTests.swift */,
|
||||
563363AA1C933FF8000BE133 /* PersistableTests.swift */,
|
||||
);
|
||||
path = Persistable;
|
||||
sourceTree = "<group>";
|
||||
@@ -2205,28 +2173,25 @@
|
||||
560FC56B1CB00B880014AA8E /* CollationTests.swift in Sources */,
|
||||
560FC56C1CB00B880014AA8E /* UpdateStatementTests.swift in Sources */,
|
||||
560FC56D1CB00B880014AA8E /* DatabaseMigratorTests.swift in Sources */,
|
||||
560FC56E1CB00B880014AA8E /* DatabasePoolPersistableTests.swift in Sources */,
|
||||
560FC56F1CB00B880014AA8E /* RecordAwakeFromFetchTests.swift in Sources */,
|
||||
560FC5701CB00B880014AA8E /* DatabasePoolCollationTests.swift in Sources */,
|
||||
560FC5711CB00B880014AA8E /* PrimaryKeySingleTests.swift in Sources */,
|
||||
560FC5721CB00B880014AA8E /* SQLiteStatementConversionTests.swift in Sources */,
|
||||
560FC5731CB00B880014AA8E /* RecordFetchTests.swift in Sources */,
|
||||
560FC5741CB00B880014AA8E /* DatabasePoolFunctionTests.swift in Sources */,
|
||||
560FC5751CB00B880014AA8E /* DatabaseQueueMutablePersistableTests.swift in Sources */,
|
||||
560FC5761CB00B880014AA8E /* DetachedRowTests.swift in Sources */,
|
||||
560FC5771CB00B880014AA8E /* DatabaseQueueSchemaCacheTests.swift in Sources */,
|
||||
560FC5781CB00B880014AA8E /* MetalRowTests.swift in Sources */,
|
||||
560FC5791CB00B880014AA8E /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
560FC57A1CB00B880014AA8E /* DatabasePoolFileAttributesTests.swift in Sources */,
|
||||
560FC57B1CB00B880014AA8E /* DatabasePoolMutablePersistableTests.swift in Sources */,
|
||||
560FC57C1CB00B880014AA8E /* StatementArgumentsTests.swift in Sources */,
|
||||
560FC57D1CB00B880014AA8E /* RecordInitializersTests.swift in Sources */,
|
||||
560FC57E1CB00B880014AA8E /* DatabaseMutablePersistableTests.swift in Sources */,
|
||||
560FC57E1CB00B880014AA8E /* MutablePersistableTests.swift in Sources */,
|
||||
560FC57F1CB00B880014AA8E /* RowConvertible+FetchRequestTests.swift in Sources */,
|
||||
560FC5801CB00B880014AA8E /* DatabasePoolReadOnlyTests.swift in Sources */,
|
||||
560FC5811CB00B880014AA8E /* RecordCopyTests.swift in Sources */,
|
||||
560FC5821CB00B880014AA8E /* RawRepresentableTests.swift in Sources */,
|
||||
560FC5841CB00B880014AA8E /* DatabasePersistableTests.swift in Sources */,
|
||||
560FC5841CB00B880014AA8E /* PersistableTests.swift in Sources */,
|
||||
560FC5851CB00B880014AA8E /* ManagedDataControllerTests.swift in Sources */,
|
||||
560FC5861CB00B880014AA8E /* MappingTests.swift in Sources */,
|
||||
560FC5871CB00B880014AA8E /* RecordSubClassTests.swift in Sources */,
|
||||
@@ -2234,7 +2199,6 @@
|
||||
560FC5891CB00B880014AA8E /* TransactionObserverTests.swift in Sources */,
|
||||
560FC58A1CB00B880014AA8E /* DatabasePoolReleaseMemoryTests.swift in Sources */,
|
||||
560FC58B1CB00B880014AA8E /* DatabaseValueTests.swift in Sources */,
|
||||
560FC58C1CB00B880014AA8E /* DatabaseQueuePersistableTests.swift in Sources */,
|
||||
567156171CB142AA007DC145 /* ReadOnlyDatabaseTests.swift in Sources */,
|
||||
560FC58D1CB00B880014AA8E /* Row+FoundationTests.swift in Sources */,
|
||||
567156141CB141D0007DC145 /* InMemoryDatabaseTests.swift in Sources */,
|
||||
@@ -2302,28 +2266,25 @@
|
||||
5671562A1CB16729007DC145 /* UpdateStatementTests.swift in Sources */,
|
||||
567156711CB18050007DC145 /* EncryptionTests.swift in Sources */,
|
||||
5671562B1CB16729007DC145 /* DatabaseMigratorTests.swift in Sources */,
|
||||
5671562C1CB16729007DC145 /* DatabasePoolPersistableTests.swift in Sources */,
|
||||
5671562D1CB16729007DC145 /* RecordAwakeFromFetchTests.swift in Sources */,
|
||||
5671562E1CB16729007DC145 /* DatabasePoolCollationTests.swift in Sources */,
|
||||
5671562F1CB16729007DC145 /* PrimaryKeySingleTests.swift in Sources */,
|
||||
567156301CB16729007DC145 /* SQLiteStatementConversionTests.swift in Sources */,
|
||||
567156311CB16729007DC145 /* RecordFetchTests.swift in Sources */,
|
||||
567156321CB16729007DC145 /* DatabasePoolFunctionTests.swift in Sources */,
|
||||
567156331CB16729007DC145 /* DatabaseQueueMutablePersistableTests.swift in Sources */,
|
||||
567156341CB16729007DC145 /* DetachedRowTests.swift in Sources */,
|
||||
567156351CB16729007DC145 /* DatabaseQueueSchemaCacheTests.swift in Sources */,
|
||||
567156361CB16729007DC145 /* MetalRowTests.swift in Sources */,
|
||||
567156371CB16729007DC145 /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
567156381CB16729007DC145 /* DatabasePoolFileAttributesTests.swift in Sources */,
|
||||
567156391CB16729007DC145 /* DatabasePoolMutablePersistableTests.swift in Sources */,
|
||||
5671563A1CB16729007DC145 /* StatementArgumentsTests.swift in Sources */,
|
||||
5671563B1CB16729007DC145 /* RecordInitializersTests.swift in Sources */,
|
||||
5671563C1CB16729007DC145 /* DatabaseMutablePersistableTests.swift in Sources */,
|
||||
5671563C1CB16729007DC145 /* MutablePersistableTests.swift in Sources */,
|
||||
5671563D1CB16729007DC145 /* RowConvertible+FetchRequestTests.swift in Sources */,
|
||||
5671563E1CB16729007DC145 /* DatabasePoolReadOnlyTests.swift in Sources */,
|
||||
5671563F1CB16729007DC145 /* RecordCopyTests.swift in Sources */,
|
||||
567156401CB16729007DC145 /* RawRepresentableTests.swift in Sources */,
|
||||
567156411CB16729007DC145 /* DatabasePersistableTests.swift in Sources */,
|
||||
567156411CB16729007DC145 /* PersistableTests.swift in Sources */,
|
||||
567156421CB16729007DC145 /* ManagedDataControllerTests.swift in Sources */,
|
||||
567156431CB16729007DC145 /* MappingTests.swift in Sources */,
|
||||
567156441CB16729007DC145 /* RecordSubClassTests.swift in Sources */,
|
||||
@@ -2331,7 +2292,6 @@
|
||||
567156461CB16729007DC145 /* TransactionObserverTests.swift in Sources */,
|
||||
567156471CB16729007DC145 /* DatabasePoolReleaseMemoryTests.swift in Sources */,
|
||||
567156481CB16729007DC145 /* DatabaseValueTests.swift in Sources */,
|
||||
567156491CB16729007DC145 /* DatabaseQueuePersistableTests.swift in Sources */,
|
||||
5671564A1CB16729007DC145 /* ReadOnlyDatabaseTests.swift in Sources */,
|
||||
5671564B1CB16729007DC145 /* Row+FoundationTests.swift in Sources */,
|
||||
5671564C1CB16729007DC145 /* InMemoryDatabaseTests.swift in Sources */,
|
||||
@@ -2429,36 +2389,32 @@
|
||||
56AFCA391CB1AA9900F48B96 /* SelectStatementTests.swift in Sources */,
|
||||
56AFCA3A1CB1AA9900F48B96 /* UpdateStatementTests.swift in Sources */,
|
||||
56AFCA3B1CB1AA9900F48B96 /* DatabaseMigratorTests.swift in Sources */,
|
||||
56AFCA3C1CB1AA9900F48B96 /* DatabasePoolPersistableTests.swift in Sources */,
|
||||
56AFCA3D1CB1AA9900F48B96 /* RecordAwakeFromFetchTests.swift in Sources */,
|
||||
56AFCA3E1CB1AA9900F48B96 /* DatabasePoolCollationTests.swift in Sources */,
|
||||
56AFCA3F1CB1AA9900F48B96 /* PrimaryKeySingleTests.swift in Sources */,
|
||||
56AFCA401CB1AA9900F48B96 /* RecordFetchTests.swift in Sources */,
|
||||
56AFCA411CB1AA9900F48B96 /* SQLiteStatementConversionTests.swift in Sources */,
|
||||
56AFCA421CB1AA9900F48B96 /* DatabasePoolFunctionTests.swift in Sources */,
|
||||
56AFCA431CB1AA9900F48B96 /* DatabaseQueueMutablePersistableTests.swift in Sources */,
|
||||
56AFCA441CB1AA9900F48B96 /* DetachedRowTests.swift in Sources */,
|
||||
56AFCA451CB1AA9900F48B96 /* DatabaseQueueSchemaCacheTests.swift in Sources */,
|
||||
56AFCA461CB1AA9900F48B96 /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
56AFCA471CB1AA9900F48B96 /* MetalRowTests.swift in Sources */,
|
||||
56AFCA481CB1AA9900F48B96 /* DatabasePoolMutablePersistableTests.swift in Sources */,
|
||||
56AFCA491CB1AA9900F48B96 /* StatementArgumentsTests.swift in Sources */,
|
||||
56AFCA4A1CB1AA9900F48B96 /* RecordInitializersTests.swift in Sources */,
|
||||
56AFCA4B1CB1AA9900F48B96 /* DatabaseMutablePersistableTests.swift in Sources */,
|
||||
56AFCA4B1CB1AA9900F48B96 /* MutablePersistableTests.swift in Sources */,
|
||||
56AFCA4C1CB1AA9900F48B96 /* RowConvertible+FetchRequestTests.swift in Sources */,
|
||||
56AFCA4D1CB1AA9900F48B96 /* DatabasePoolReadOnlyTests.swift in Sources */,
|
||||
56AFCA4E1CB1AA9900F48B96 /* DatabasePoolFileAttributesTests.swift in Sources */,
|
||||
56AFCA4F1CB1AA9900F48B96 /* NSDataMemoryTests.swift in Sources */,
|
||||
56AFCA501CB1AA9900F48B96 /* RecordCopyTests.swift in Sources */,
|
||||
56AFCA511CB1AA9900F48B96 /* ManagedDataControllerTests.swift in Sources */,
|
||||
56AFCA521CB1AA9900F48B96 /* DatabasePersistableTests.swift in Sources */,
|
||||
56AFCA521CB1AA9900F48B96 /* PersistableTests.swift in Sources */,
|
||||
56AFCA531CB1AA9900F48B96 /* DatabaseValueConversionTests.swift in Sources */,
|
||||
56AFCA541CB1AA9900F48B96 /* MappingTests.swift in Sources */,
|
||||
56AFCA551CB1AA9900F48B96 /* RawRepresentableTests.swift in Sources */,
|
||||
56AFCA561CB1AA9900F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */,
|
||||
56AFCA571CB1AA9900F48B96 /* TransactionObserverTests.swift in Sources */,
|
||||
56AFCA581CB1AA9900F48B96 /* Row+FoundationTests.swift in Sources */,
|
||||
56AFCA591CB1AA9900F48B96 /* DatabaseQueuePersistableTests.swift in Sources */,
|
||||
56AFCA5A1CB1AA9900F48B96 /* RecordSubClassTests.swift in Sources */,
|
||||
56AFCA5B1CB1AA9900F48B96 /* DatabaseValueTests.swift in Sources */,
|
||||
56AFCA5C1CB1AA9900F48B96 /* ReadOnlyDatabaseTests.swift in Sources */,
|
||||
@@ -2509,7 +2465,6 @@
|
||||
56AFCA921CB1ABC800F48B96 /* SelectStatementTests.swift in Sources */,
|
||||
56AFCA931CB1ABC800F48B96 /* UpdateStatementTests.swift in Sources */,
|
||||
56AFCA941CB1ABC800F48B96 /* DatabaseMigratorTests.swift in Sources */,
|
||||
56AFCA951CB1ABC800F48B96 /* DatabasePoolPersistableTests.swift in Sources */,
|
||||
56AFCAD91CB1AC5C00F48B96 /* EncryptionTests.swift in Sources */,
|
||||
56AFCA961CB1ABC800F48B96 /* RecordAwakeFromFetchTests.swift in Sources */,
|
||||
56AFCA971CB1ABC800F48B96 /* DatabasePoolCollationTests.swift in Sources */,
|
||||
@@ -2517,29 +2472,26 @@
|
||||
56AFCA991CB1ABC800F48B96 /* RecordFetchTests.swift in Sources */,
|
||||
56AFCA9A1CB1ABC800F48B96 /* SQLiteStatementConversionTests.swift in Sources */,
|
||||
56AFCA9B1CB1ABC800F48B96 /* DatabasePoolFunctionTests.swift in Sources */,
|
||||
56AFCA9C1CB1ABC800F48B96 /* DatabaseQueueMutablePersistableTests.swift in Sources */,
|
||||
56AFCA9D1CB1ABC800F48B96 /* DetachedRowTests.swift in Sources */,
|
||||
56AFCA9E1CB1ABC800F48B96 /* DatabaseQueueSchemaCacheTests.swift in Sources */,
|
||||
56AFCA9F1CB1ABC800F48B96 /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
56AFCAA01CB1ABC800F48B96 /* MetalRowTests.swift in Sources */,
|
||||
56AFCAA11CB1ABC800F48B96 /* DatabasePoolMutablePersistableTests.swift in Sources */,
|
||||
56AFCAA21CB1ABC800F48B96 /* StatementArgumentsTests.swift in Sources */,
|
||||
56AFCAA31CB1ABC800F48B96 /* RecordInitializersTests.swift in Sources */,
|
||||
56AFCAA41CB1ABC800F48B96 /* DatabaseMutablePersistableTests.swift in Sources */,
|
||||
56AFCAA41CB1ABC800F48B96 /* MutablePersistableTests.swift in Sources */,
|
||||
56AFCAA51CB1ABC800F48B96 /* RowConvertible+FetchRequestTests.swift in Sources */,
|
||||
56AFCAA61CB1ABC800F48B96 /* DatabasePoolReadOnlyTests.swift in Sources */,
|
||||
56AFCAA71CB1ABC800F48B96 /* DatabasePoolFileAttributesTests.swift in Sources */,
|
||||
56AFCAA81CB1ABC800F48B96 /* NSDataMemoryTests.swift in Sources */,
|
||||
56AFCAA91CB1ABC800F48B96 /* RecordCopyTests.swift in Sources */,
|
||||
56AFCAAA1CB1ABC800F48B96 /* ManagedDataControllerTests.swift in Sources */,
|
||||
56AFCAAB1CB1ABC800F48B96 /* DatabasePersistableTests.swift in Sources */,
|
||||
56AFCAAB1CB1ABC800F48B96 /* PersistableTests.swift in Sources */,
|
||||
56AFCAAC1CB1ABC800F48B96 /* DatabaseValueConversionTests.swift in Sources */,
|
||||
56AFCAAD1CB1ABC800F48B96 /* MappingTests.swift in Sources */,
|
||||
56AFCAAE1CB1ABC800F48B96 /* RawRepresentableTests.swift in Sources */,
|
||||
56AFCAAF1CB1ABC800F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */,
|
||||
56AFCAB01CB1ABC800F48B96 /* TransactionObserverTests.swift in Sources */,
|
||||
56AFCAB11CB1ABC800F48B96 /* Row+FoundationTests.swift in Sources */,
|
||||
56AFCAB21CB1ABC800F48B96 /* DatabaseQueuePersistableTests.swift in Sources */,
|
||||
56AFCAB31CB1ABC800F48B96 /* RecordSubClassTests.swift in Sources */,
|
||||
56AFCAB41CB1ABC800F48B96 /* DatabaseValueTests.swift in Sources */,
|
||||
56AFCAB51CB1ABC800F48B96 /* ReadOnlyDatabaseTests.swift in Sources */,
|
||||
@@ -2639,36 +2591,32 @@
|
||||
56A2384A1B9C74A90082EB20 /* SelectStatementTests.swift in Sources */,
|
||||
56A2384C1B9C74A90082EB20 /* UpdateStatementTests.swift in Sources */,
|
||||
56A2384E1B9C74A90082EB20 /* DatabaseMigratorTests.swift in Sources */,
|
||||
563363B61C933FF8000BE133 /* DatabasePoolPersistableTests.swift in Sources */,
|
||||
56A238641B9C74A90082EB20 /* RecordAwakeFromFetchTests.swift in Sources */,
|
||||
569531351C919DF200CF1A2B /* DatabasePoolCollationTests.swift in Sources */,
|
||||
56A2385A1B9C74A90082EB20 /* PrimaryKeySingleTests.swift in Sources */,
|
||||
56A238661B9C74A90082EB20 /* RecordFetchTests.swift in Sources */,
|
||||
56EE573E1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift in Sources */,
|
||||
569531381C919DF700CF1A2B /* DatabasePoolFunctionTests.swift in Sources */,
|
||||
563363B81C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift in Sources */,
|
||||
56A238481B9C74A90082EB20 /* DetachedRowTests.swift in Sources */,
|
||||
569531271C9087B700CF1A2B /* DatabaseQueueSchemaCacheTests.swift in Sources */,
|
||||
56A238541B9C74A90082EB20 /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
56FDECE31BB32DFD009AD709 /* MetalRowTests.swift in Sources */,
|
||||
563363B41C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift in Sources */,
|
||||
56DE7B121C3D93ED00861EB8 /* StatementArgumentsTests.swift in Sources */,
|
||||
56A238681B9C74A90082EB20 /* RecordInitializersTests.swift in Sources */,
|
||||
563363B01C933FF8000BE133 /* DatabaseMutablePersistableTests.swift in Sources */,
|
||||
563363B01C933FF8000BE133 /* MutablePersistableTests.swift in Sources */,
|
||||
56300B621C53C42C005A543B /* RowConvertible+FetchRequestTests.swift in Sources */,
|
||||
56EA869F1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift in Sources */,
|
||||
563363E01C959295000BE133 /* DatabasePoolFileAttributesTests.swift in Sources */,
|
||||
56EB0AB31BCD787300A3DC55 /* NSDataMemoryTests.swift in Sources */,
|
||||
56A2385E1B9C74A90082EB20 /* RecordCopyTests.swift in Sources */,
|
||||
56FC78691BBAEB8C00CA1285 /* ManagedDataControllerTests.swift in Sources */,
|
||||
563363B21C933FF8000BE133 /* DatabasePersistableTests.swift in Sources */,
|
||||
563363B21C933FF8000BE133 /* PersistableTests.swift in Sources */,
|
||||
56A238421B9C74A90082EB20 /* DatabaseValueConversionTests.swift in Sources */,
|
||||
56FC78671BBAEB8C00CA1285 /* MappingTests.swift in Sources */,
|
||||
56A238441B9C74A90082EB20 /* RawRepresentableTests.swift in Sources */,
|
||||
560A37AC1C90085D00949E71 /* DatabasePoolConcurrencyTests.swift in Sources */,
|
||||
5607EFD41BB827FD00605DE3 /* TransactionObserverTests.swift in Sources */,
|
||||
565D5D721BBC694D00DC9BD4 /* Row+FoundationTests.swift in Sources */,
|
||||
563363BA1C933FF8000BE133 /* DatabaseQueuePersistableTests.swift in Sources */,
|
||||
56A2386A1B9C74A90082EB20 /* RecordSubClassTests.swift in Sources */,
|
||||
56A2383E1B9C74A90082EB20 /* DatabaseValueTests.swift in Sources */,
|
||||
567156181CB142AA007DC145 /* ReadOnlyDatabaseTests.swift in Sources */,
|
||||
@@ -2719,29 +2667,26 @@
|
||||
564A50C71BFF4B7F00B3A3A2 /* CollationTests.swift in Sources */,
|
||||
56A2384B1B9C74A90082EB20 /* UpdateStatementTests.swift in Sources */,
|
||||
56A2384D1B9C74A90082EB20 /* DatabaseMigratorTests.swift in Sources */,
|
||||
563363B51C933FF8000BE133 /* DatabasePoolPersistableTests.swift in Sources */,
|
||||
56A238631B9C74A90082EB20 /* RecordAwakeFromFetchTests.swift in Sources */,
|
||||
569531341C919DF200CF1A2B /* DatabasePoolCollationTests.swift in Sources */,
|
||||
56A238591B9C74A90082EB20 /* PrimaryKeySingleTests.swift in Sources */,
|
||||
56EE573D1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift in Sources */,
|
||||
56A238651B9C74A90082EB20 /* RecordFetchTests.swift in Sources */,
|
||||
569531371C919DF700CF1A2B /* DatabasePoolFunctionTests.swift in Sources */,
|
||||
563363B71C933FF8000BE133 /* DatabaseQueueMutablePersistableTests.swift in Sources */,
|
||||
56A238471B9C74A90082EB20 /* DetachedRowTests.swift in Sources */,
|
||||
569531261C9087B600CF1A2B /* DatabaseQueueSchemaCacheTests.swift in Sources */,
|
||||
56FDECE21BB32DFD009AD709 /* MetalRowTests.swift in Sources */,
|
||||
56A238531B9C74A90082EB20 /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
563363DF1C959295000BE133 /* DatabasePoolFileAttributesTests.swift in Sources */,
|
||||
563363B31C933FF8000BE133 /* DatabasePoolMutablePersistableTests.swift in Sources */,
|
||||
56DE7B111C3D93ED00861EB8 /* StatementArgumentsTests.swift in Sources */,
|
||||
56A238671B9C74A90082EB20 /* RecordInitializersTests.swift in Sources */,
|
||||
563363AF1C933FF8000BE133 /* DatabaseMutablePersistableTests.swift in Sources */,
|
||||
563363AF1C933FF8000BE133 /* MutablePersistableTests.swift in Sources */,
|
||||
56300B611C53C42C005A543B /* RowConvertible+FetchRequestTests.swift in Sources */,
|
||||
56EA869E1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift in Sources */,
|
||||
56A2385D1B9C74A90082EB20 /* RecordCopyTests.swift in Sources */,
|
||||
56A238431B9C74A90082EB20 /* RawRepresentableTests.swift in Sources */,
|
||||
56EB0AB21BCD787300A3DC55 /* NSDataMemoryTests.swift in Sources */,
|
||||
563363B11C933FF8000BE133 /* DatabasePersistableTests.swift in Sources */,
|
||||
563363B11C933FF8000BE133 /* PersistableTests.swift in Sources */,
|
||||
56FC78681BBAEB8C00CA1285 /* ManagedDataControllerTests.swift in Sources */,
|
||||
56FC78661BBAEB8C00CA1285 /* MappingTests.swift in Sources */,
|
||||
56A238691B9C74A90082EB20 /* RecordSubClassTests.swift in Sources */,
|
||||
@@ -2749,7 +2694,6 @@
|
||||
5607EFD31BB8254800605DE3 /* TransactionObserverTests.swift in Sources */,
|
||||
563363D01C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift in Sources */,
|
||||
56A2383D1B9C74A90082EB20 /* DatabaseValueTests.swift in Sources */,
|
||||
563363B91C933FF8000BE133 /* DatabaseQueuePersistableTests.swift in Sources */,
|
||||
565D5D711BBC694D00DC9BD4 /* Row+FoundationTests.swift in Sources */,
|
||||
567156161CB142AA007DC145 /* ReadOnlyDatabaseTests.swift in Sources */,
|
||||
56A238571B9C74A90082EB20 /* PrimaryKeyRowIDTests.swift in Sources */,
|
||||
|
||||
+72
-72
@@ -1465,75 +1465,75 @@ public struct DatabaseEvent {
|
||||
}
|
||||
|
||||
|
||||
// =========================================================================
|
||||
// MARK: - DatabaseReader
|
||||
|
||||
extension Database : DatabaseReader {
|
||||
|
||||
// MARK: - DatabaseReader Protocol Adoption
|
||||
|
||||
/// Synchronously evalutes the *block* argument in a deferred transaction,
|
||||
/// and returns its result.
|
||||
///
|
||||
/// This method is part of the DatabaseReader protocol adoption.
|
||||
public func read<T>(block: (db: Database) throws -> T) rethrows -> T {
|
||||
// The isolation guarantees required by DatabaseReader.read require that
|
||||
// we run the block in a transaction.
|
||||
//
|
||||
// Problem is, our inTransaction() method is declared as a `throws`
|
||||
// function, not a `rethrows` function. That's on purpose: immediate and
|
||||
// exclusive transactions may throw their own locking errors.
|
||||
//
|
||||
// We could update DatabaseReader and make the read() method `throws`.
|
||||
//
|
||||
// Instead we assume that read-only deferred transaction always
|
||||
// succeeds: let's turn our throwing inTransaction() into a rethrowing
|
||||
// function with this little trick:
|
||||
func impl(@noescape block: (db: Database) throws -> T, onError: (ErrorType) throws -> ()) rethrows -> T {
|
||||
var result: T? = nil
|
||||
do {
|
||||
try inTransaction(.Deferred) {
|
||||
result = try block(db: self)
|
||||
return .Commit
|
||||
}
|
||||
} catch {
|
||||
try onError(error)
|
||||
}
|
||||
return result!
|
||||
}
|
||||
preconditionValidQueue()
|
||||
return try impl(block, onError: { throw $0 })
|
||||
}
|
||||
|
||||
/// Synchronously evalutes the *block* argument, and returns its result.
|
||||
///
|
||||
/// This method is part of the DatabaseReader protocol adoption.
|
||||
public func nonIsolatedRead<T>(block: (db: Database) throws -> T) rethrows -> T {
|
||||
preconditionValidQueue()
|
||||
return try block(db: self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =========================================================================
|
||||
// MARK: - DatabaseWriter
|
||||
|
||||
extension Database : DatabaseWriter {
|
||||
|
||||
// MARK: - DatabaseWriter Protocol Adoption
|
||||
|
||||
/// Synchronously evalutes the *block* argument, and returns its result.
|
||||
///
|
||||
/// This method is part of the DatabaseWriter protocol adoption.
|
||||
public func write<T>(block: (db: Database) throws -> T) rethrows -> T {
|
||||
preconditionValidQueue()
|
||||
return try block(db: self)
|
||||
}
|
||||
|
||||
/// Synchronously evalutes the *block* argument in a deferred transaction.
|
||||
///
|
||||
/// This method is part of the DatabaseWriter protocol adoption.
|
||||
public func readFromWrite(block: (db: Database) -> Void) {
|
||||
read(block)
|
||||
}
|
||||
}
|
||||
//// =========================================================================
|
||||
//// MARK: - DatabaseReader
|
||||
//
|
||||
//extension Database : DatabaseReader {
|
||||
//
|
||||
// // MARK: - DatabaseReader Protocol Adoption
|
||||
//
|
||||
// /// Synchronously evalutes the *block* argument in a deferred transaction,
|
||||
// /// and returns its result.
|
||||
// ///
|
||||
// /// This method is part of the DatabaseReader protocol adoption.
|
||||
// public func read<T>(block: (db: Database) throws -> T) rethrows -> T {
|
||||
// // The isolation guarantees required by DatabaseReader.read require that
|
||||
// // we run the block in a transaction.
|
||||
// //
|
||||
// // Problem is, our inTransaction() method is declared as a `throws`
|
||||
// // function, not a `rethrows` function. That's on purpose: immediate and
|
||||
// // exclusive transactions may throw their own locking errors.
|
||||
// //
|
||||
// // We could update DatabaseReader and make the read() method `throws`.
|
||||
// //
|
||||
// // Instead we assume that read-only deferred transaction always
|
||||
// // succeeds: let's turn our throwing inTransaction() into a rethrowing
|
||||
// // function with this little trick:
|
||||
// func impl(@noescape block: (db: Database) throws -> T, onError: (ErrorType) throws -> ()) rethrows -> T {
|
||||
// var result: T? = nil
|
||||
// do {
|
||||
// try inTransaction(.Deferred) {
|
||||
// result = try block(db: self)
|
||||
// return .Commit
|
||||
// }
|
||||
// } catch {
|
||||
// try onError(error)
|
||||
// }
|
||||
// return result!
|
||||
// }
|
||||
// preconditionValidQueue()
|
||||
// return try impl(block, onError: { throw $0 })
|
||||
// }
|
||||
//
|
||||
// /// Synchronously evalutes the *block* argument, and returns its result.
|
||||
// ///
|
||||
// /// This method is part of the DatabaseReader protocol adoption.
|
||||
// public func nonIsolatedRead<T>(block: (db: Database) throws -> T) rethrows -> T {
|
||||
// preconditionValidQueue()
|
||||
// return try block(db: self)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// =========================================================================
|
||||
//// MARK: - DatabaseWriter
|
||||
//
|
||||
//extension Database : DatabaseWriter {
|
||||
//
|
||||
// // MARK: - DatabaseWriter Protocol Adoption
|
||||
//
|
||||
// /// Synchronously evalutes the *block* argument, and returns its result.
|
||||
// ///
|
||||
// /// This method is part of the DatabaseWriter protocol adoption.
|
||||
// public func write<T>(block: (db: Database) throws -> T) rethrows -> T {
|
||||
// preconditionValidQueue()
|
||||
// return try block(db: self)
|
||||
// }
|
||||
//
|
||||
// /// Synchronously evalutes the *block* argument in a deferred transaction.
|
||||
// ///
|
||||
// /// This method is part of the DatabaseWriter protocol adoption.
|
||||
// public func readFromWrite(block: (db: Database) -> Void) {
|
||||
// read(block)
|
||||
// }
|
||||
//}
|
||||
@@ -444,10 +444,12 @@ extension DatabasePool : DatabaseWriter {
|
||||
let semaphore = dispatch_semaphore_create(0)
|
||||
self.readerPool.get { reader in
|
||||
reader.performAsync { db in
|
||||
db.read { db in
|
||||
// Assume COMMIT DEFERRED TRANSACTION does not throw error.
|
||||
try! db.inTransaction(.Deferred) {
|
||||
// Now we're isolated: release the writing queue
|
||||
dispatch_semaphore_signal(semaphore)
|
||||
block(db: db)
|
||||
return .Commit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
/// The protocol for all types that can fetch values from a database.
|
||||
///
|
||||
/// It is adopted by DatabaseQueue, DatabasePool, and Database.
|
||||
///
|
||||
/// You typically provide a DatabaseReader to fetching methods:
|
||||
///
|
||||
/// let persons = Person.fetchAll(dbQueue)
|
||||
/// let persons = Person.fetchAll(dbPool)
|
||||
/// dbQueue.inDatabase { db in
|
||||
/// let persons = Person.fetchAll(db)
|
||||
/// }
|
||||
/// It is adopted by DatabaseQueue and DatabasePool.
|
||||
///
|
||||
/// The protocol comes with isolation guarantees that describe the behavior of
|
||||
/// adopting types in a multithreaded application.
|
||||
///
|
||||
/// Types that adopt the protocol can provide stronger guarantees in practice.
|
||||
/// Types that adopt the protocol can provide in practice stronger guarantees.
|
||||
/// For example, DatabaseQueue provides a stronger isolation level
|
||||
/// than DatabasePool.
|
||||
///
|
||||
|
||||
@@ -141,13 +141,13 @@ public extension DatabaseValueConvertible {
|
||||
/// let names = String.fetchAll(db, "SELECT name FROM ...") // [String]
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An array.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(db: DatabaseReader, _ sql: String, arguments: StatementArguments? = nil) -> [Self] {
|
||||
return db.nonIsolatedRead { db in fetchAll(try! db.selectStatement(sql), arguments: arguments) }
|
||||
public static func fetchAll(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> [Self] {
|
||||
return fetchAll(try! db.selectStatement(sql), arguments: arguments)
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from an SQL query.
|
||||
@@ -158,13 +158,13 @@ public extension DatabaseValueConvertible {
|
||||
/// let name = String.fetchOne(db, "SELECT name FROM ...") // String?
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An optional value.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(db: DatabaseReader, _ sql: String, arguments: StatementArguments? = nil) -> Self? {
|
||||
return db.nonIsolatedRead { db in fetchOne(try! db.selectStatement(sql), arguments: arguments) }
|
||||
public static func fetchOne(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> Self? {
|
||||
return fetchOne(try! db.selectStatement(sql), arguments: arguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,12 +262,12 @@ public extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// let names = String.fetchAll(db, "SELECT name FROM ...") // [String?]
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - parameter arguments: Optional statement arguments.
|
||||
/// - returns: An array of optional values.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(db: DatabaseReader, _ sql: String, arguments: StatementArguments? = nil) -> [Wrapped?] {
|
||||
return db.nonIsolatedRead { db in fetchAll(try! db.selectStatement(sql), arguments: arguments) }
|
||||
public static func fetchAll(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> [Wrapped?] {
|
||||
return fetchAll(try! db.selectStatement(sql), arguments: arguments)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,11 @@
|
||||
/// The protocol for all types that can update a database.
|
||||
///
|
||||
/// It is adopted by DatabaseQueue, DatabasePool, and Database.
|
||||
///
|
||||
/// let person = Person(...)
|
||||
/// try person.insert(dbQueue)
|
||||
/// try person.insert(dbPool)
|
||||
/// try dbQueue.inDatabase { db in
|
||||
/// try person.insert(db)
|
||||
/// }
|
||||
/// It is adopted by DatabaseQueue and DatabasePool.
|
||||
///
|
||||
/// The protocol comes with isolation guarantees that describe the behavior of
|
||||
/// adopting types in a multithreaded application.
|
||||
///
|
||||
/// Types that adopt the protocol can provide stronger guarantees in practice.
|
||||
/// Types that adopt the protocol can in practice provide stronger guarantees.
|
||||
/// For example, DatabaseQueue provides a stronger isolation level
|
||||
/// than DatabasePool.
|
||||
///
|
||||
@@ -64,38 +57,7 @@ public protocol DatabaseWriter : DatabaseReader {
|
||||
func readFromWrite(block: (db: Database) -> Void)
|
||||
}
|
||||
|
||||
extension DatabaseWriter {
|
||||
|
||||
// MARK: - Writing in Database
|
||||
|
||||
/// Executes one or several SQL statements, separated by semi-colons.
|
||||
///
|
||||
/// try writer.execute(
|
||||
/// "INSERT INTO persons (name) VALUES (:name)",
|
||||
/// arguments: ["name": "Arthur"])
|
||||
///
|
||||
/// try writer.execute(
|
||||
/// "INSERT INTO persons (name) VALUES (?);" +
|
||||
/// "INSERT INTO persons (name) VALUES (?);" +
|
||||
/// "INSERT INTO persons (name) VALUES (?);",
|
||||
/// arguments; ['Arthur', 'Barbara', 'Craig'])
|
||||
///
|
||||
/// This method may throw a DatabaseError.
|
||||
///
|
||||
/// See documentation of the write() method for information about the
|
||||
/// isolation from concurrent database updates.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: A DatabaseChanges.
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
public func execute(sql: String, arguments: StatementArguments? = nil) throws -> DatabaseChanges {
|
||||
return try write { db in
|
||||
try db.execute(sql, arguments: arguments)
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseWriter {
|
||||
|
||||
// MARK: - Transaction Observers
|
||||
|
||||
|
||||
+6
-6
@@ -536,13 +536,13 @@ extension Row {
|
||||
/// let rows = Row.fetchAll(db, "SELECT ...")
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An array of rows.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(db: DatabaseReader, _ sql: String, arguments: StatementArguments? = nil) -> [Row] {
|
||||
return db.nonIsolatedRead { db in fetchAll(try! db.selectStatement(sql), arguments: arguments) }
|
||||
public static func fetchAll(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> [Row] {
|
||||
return fetchAll(try! db.selectStatement(sql), arguments: arguments)
|
||||
}
|
||||
|
||||
/// Returns a single row fetched from an SQL query.
|
||||
@@ -550,13 +550,13 @@ extension Row {
|
||||
/// let row = Row.fetchOne(db, "SELECT ...")
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An optional row.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(db: DatabaseReader, _ sql: String, arguments: StatementArguments? = nil) -> Row? {
|
||||
return db.nonIsolatedRead { db in fetchOne(try! db.selectStatement(sql), arguments: arguments) }
|
||||
public static func fetchOne(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> Row? {
|
||||
return fetchOne(try! db.selectStatement(sql), arguments: arguments)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -149,13 +149,13 @@ public extension DatabaseValueConvertible where Self: StatementColumnConvertible
|
||||
/// let names = String.fetchAll(db, "SELECT name FROM ...") // [String]
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An array of values.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(db: DatabaseReader, _ sql: String, arguments: StatementArguments? = nil) -> [Self] {
|
||||
return db.nonIsolatedRead { db in fetchAll(try! db.selectStatement(sql), arguments: arguments) }
|
||||
public static func fetchAll(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> [Self] {
|
||||
return fetchAll(try! db.selectStatement(sql), arguments: arguments)
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from an SQL query.
|
||||
@@ -163,12 +163,12 @@ public extension DatabaseValueConvertible where Self: StatementColumnConvertible
|
||||
/// let name = String.fetchOne(db, "SELECT name FROM ...") // String?
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An optional value.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(db: DatabaseReader, _ sql: String, arguments: StatementArguments? = nil) -> Self? {
|
||||
return db.nonIsolatedRead { db in fetchOne(try! db.selectStatement(sql), arguments: arguments) }
|
||||
public static func fetchOne(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> Self? {
|
||||
return fetchOne(try! db.selectStatement(sql), arguments: arguments)
|
||||
}
|
||||
}
|
||||
@@ -167,9 +167,9 @@ extension FetchRequest {
|
||||
|
||||
/// Returns the number of rows matched by the request.
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public func fetchCount(db: DatabaseReader) -> Int {
|
||||
public func fetchCount(db: Database) -> Int {
|
||||
return Int.fetchOne(db, FetchRequest(query: query.countQuery))!
|
||||
}
|
||||
}
|
||||
@@ -225,10 +225,10 @@ extension FetchRequest where T: RowConvertible {
|
||||
/// let request = Person.order(nameColumn)
|
||||
/// let persons = request.fetchAll(db) // [Person]
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public func fetchAll(db: DatabaseReader) -> [T] {
|
||||
return db.nonIsolatedRead { db in Array(self.fetch(db)) }
|
||||
public func fetchAll(db: Database) -> [T] {
|
||||
return Array(fetch(db))
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from a fetch request.
|
||||
@@ -237,10 +237,10 @@ extension FetchRequest where T: RowConvertible {
|
||||
/// let request = Person.order(nameColumn)
|
||||
/// let person = request.fetchOne(db) // Person?
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public func fetchOne(db: DatabaseReader) -> T? {
|
||||
return db.nonIsolatedRead { db in self.fetch(db).generate().next() }
|
||||
public func fetchOne(db: Database) -> T? {
|
||||
return fetch(db).generate().next()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,9 +320,9 @@ extension TableMapping {
|
||||
|
||||
/// Returns the number of records.
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchCount(db: DatabaseReader) -> Int {
|
||||
public static func fetchCount(db: Database) -> Int {
|
||||
return all().fetchCount(db)
|
||||
}
|
||||
}
|
||||
@@ -360,10 +360,10 @@ extension DatabaseValueConvertible {
|
||||
/// let request = Person.select(nameColumn)
|
||||
/// let names = String.fetchAll(db, request) // [String]
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll<T>(db: DatabaseReader, _ request: FetchRequest<T>) -> [Self] {
|
||||
return db.nonIsolatedRead { db in try! fetchAll(request.selectStatement(db)) }
|
||||
public static func fetchAll<T>(db: Database, _ request: FetchRequest<T>) -> [Self] {
|
||||
return try! fetchAll(request.selectStatement(db))
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from a fetch request.
|
||||
@@ -375,10 +375,10 @@ extension DatabaseValueConvertible {
|
||||
/// let request = Person.select(nameColumn)
|
||||
/// let name = String.fetchOne(db, request) // String?
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchOne<T>(db: DatabaseReader, _ request: FetchRequest<T>) -> Self? {
|
||||
return db.nonIsolatedRead { db in try! fetchOne(request.selectStatement(db)) }
|
||||
public static func fetchOne<T>(db: Database, _ request: FetchRequest<T>) -> Self? {
|
||||
return try! fetchOne(request.selectStatement(db))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,10 +415,10 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// let request = Person.select(nameColumn)
|
||||
/// let names = Optional<String>.fetchAll(db, request) // [String?]
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll<T>(db: DatabaseReader, _ request: FetchRequest<T>) -> [Wrapped?] {
|
||||
return db.nonIsolatedRead { db in try! fetchAll(request.selectStatement(db)) }
|
||||
public static func fetchAll<T>(db: Database, _ request: FetchRequest<T>) -> [Wrapped?] {
|
||||
return try! fetchAll(request.selectStatement(db))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,10 +455,10 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// let request = Person.select(nameColumn)
|
||||
/// let names = String.fetchAll(db, request) // [String]
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll<T>(db: DatabaseReader, _ request: FetchRequest<T>) -> [Self] {
|
||||
return db.nonIsolatedRead { db in try! fetchAll(request.selectStatement(db)) }
|
||||
public static func fetchAll<T>(db: Database, _ request: FetchRequest<T>) -> [Self] {
|
||||
return try! fetchAll(request.selectStatement(db))
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from a fetch request.
|
||||
@@ -470,10 +470,10 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// let request = Person.select(nameColumn)
|
||||
/// let name = String.fetchOne(db, request) // String?
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchOne<T>(db: DatabaseReader, _ request: FetchRequest<T>) -> Self? {
|
||||
return db.nonIsolatedRead { db in try! fetchOne(request.selectStatement(db)) }
|
||||
public static func fetchOne<T>(db: Database, _ request: FetchRequest<T>) -> Self? {
|
||||
return try! fetchOne(request.selectStatement(db))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,10 +510,10 @@ extension RowConvertible {
|
||||
/// let request = Person.order(nameColumn)
|
||||
/// let identities = Identity.fetchAll(db, request) // [Identity]
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll<T>(db: DatabaseReader, _ request: FetchRequest<T>) -> [Self] {
|
||||
return db.nonIsolatedRead { db in try! fetchAll(request.selectStatement(db)) }
|
||||
public static func fetchAll<T>(db: Database, _ request: FetchRequest<T>) -> [Self] {
|
||||
return try! fetchAll(request.selectStatement(db))
|
||||
}
|
||||
|
||||
/// Returns a single record fetched from a fetch request.
|
||||
@@ -522,10 +522,10 @@ extension RowConvertible {
|
||||
/// let request = Person.order(nameColumn)
|
||||
/// let identity = Identity.fetchOne(db, request) // Identity?
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchOne<T>(db: DatabaseReader, _ request: FetchRequest<T>) -> Self? {
|
||||
return db.nonIsolatedRead { db in try! fetchOne(request.selectStatement(db)) }
|
||||
public static func fetchOne<T>(db: Database, _ request: FetchRequest<T>) -> Self? {
|
||||
return try! fetchOne(request.selectStatement(db))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,9 +557,9 @@ extension RowConvertible where Self: TableMapping {
|
||||
///
|
||||
/// let persons = Person.fetchAll(db) // [Person]
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(db: DatabaseReader) -> [Self] {
|
||||
public static func fetchAll(db: Database) -> [Self] {
|
||||
return all().fetchAll(db)
|
||||
}
|
||||
|
||||
@@ -567,9 +567,9 @@ extension RowConvertible where Self: TableMapping {
|
||||
///
|
||||
/// let person = Person.fetchOne(db) // Person?
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(db: DatabaseReader) -> Self? {
|
||||
public static func fetchOne(db: Database) -> Self? {
|
||||
return all().fetchOne(db)
|
||||
}
|
||||
}
|
||||
@@ -620,10 +620,10 @@ extension Row {
|
||||
/// let request = Person.select(idColumn, nameColumn)
|
||||
/// let rows = Row.fetchAll(db, request)
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll<T>(db: DatabaseReader, _ request: FetchRequest<T>) -> [Row] {
|
||||
return db.nonIsolatedRead { db in try! fetchAll(request.selectStatement(db)) }
|
||||
public static func fetchAll<T>(db: Database, _ request: FetchRequest<T>) -> [Row] {
|
||||
return try! fetchAll(request.selectStatement(db))
|
||||
}
|
||||
|
||||
/// Returns a single row fetched from a fetch request.
|
||||
@@ -633,9 +633,9 @@ extension Row {
|
||||
/// let request = Person.select(idColumn, nameColumn)
|
||||
/// let row = Row.fetchOne(db, request)
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchOne<T>(db: DatabaseReader, _ request: FetchRequest<T>) -> Row? {
|
||||
return db.nonIsolatedRead { db in try! fetchOne(request.selectStatement(db)) }
|
||||
public static func fetchOne<T>(db: Database, _ request: FetchRequest<T>) -> Row? {
|
||||
return try! fetchOne(request.selectStatement(db))
|
||||
}
|
||||
}
|
||||
@@ -79,8 +79,8 @@ public struct DatabaseMigrator {
|
||||
/// migration has not yet been applied, its block is executed in
|
||||
/// a transaction.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database) where migrations should apply.
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue or DatabasePool) where
|
||||
/// migrations should apply.
|
||||
/// - throws: An eventual error thrown by the registered migration blocks.
|
||||
public func migrate(db: DatabaseWriter) throws {
|
||||
try db.write { db in
|
||||
|
||||
@@ -101,10 +101,9 @@ public protocol MutablePersistable : TableMapping {
|
||||
/// implementation of insert(). In their implementation, it is recommended
|
||||
/// that they invoke the performInsert() method.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
mutating func insert(db: DatabaseWriter) throws
|
||||
mutating func insert(db: Database) throws
|
||||
|
||||
/// Executes an UPDATE statement.
|
||||
///
|
||||
@@ -116,12 +115,11 @@ public protocol MutablePersistable : TableMapping {
|
||||
/// implementation of update(). In their implementation, it is recommended
|
||||
/// that they invoke the performUpdate() method.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
/// PersistenceError.NotFound is thrown if the primary key does not
|
||||
/// match any row in the database.
|
||||
func update(db: DatabaseWriter) throws
|
||||
func update(db: Database) throws
|
||||
|
||||
/// Executes an INSERT or an UPDATE statement so that `self` is saved in
|
||||
/// the database.
|
||||
@@ -139,11 +137,10 @@ public protocol MutablePersistable : TableMapping {
|
||||
/// implementation of save(). In their implementation, it is recommended
|
||||
/// that they invoke the performSave() method.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs, or errors
|
||||
/// thrown by update().
|
||||
mutating func save(db: DatabaseWriter) throws
|
||||
mutating func save(db: Database) throws
|
||||
|
||||
/// Executes a DELETE statement.
|
||||
///
|
||||
@@ -152,11 +149,10 @@ public protocol MutablePersistable : TableMapping {
|
||||
/// implementation of delete(). In their implementation, it is recommended
|
||||
/// that they invoke the performDelete() method.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: Whether a database row was deleted.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
func delete(db: DatabaseWriter) throws -> Bool
|
||||
func delete(db: Database) throws -> Bool
|
||||
|
||||
/// Returns true if and only if the primary key matches a row in
|
||||
/// the database.
|
||||
@@ -166,9 +162,9 @@ public protocol MutablePersistable : TableMapping {
|
||||
/// implementation of exists(). In their implementation, it is recommended
|
||||
/// that they invoke the performExists() method.
|
||||
///
|
||||
/// - parameter db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: Whether the primary key matches a row in the database.
|
||||
func exists(db: DatabaseReader) -> Bool
|
||||
func exists(db: Database) -> Bool
|
||||
}
|
||||
|
||||
public extension MutablePersistable {
|
||||
@@ -185,14 +181,14 @@ public extension MutablePersistable {
|
||||
/// Executes an INSERT statement.
|
||||
///
|
||||
/// The default implementation for insert() invokes performInsert().
|
||||
mutating func insert(db: DatabaseWriter) throws {
|
||||
mutating func insert(db: Database) throws {
|
||||
try performInsert(db)
|
||||
}
|
||||
|
||||
/// Executes an UPDATE statement.
|
||||
///
|
||||
/// The default implementation for update() invokes performUpdate().
|
||||
func update(db: DatabaseWriter) throws {
|
||||
func update(db: Database) throws {
|
||||
try performUpdate(db)
|
||||
}
|
||||
|
||||
@@ -200,14 +196,14 @@ public extension MutablePersistable {
|
||||
/// the database.
|
||||
///
|
||||
/// The default implementation for save() invokes performSave().
|
||||
mutating func save(db: DatabaseWriter) throws {
|
||||
mutating func save(db: Database) throws {
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
/// Executes a DELETE statement.
|
||||
///
|
||||
/// The default implementation for delete() invokes performDelete().
|
||||
func delete(db: DatabaseWriter) throws -> Bool {
|
||||
func delete(db: Database) throws -> Bool {
|
||||
return try performDelete(db)
|
||||
}
|
||||
|
||||
@@ -215,7 +211,7 @@ public extension MutablePersistable {
|
||||
/// the database.
|
||||
///
|
||||
/// The default implementation for exists() invokes performExists().
|
||||
func exists(db: DatabaseReader) -> Bool {
|
||||
func exists(db: Database) -> Bool {
|
||||
return performExists(db)
|
||||
}
|
||||
|
||||
@@ -241,13 +237,11 @@ public extension MutablePersistable {
|
||||
/// that adopt MutablePersistable can invoke performInsert() in their
|
||||
/// implementation of insert(). They should not provide their own
|
||||
/// implementation of performInsert().
|
||||
mutating func performInsert(db: DatabaseWriter) throws {
|
||||
try db.write { db in
|
||||
let dataMapper = DataMapper(db, self)
|
||||
let changes = try dataMapper.insertStatement().execute()
|
||||
if let rowID = changes.insertedRowID {
|
||||
self.didInsertWithRowID(rowID, forColumn: dataMapper.primaryKey.rowIDColumn)
|
||||
}
|
||||
mutating func performInsert(db: Database) throws {
|
||||
let dataMapper = DataMapper(db, self)
|
||||
let changes = try dataMapper.insertStatement().execute()
|
||||
if let rowID = changes.insertedRowID {
|
||||
didInsertWithRowID(rowID, forColumn: dataMapper.primaryKey.rowIDColumn)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,12 +252,10 @@ public extension MutablePersistable {
|
||||
/// that adopt MutablePersistable can invoke performUpdate() in their
|
||||
/// implementation of update(). They should not provide their own
|
||||
/// implementation of performUpdate().
|
||||
func performUpdate(db: DatabaseWriter) throws {
|
||||
try db.write { db in
|
||||
let changes = try DataMapper(db, self).updateStatement().execute()
|
||||
if changes.changedRowCount == 0 {
|
||||
throw PersistenceError.NotFound(self)
|
||||
}
|
||||
func performUpdate(db: Database) throws {
|
||||
let changes = try DataMapper(db, self).updateStatement().execute()
|
||||
if changes.changedRowCount == 0 {
|
||||
throw PersistenceError.NotFound(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,25 +268,23 @@ public extension MutablePersistable {
|
||||
/// implementation of performSave().
|
||||
///
|
||||
/// This default implementation forwards the job to `update` or `insert`.
|
||||
mutating func performSave(db: DatabaseWriter) throws {
|
||||
mutating func performSave(db: Database) throws {
|
||||
// Make sure we call self.insert and self.update so that classes
|
||||
// that override insert or save have opportunity to perform their
|
||||
// custom job.
|
||||
|
||||
try db.write { db in
|
||||
if self.canUpdateInDatabase(db) {
|
||||
do {
|
||||
try self.update(db)
|
||||
} catch PersistenceError.NotFound {
|
||||
// TODO: check that the not persisted objet is self
|
||||
//
|
||||
// Why? Adopting types could override update() and update
|
||||
// another object which may be the one throwing this error.
|
||||
try self.insert(db)
|
||||
}
|
||||
} else {
|
||||
try self.insert(db)
|
||||
if self.canUpdateInDatabase(db) {
|
||||
do {
|
||||
try update(db)
|
||||
} catch PersistenceError.NotFound {
|
||||
// TODO: check that the not persisted objet is self
|
||||
//
|
||||
// Why? Adopting types could override update() and update
|
||||
// another object which may be the one throwing this error.
|
||||
try insert(db)
|
||||
}
|
||||
} else {
|
||||
try insert(db)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,10 +295,8 @@ public extension MutablePersistable {
|
||||
/// that adopt MutablePersistable can invoke performDelete() in
|
||||
/// their implementation of delete(). They should not provide their own
|
||||
/// implementation of performDelete().
|
||||
func performDelete(db: DatabaseWriter) throws -> Bool {
|
||||
return try db.write { db in
|
||||
try DataMapper(db, self).deleteStatement().execute().changedRowCount > 0
|
||||
}
|
||||
func performDelete(db: Database) throws -> Bool {
|
||||
return try DataMapper(db, self).deleteStatement().execute().changedRowCount > 0
|
||||
}
|
||||
|
||||
/// Don't invoke this method directly: it is an internal method for types
|
||||
@@ -318,10 +306,8 @@ public extension MutablePersistable {
|
||||
/// that adopt MutablePersistable can invoke performExists() in
|
||||
/// their implementation of exists(). They should not provide their own
|
||||
/// implementation of performExists().
|
||||
func performExists(db: DatabaseReader) -> Bool {
|
||||
return db.nonIsolatedRead { db in
|
||||
(Row.fetchOne(DataMapper(db, self).existsStatement()) != nil)
|
||||
}
|
||||
func performExists(db: Database) -> Bool {
|
||||
return (Row.fetchOne(DataMapper(db, self).existsStatement()) != nil)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -414,10 +400,9 @@ public protocol Persistable : MutablePersistable {
|
||||
/// implementation of insert(). In their implementation, it is recommended
|
||||
/// that they invoke the performInsert() method.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
func insert(db: DatabaseWriter) throws
|
||||
func insert(db: Database) throws
|
||||
|
||||
/// Executes an INSERT or an UPDATE statement so that `self` is saved in
|
||||
/// the database.
|
||||
@@ -435,11 +420,10 @@ public protocol Persistable : MutablePersistable {
|
||||
/// implementation of save(). In their implementation, it is recommended
|
||||
/// that they invoke the performSave() method.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs, or errors
|
||||
/// thrown by update().
|
||||
func save(db: DatabaseWriter) throws
|
||||
func save(db: Database) throws
|
||||
}
|
||||
|
||||
public extension Persistable {
|
||||
@@ -455,7 +439,7 @@ public extension Persistable {
|
||||
/// Executes an INSERT statement.
|
||||
///
|
||||
/// The default implementation for insert() invokes performInsert().
|
||||
func insert(db: DatabaseWriter) throws {
|
||||
func insert(db: Database) throws {
|
||||
try performInsert(db)
|
||||
}
|
||||
|
||||
@@ -463,7 +447,7 @@ public extension Persistable {
|
||||
/// the database.
|
||||
///
|
||||
/// The default implementation for save() invokes performSave().
|
||||
func save(db: DatabaseWriter) throws {
|
||||
func save(db: Database) throws {
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
@@ -477,13 +461,11 @@ public extension Persistable {
|
||||
/// that adopt Persistable can invoke performInsert() in their
|
||||
/// implementation of insert(). They should not provide their own
|
||||
/// implementation of performInsert().
|
||||
func performInsert(db: DatabaseWriter) throws {
|
||||
try db.write { db in
|
||||
let dataMapper = DataMapper(db, self)
|
||||
let changes = try dataMapper.insertStatement().execute()
|
||||
if let rowID = changes.insertedRowID {
|
||||
self.didInsertWithRowID(rowID, forColumn: dataMapper.primaryKey.rowIDColumn)
|
||||
}
|
||||
func performInsert(db: Database) throws {
|
||||
let dataMapper = DataMapper(db, self)
|
||||
let changes = try dataMapper.insertStatement().execute()
|
||||
if let rowID = changes.insertedRowID {
|
||||
didInsertWithRowID(rowID, forColumn: dataMapper.primaryKey.rowIDColumn)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,24 +478,22 @@ public extension Persistable {
|
||||
/// implementation of performSave().
|
||||
///
|
||||
/// This default implementation forwards the job to `update` or `insert`.
|
||||
func performSave(db: DatabaseWriter) throws {
|
||||
func performSave(db: Database) throws {
|
||||
// Make sure we call self.insert and self.update so that classes that
|
||||
// override insert or save have opportunity to perform their custom job.
|
||||
|
||||
try db.write { db in
|
||||
if self.canUpdateInDatabase(db) {
|
||||
do {
|
||||
try self.update(db)
|
||||
} catch PersistenceError.NotFound {
|
||||
// TODO: check that the not persisted objet is self
|
||||
//
|
||||
// Why? Adopting types could override update() and update another
|
||||
// object which may be the one throwing this error.
|
||||
try self.insert(db)
|
||||
}
|
||||
} else {
|
||||
try self.insert(db)
|
||||
if canUpdateInDatabase(db) {
|
||||
do {
|
||||
try update(db)
|
||||
} catch PersistenceError.NotFound {
|
||||
// TODO: check that the not persisted objet is self
|
||||
//
|
||||
// Why? Adopting types could override update() and update another
|
||||
// object which may be the one throwing this error.
|
||||
try insert(db)
|
||||
}
|
||||
} else {
|
||||
try insert(db)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+35
-43
@@ -201,10 +201,9 @@ public class Record : RowConvertible, TableMapping, Persistable {
|
||||
/// their id automatically set after successful insertion, if it was nil
|
||||
/// before the insertion.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
public func insert(db: DatabaseWriter) throws {
|
||||
public func insert(db: Database) throws {
|
||||
// The simplest code would be:
|
||||
//
|
||||
// try performInsert(db)
|
||||
@@ -217,32 +216,30 @@ public class Record : RowConvertible, TableMapping, Persistable {
|
||||
// So let's provide our custom implementation of insert, which uses the
|
||||
// same persistentDictionary for both insertion, and change tracking.
|
||||
|
||||
try db.write { db in
|
||||
let dataMapper = DataMapper(db, self)
|
||||
var persistentDictionary = dataMapper.persistentDictionary
|
||||
let changes = try dataMapper.insertStatement().execute()
|
||||
if let rowID = changes.insertedRowID {
|
||||
let rowIDColumn = dataMapper.primaryKey.rowIDColumn
|
||||
self.didInsertWithRowID(rowID, forColumn: rowIDColumn)
|
||||
|
||||
// Update persistentDictionary with inserted id, so that we can
|
||||
// set hasPersistentChangedValues to false:
|
||||
if let rowIDColumn = rowIDColumn {
|
||||
if persistentDictionary[rowIDColumn] != nil {
|
||||
persistentDictionary[rowIDColumn] = rowID
|
||||
} else {
|
||||
let rowIDColumn = rowIDColumn.lowercaseString
|
||||
for column in persistentDictionary.keys where column.lowercaseString == rowIDColumn {
|
||||
persistentDictionary[column] = rowID
|
||||
break
|
||||
}
|
||||
let dataMapper = DataMapper(db, self)
|
||||
var persistentDictionary = dataMapper.persistentDictionary
|
||||
let changes = try dataMapper.insertStatement().execute()
|
||||
if let rowID = changes.insertedRowID {
|
||||
let rowIDColumn = dataMapper.primaryKey.rowIDColumn
|
||||
didInsertWithRowID(rowID, forColumn: rowIDColumn)
|
||||
|
||||
// Update persistentDictionary with inserted id, so that we can
|
||||
// set hasPersistentChangedValues to false:
|
||||
if let rowIDColumn = rowIDColumn {
|
||||
if persistentDictionary[rowIDColumn] != nil {
|
||||
persistentDictionary[rowIDColumn] = rowID
|
||||
} else {
|
||||
let rowIDColumn = rowIDColumn.lowercaseString
|
||||
for column in persistentDictionary.keys where column.lowercaseString == rowIDColumn {
|
||||
persistentDictionary[column] = rowID
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set hasPersistentChangedValues to false
|
||||
self.referenceRow = Row(persistentDictionary)
|
||||
}
|
||||
|
||||
// Set hasPersistentChangedValues to false
|
||||
referenceRow = Row(persistentDictionary)
|
||||
}
|
||||
|
||||
/// Executes an UPDATE statement.
|
||||
@@ -253,12 +250,11 @@ public class Record : RowConvertible, TableMapping, Persistable {
|
||||
/// This method is guaranteed to have updated a row in the database if it
|
||||
/// returns without error.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
/// PersistenceError.NotFound is thrown if the primary key does not match
|
||||
/// any row in the database and record could not be updated.
|
||||
public func update(db: DatabaseWriter) throws {
|
||||
public func update(db: Database) throws {
|
||||
// The simplest code would be:
|
||||
//
|
||||
// try performUpdate(db)
|
||||
@@ -270,16 +266,14 @@ public class Record : RowConvertible, TableMapping, Persistable {
|
||||
//
|
||||
// So let's provide our custom implementation of insert, which uses the
|
||||
// same persistentDictionary for both update, and change tracking.
|
||||
try db.write { db in
|
||||
let dataMapper = DataMapper(db, self)
|
||||
let changes = try dataMapper.updateStatement().execute()
|
||||
if changes.changedRowCount == 0 {
|
||||
throw PersistenceError.NotFound(self)
|
||||
}
|
||||
|
||||
// Set hasPersistentChangedValues to false
|
||||
self.referenceRow = Row(dataMapper.persistentDictionary)
|
||||
let dataMapper = DataMapper(db, self)
|
||||
let changes = try dataMapper.updateStatement().execute()
|
||||
if changes.changedRowCount == 0 {
|
||||
throw PersistenceError.NotFound(self)
|
||||
}
|
||||
|
||||
// Set hasPersistentChangedValues to false
|
||||
referenceRow = Row(dataMapper.persistentDictionary)
|
||||
}
|
||||
|
||||
/// Executes an INSERT or an UPDATE statement so that `self` is saved in
|
||||
@@ -296,11 +290,10 @@ public class Record : RowConvertible, TableMapping, Persistable {
|
||||
/// This method is guaranteed to have inserted or updated a row in the
|
||||
/// database if it returns without error.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs, or errors
|
||||
/// thrown by update().
|
||||
final public func save(db: DatabaseWriter) throws {
|
||||
final public func save(db: Database) throws {
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
@@ -309,11 +302,10 @@ public class Record : RowConvertible, TableMapping, Persistable {
|
||||
/// On success, this method sets the *hasPersistentChangedValues* flag
|
||||
/// to true.
|
||||
///
|
||||
/// - parameter db: A DatabaseWriter (DatabaseQueue, DatabasePool, or
|
||||
/// Database).
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: Whether a database row was deleted.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func delete(db: DatabaseWriter) throws -> Bool {
|
||||
public func delete(db: Database) throws -> Bool {
|
||||
defer {
|
||||
// Future calls to update() will throw NotFound. Make the user
|
||||
// a favor and make sure this error is thrown even if she checks the
|
||||
|
||||
@@ -136,13 +136,13 @@ extension RowConvertible {
|
||||
/// let persons = Person.fetchAll(db, "SELECT * FROM persons") // [Person]
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An array of records.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(db: DatabaseReader, _ sql: String, arguments: StatementArguments? = nil) -> [Self] {
|
||||
return db.nonIsolatedRead { db in fetchAll(try! db.selectStatement(sql), arguments: arguments) }
|
||||
public static func fetchAll(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> [Self] {
|
||||
return fetchAll(try! db.selectStatement(sql), arguments: arguments)
|
||||
}
|
||||
|
||||
/// Returns a single record fetched from an SQL query.
|
||||
@@ -150,12 +150,12 @@ extension RowConvertible {
|
||||
/// let person = Person.fetchOne(db, "SELECT * FROM persons") // Person?
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An optional record.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(db: DatabaseReader, _ sql: String, arguments: StatementArguments? = nil) -> Self? {
|
||||
return db.nonIsolatedRead { db in fetchOne(try! db.selectStatement(sql), arguments: arguments) }
|
||||
public static func fetchOne(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> Self? {
|
||||
return fetchOne(try! db.selectStatement(sql), arguments: arguments)
|
||||
}
|
||||
}
|
||||
@@ -42,17 +42,15 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// The order of records in the returned array is undefined.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - keys: A sequence of primary keys.
|
||||
/// - returns: An array of records.
|
||||
@warn_unused_result
|
||||
public static func fetchAll<Sequence: SequenceType where Sequence.Generator.Element: DatabaseValueConvertible>(db: DatabaseReader, keys: Sequence) -> [Self] {
|
||||
return db.nonIsolatedRead { db in
|
||||
guard let statement = fetchByPrimaryKeyStatement(db, values: keys) else {
|
||||
return []
|
||||
}
|
||||
return fetchAll(statement)
|
||||
public static func fetchAll<Sequence: SequenceType where Sequence.Generator.Element: DatabaseValueConvertible>(db: Database, keys: Sequence) -> [Self] {
|
||||
guard let statement = fetchByPrimaryKeyStatement(db, values: keys) else {
|
||||
return []
|
||||
}
|
||||
return fetchAll(statement)
|
||||
}
|
||||
|
||||
/// Returns a single record given its primary key.
|
||||
@@ -60,17 +58,15 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// let person = Person.fetchOne(db, key: 123) // Person?
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - key: A primary key value.
|
||||
/// - returns: An optional record.
|
||||
@warn_unused_result
|
||||
public static func fetchOne<PrimaryKeyType: DatabaseValueConvertible>(db: DatabaseReader, key: PrimaryKeyType?) -> Self? {
|
||||
public static func fetchOne<PrimaryKeyType: DatabaseValueConvertible>(db: Database, key: PrimaryKeyType?) -> Self? {
|
||||
guard let key = key else {
|
||||
return nil
|
||||
}
|
||||
return db.nonIsolatedRead { db in
|
||||
return fetchOne(fetchByPrimaryKeyStatement(db, values: [key])!)
|
||||
}
|
||||
return fetchOne(fetchByPrimaryKeyStatement(db, values: [key])!)
|
||||
}
|
||||
|
||||
// Returns "SELECT * FROM table WHERE id IN (?,?,?)"
|
||||
@@ -136,17 +132,15 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// The order of records in the returned array is undefined.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - keys: An array of key dictionaries.
|
||||
/// - returns: An array of records.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(db: DatabaseReader, keys: [[String: DatabaseValueConvertible?]]) -> [Self] {
|
||||
return db.nonIsolatedRead { db in
|
||||
guard let statement = fetchByKeyStatement(db, keys: keys) else {
|
||||
return []
|
||||
}
|
||||
return fetchAll(statement)
|
||||
public static func fetchAll(db: Database, keys: [[String: DatabaseValueConvertible?]]) -> [Self] {
|
||||
guard let statement = fetchByKeyStatement(db, keys: keys) else {
|
||||
return []
|
||||
}
|
||||
return fetchAll(statement)
|
||||
}
|
||||
|
||||
/// Returns a single record given a key dictionary.
|
||||
@@ -154,12 +148,12 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// let person = Person.fetchOne(db, key: ["name": Arthur"]) // Person?
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A DatabaseReader (DatabaseQueue, DatabasePool, or Database).
|
||||
/// - db: A database connection.
|
||||
/// - key: A dictionary of values.
|
||||
/// - returns: An optional record.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(db: DatabaseReader, key: [String: DatabaseValueConvertible?]) -> Self? {
|
||||
return db.nonIsolatedRead { db in fetchOne(fetchByKeyStatement(db, keys: [key])!) }
|
||||
public static func fetchOne(db: Database, key: [String: DatabaseValueConvertible?]) -> Self? {
|
||||
return fetchOne(fetchByKeyStatement(db, keys: [key])!)
|
||||
}
|
||||
|
||||
// Returns "SELECT * FROM table WHERE (a = ? AND b = ?) OR (a = ? AND b = ?) ...
|
||||
|
||||
@@ -36,10 +36,10 @@ class GRDBTestCase: XCTestCase {
|
||||
private var dbDirectoryPath: String!
|
||||
|
||||
// Populated by default configuration
|
||||
var sqlQueries: [String]!
|
||||
var sqlQueries: [String]! // TODO: protect against concurrent accesses
|
||||
|
||||
// Populated by default configuration
|
||||
var lastSQLQuery: String!
|
||||
var lastSQLQuery: String! // TODO: protect against concurrent accesses
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
@@ -32,9 +32,11 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
// Create and release DatabasePool
|
||||
let dbPool = try makeDatabasePool()
|
||||
// Writer connection
|
||||
try dbPool.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
// Reader connection
|
||||
_ = Int.fetchOne(dbPool, "SELECT COUNT(*) FROM items")
|
||||
dbPool.read { _ in }
|
||||
}
|
||||
|
||||
// One reader, one writer
|
||||
@@ -65,9 +67,11 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
for _ in 0..<2 {
|
||||
try dbPool.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
for _ in 0..<2 {
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
}
|
||||
|
||||
// Block 1 Block 2 Block3
|
||||
@@ -153,7 +157,9 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
let (block1, block2) = { () -> (() -> (), () -> ()) in
|
||||
var dbPool: DatabasePool? = try! makeDatabasePool()
|
||||
try! dbPool!.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try! dbPool!.write { db in
|
||||
try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let block1 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
@@ -221,9 +227,11 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
let (block1, block2) = { () -> (() -> (), () -> ()) in
|
||||
var dbPool: DatabasePool? = try! makeDatabasePool()
|
||||
try! dbPool!.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try! dbPool!.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
try! dbPool!.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
try! dbPool!.write { db in
|
||||
try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
|
||||
let block1 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
|
||||
@@ -70,7 +70,9 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
let (block1, block2) = { () -> (() -> (), () -> ()) in
|
||||
var dbQueue: DatabaseQueue? = try! makeDatabaseQueue()
|
||||
try! dbQueue!.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try! dbQueue!.write { db in
|
||||
try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let block1 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
@@ -138,9 +140,11 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
let (block1, block2) = { () -> (() -> (), () -> ()) in
|
||||
var dbQueue: DatabaseQueue? = try! makeDatabaseQueue()
|
||||
try! dbQueue!.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try! dbQueue!.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
try! dbQueue!.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
try! dbQueue!.write { db in
|
||||
try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
|
||||
let block1 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
|
||||
@@ -7,16 +7,6 @@ import XCTest
|
||||
|
||||
class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
func testUnwrappedReadWrite() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try dbPool.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
let id = Int.fetchOne(dbPool, "SELECT id FROM items")!
|
||||
XCTAssertEqual(id, 1)
|
||||
}
|
||||
}
|
||||
|
||||
func testWrappedReadWrite() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
@@ -12,7 +12,9 @@ class DatabasePoolFileAttributesTests: GRDBTestCase {
|
||||
let dbPool = try makeDatabasePool()
|
||||
let fm = NSFileManager.defaultManager()
|
||||
|
||||
try dbPool.execute("CREATE TABLE foo (bar INTEGER)")
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE foo (bar INTEGER)")
|
||||
}
|
||||
var attributes = try fm.attributesOfItemAtPath(dbPool.path)
|
||||
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
attributes = try fm.attributesOfItemAtPath(dbPool.path + "-wal")
|
||||
@@ -28,7 +30,9 @@ class DatabasePoolFileAttributesTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.execute("CREATE TABLE foo (bar INTEGER)")
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE foo (bar INTEGER)")
|
||||
}
|
||||
var attributes = try fm.attributesOfItemAtPath(dbPool.path)
|
||||
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
attributes = try fm.attributesOfItemAtPath(dbPool.path + "-wal")
|
||||
@@ -59,7 +63,9 @@ class DatabasePoolFileAttributesTests: GRDBTestCase {
|
||||
|
||||
dbConfiguration.fileAttributes = [NSFileExtensionHidden: true]
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.execute("CREATE TABLE foo (bar INTEGER)")
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE foo (bar INTEGER)")
|
||||
}
|
||||
// TODO: this test is fragile: we have to wait until the database
|
||||
// store has been notified of file creation.
|
||||
NSThread.sleepForTimeInterval(0.1)
|
||||
|
||||
@@ -27,7 +27,9 @@ class DatabasePoolReadOnlyTests: GRDBTestCase {
|
||||
let dbPool = try makeDatabasePool(databaseFileName)
|
||||
|
||||
// Make sure the database is not in WAL mode
|
||||
let mode = String.fetchOne(dbPool, "PRAGMA journal_mode")!
|
||||
let mode = dbPool.read { db in
|
||||
String.fetchOne(db, "PRAGMA journal_mode")!
|
||||
}
|
||||
XCTAssertNotEqual(mode.lowercaseString, "wal")
|
||||
|
||||
// Block 1 Block 2
|
||||
|
||||
@@ -24,16 +24,6 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
dbConfiguration.busyMode = .Callback(busyCallback)
|
||||
}
|
||||
|
||||
func testUnwrappedReadWrite() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try dbQueue.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
let id = Int.fetchOne(dbQueue, "SELECT id FROM items")!
|
||||
XCTAssertEqual(id, 1)
|
||||
}
|
||||
}
|
||||
|
||||
func testWrappedReadWrite() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
@@ -55,7 +45,9 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// Work around SQLCipher bug when two connections are open to the
|
||||
// same empty database: make sure the database is not empty before
|
||||
// running this test
|
||||
try dbQueue1.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
}
|
||||
#endif
|
||||
let dbQueue2 = try makeDatabaseQueue()
|
||||
|
||||
@@ -250,7 +242,9 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// Work around SQLCipher bug when two connections are open to the
|
||||
// same empty database: make sure the database is not empty before
|
||||
// running this test
|
||||
try dbQueue1.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
}
|
||||
#endif
|
||||
let dbQueue2 = try makeDatabaseQueue()
|
||||
|
||||
@@ -314,7 +308,9 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// Work around SQLCipher bug when two connections are open to the
|
||||
// same empty database: make sure the database is not empty before
|
||||
// running this test
|
||||
try dbQueue1.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
}
|
||||
#endif
|
||||
let dbQueue2 = try makeDatabaseQueue()
|
||||
|
||||
@@ -380,7 +376,9 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// Work around SQLCipher bug when two connections are open to the
|
||||
// same empty database: make sure the database is not empty before
|
||||
// running this test
|
||||
try dbQueue1.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
}
|
||||
#endif
|
||||
let dbQueue2 = try makeDatabaseQueue()
|
||||
|
||||
|
||||
@@ -5,187 +5,6 @@ import XCTest
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
#if !SQLITE_HAS_CODEC
|
||||
#if os(OSX)
|
||||
import SQLiteMacOSX
|
||||
#elseif os(iOS)
|
||||
#if (arch(i386) || arch(x86_64))
|
||||
import SQLiteiPhoneSimulator
|
||||
#else
|
||||
import SQLiteiPhoneOS
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// A type that adopts DatabaseValueConvertible but does not adopt StatementColumnConvertible
|
||||
private struct WrappedInt: DatabaseValueConvertible {
|
||||
let int: Int
|
||||
init(int: Int) {
|
||||
self.int = int
|
||||
}
|
||||
var databaseValue: DatabaseValue {
|
||||
return int.databaseValue
|
||||
}
|
||||
static func fromDatabaseValue(databaseValue: DatabaseValue) -> WrappedInt? {
|
||||
guard let int = Int.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return WrappedInt(int: int)
|
||||
}
|
||||
}
|
||||
|
||||
// A type that adopts DatabaseValueConvertible and StatementColumnConvertible
|
||||
private struct FastWrappedInt: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
let int: Int
|
||||
let fast: Bool
|
||||
|
||||
init(int: Int, fast: Bool) {
|
||||
self.int = int
|
||||
self.fast = fast
|
||||
}
|
||||
|
||||
init(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
self.init(int: Int(sqlite3_column_int64(sqliteStatement, index)), fast: true)
|
||||
}
|
||||
|
||||
var databaseValue: DatabaseValue {
|
||||
return int.databaseValue
|
||||
}
|
||||
|
||||
static func fromDatabaseValue(databaseValue: DatabaseValue) -> FastWrappedInt? {
|
||||
guard let int = Int.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return FastWrappedInt(int: int, fast: false)
|
||||
}
|
||||
}
|
||||
|
||||
private struct Item: RowConvertible, TableMapping {
|
||||
let id: Int64
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "items"
|
||||
}
|
||||
|
||||
init(_ row: Row) {
|
||||
self.id = row.value(named: "id")
|
||||
}
|
||||
}
|
||||
|
||||
class DatabaseReaderTests : GRDBTestCase {
|
||||
|
||||
func testDatabaseValueConvertibleFetch() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue("DatabaseQueue.swift")
|
||||
let dbPool = try makeDatabasePool("DatabasePool.swift")
|
||||
|
||||
XCTAssertEqual(WrappedInt.fetchOne(dbQueue, "SELECT 123")!.int, 123)
|
||||
XCTAssertEqual(WrappedInt.fetchAll(dbQueue, "SELECT 123 UNION SELECT 321").map { $0.int }, [123, 321])
|
||||
|
||||
XCTAssertEqual(WrappedInt.fetchOne(dbPool, "SELECT 123")!.int, 123)
|
||||
XCTAssertEqual(WrappedInt.fetchAll(dbPool, "SELECT 123 UNION SELECT 321").map { $0.int }, [123, 321])
|
||||
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(WrappedInt.fetchOne(db, "SELECT 123")!.int, 123)
|
||||
XCTAssertEqual(WrappedInt.fetchAll(db, "SELECT 123 UNION SELECT 321").map { $0.int }, [123, 321])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testStatementColumnConvertibleFetch() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue("DatabaseQueue.swift")
|
||||
let dbPool = try makeDatabasePool("DatabasePool.swift")
|
||||
|
||||
XCTAssertEqual(FastWrappedInt.fetchOne(dbQueue, "SELECT 123")!.int, 123)
|
||||
XCTAssertEqual(FastWrappedInt.fetchAll(dbQueue, "SELECT 123 UNION SELECT 321").map { $0.int }, [123, 321])
|
||||
|
||||
XCTAssertEqual(FastWrappedInt.fetchOne(dbPool, "SELECT 123")!.int, 123)
|
||||
XCTAssertEqual(FastWrappedInt.fetchAll(dbPool, "SELECT 123 UNION SELECT 321").map { $0.int }, [123, 321])
|
||||
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(FastWrappedInt.fetchOne(db, "SELECT 123")!.int, 123)
|
||||
XCTAssertEqual(FastWrappedInt.fetchAll(db, "SELECT 123 UNION SELECT 321").map { $0.int }, [123, 321])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRowConvertibleFetch() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue("DatabaseQueue.swift")
|
||||
let dbPool = try makeDatabasePool("DatabasePool.swift")
|
||||
|
||||
XCTAssertEqual(Item.fetchOne(dbQueue, "SELECT 123 AS id")!.id, 123)
|
||||
XCTAssertEqual(Item.fetchAll(dbQueue, "SELECT 123 AS id UNION SELECT 321").map { $0.id }, [123, 321])
|
||||
|
||||
XCTAssertEqual(Item.fetchOne(dbPool, "SELECT 123 AS id")!.id, 123)
|
||||
XCTAssertEqual(Item.fetchAll(dbPool, "SELECT 123 AS id UNION SELECT 321").map { $0.id }, [123, 321])
|
||||
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(Item.fetchOne(db, "SELECT 123 AS id")!.id, 123)
|
||||
XCTAssertEqual(Item.fetchAll(db, "SELECT 123 AS id UNION SELECT 321").map { $0.id }, [123, 321])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testTableMappingFetch() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue("DatabaseQueue.swift")
|
||||
let dbPool = try makeDatabasePool("DatabasePool.swift")
|
||||
|
||||
let populateDatabase = { (db: Database) -> () in
|
||||
try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
|
||||
try dbQueue.inDatabase { db in try populateDatabase(db) }
|
||||
try dbPool.write { db in try populateDatabase(db) }
|
||||
|
||||
|
||||
XCTAssertEqual(Item.fetchOne(dbQueue, key: 1)!.id, 1)
|
||||
XCTAssertEqual(Item.fetchAll(dbQueue, keys: [1, 2]).map { $0.id }, [1, 2])
|
||||
|
||||
XCTAssertEqual(Item.fetchOne(dbPool, key: 1)!.id, 1)
|
||||
XCTAssertEqual(Item.fetchAll(dbPool, keys: [1, 2]).map { $0.id }, [1, 2])
|
||||
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(Item.fetchOne(db, key: 1)!.id, 1)
|
||||
XCTAssertEqual(Item.fetchAll(db, keys: [1, 2]).map { $0.id }, [1, 2])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchRequestFetch() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue("DatabaseQueue.swift")
|
||||
let dbPool = try makeDatabasePool("DatabasePool.swift")
|
||||
|
||||
let populateDatabase = { (db: Database) -> () in
|
||||
try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
|
||||
try dbQueue.inDatabase { db in try populateDatabase(db) }
|
||||
try dbPool.write { db in try populateDatabase(db) }
|
||||
|
||||
let idCol = SQLColumn("id")
|
||||
|
||||
XCTAssertEqual(Item.filter(idCol == 1).fetchOne(dbQueue)!.id, 1)
|
||||
XCTAssertEqual(Item.all().fetchAll(dbQueue).map { $0.id }, [1, 2])
|
||||
XCTAssertEqual(Item.filter(idCol == 1).fetchCount(dbQueue), 1)
|
||||
|
||||
XCTAssertEqual(Item.filter(idCol == 1).fetchOne(dbPool)!.id, 1)
|
||||
XCTAssertEqual(Item.all().fetchAll(dbPool).map { $0.id }, [1, 2])
|
||||
XCTAssertEqual(Item.filter(idCol == 1).fetchCount(dbPool), 1)
|
||||
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(Item.filter(idCol == 1).fetchOne(db)!.id, 1)
|
||||
XCTAssertEqual(Item.all().fetchAll(db).map { $0.id }, [1, 2])
|
||||
XCTAssertEqual(Item.filter(idCol == 1).fetchCount(db), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
}
|
||||
@@ -24,29 +24,31 @@ class FunctionTests: GRDBTestCase {
|
||||
func testDefaultFunctions() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
|
||||
// Those functions are automatically added to all connections.
|
||||
// See Database.setupDefaultFunctions()
|
||||
// Those functions are automatically added to all connections.
|
||||
// See Database.setupDefaultFunctions()
|
||||
|
||||
let capitalizedString = DatabaseFunction.capitalizedString
|
||||
XCTAssertEqual(String.fetchOne(dbQueue, "SELECT \(capitalizedString.name)('jérÔME')"), "Jérôme")
|
||||
|
||||
let lowercaseString = DatabaseFunction.lowercaseString
|
||||
XCTAssertEqual(String.fetchOne(dbQueue, "SELECT \(lowercaseString.name)('jérÔME')"), "jérôme")
|
||||
|
||||
let uppercaseString = DatabaseFunction.uppercaseString
|
||||
XCTAssertEqual(String.fetchOne(dbQueue, "SELECT \(uppercaseString.name)('jérÔME')"), "JÉRÔME")
|
||||
|
||||
// Locale-dependent tests. Are they fragile?
|
||||
|
||||
let localizedCapitalizedString = DatabaseFunction.localizedCapitalizedString
|
||||
XCTAssertEqual(String.fetchOne(dbQueue, "SELECT \(localizedCapitalizedString.name)('jérÔME')"), "Jérôme")
|
||||
|
||||
let localizedLowercaseString = DatabaseFunction.localizedLowercaseString
|
||||
XCTAssertEqual(String.fetchOne(dbQueue, "SELECT \(localizedLowercaseString.name)('jérÔME')"), "jérôme")
|
||||
|
||||
let localizedUppercaseString = DatabaseFunction.localizedUppercaseString
|
||||
XCTAssertEqual(String.fetchOne(dbQueue, "SELECT \(localizedUppercaseString.name)('jérÔME')"), "JÉRÔME")
|
||||
let capitalizedString = DatabaseFunction.capitalizedString
|
||||
XCTAssertEqual(String.fetchOne(db, "SELECT \(capitalizedString.name)('jérÔME')"), "Jérôme")
|
||||
|
||||
let lowercaseString = DatabaseFunction.lowercaseString
|
||||
XCTAssertEqual(String.fetchOne(db, "SELECT \(lowercaseString.name)('jérÔME')"), "jérôme")
|
||||
|
||||
let uppercaseString = DatabaseFunction.uppercaseString
|
||||
XCTAssertEqual(String.fetchOne(db, "SELECT \(uppercaseString.name)('jérÔME')"), "JÉRÔME")
|
||||
|
||||
// Locale-dependent tests. Are they fragile?
|
||||
|
||||
let localizedCapitalizedString = DatabaseFunction.localizedCapitalizedString
|
||||
XCTAssertEqual(String.fetchOne(db, "SELECT \(localizedCapitalizedString.name)('jérÔME')"), "Jérôme")
|
||||
|
||||
let localizedLowercaseString = DatabaseFunction.localizedLowercaseString
|
||||
XCTAssertEqual(String.fetchOne(db, "SELECT \(localizedLowercaseString.name)('jérÔME')"), "jérôme")
|
||||
|
||||
let localizedUppercaseString = DatabaseFunction.localizedUppercaseString
|
||||
XCTAssertEqual(String.fetchOne(db, "SELECT \(localizedUppercaseString.name)('jérÔME')"), "JÉRÔME")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,416 +0,0 @@
|
||||
import XCTest
|
||||
#if SQLITE_HAS_CODEC
|
||||
import GRDBCipher
|
||||
#else
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
private struct MutablePersistablePerson : MutablePersistable {
|
||||
var id: Int64?
|
||||
var name: String?
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "name": name]
|
||||
}
|
||||
|
||||
mutating func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.id = rowID
|
||||
}
|
||||
}
|
||||
|
||||
private struct MutablePersistableCountry : MutablePersistable {
|
||||
var rowID: Int64?
|
||||
var isoCode: String
|
||||
var name: String
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
|
||||
mutating func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.rowID = rowID
|
||||
}
|
||||
}
|
||||
|
||||
private struct MutablePersistableCustomizedCountry : MutablePersistable {
|
||||
var rowID: Int64?
|
||||
var isoCode: String
|
||||
var name: String
|
||||
let willInsert: Void -> Void
|
||||
let willUpdate: Void -> Void
|
||||
let willSave: Void -> Void
|
||||
let willDelete: Void -> Void
|
||||
let willExists: Void -> Void
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
|
||||
mutating func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.rowID = rowID
|
||||
}
|
||||
|
||||
mutating func insert(db: DatabaseWriter) throws {
|
||||
willInsert()
|
||||
try performInsert(db)
|
||||
}
|
||||
|
||||
func update(db: DatabaseWriter) throws {
|
||||
willUpdate()
|
||||
try performUpdate(db)
|
||||
}
|
||||
|
||||
mutating func save(db: DatabaseWriter) throws {
|
||||
willSave()
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
func delete(db: DatabaseWriter) throws {
|
||||
willDelete()
|
||||
try performDelete(db)
|
||||
}
|
||||
|
||||
func exists(db: DatabaseReader) -> Bool {
|
||||
willExists()
|
||||
return performExists(db)
|
||||
}
|
||||
}
|
||||
|
||||
class DatabasePoolMutablePersistableTests: GRDBTestCase {
|
||||
|
||||
override func setUpDatabase(dbWriter: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("setUp") { db in
|
||||
try db.execute(
|
||||
"CREATE TABLE persons (" +
|
||||
"id INTEGER PRIMARY KEY, " +
|
||||
"name NOT NULL " +
|
||||
")")
|
||||
try db.execute(
|
||||
"CREATE TABLE countries (" +
|
||||
"isoCode TEXT NOT NULL PRIMARY KEY, " +
|
||||
"name TEXT NOT NULL " +
|
||||
")")
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - MutablePersistablePerson
|
||||
|
||||
func testInsertMutablePersistablePerson() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var person = MutablePersistablePerson(id: nil, name: "Arthur")
|
||||
try person.insert(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM persons")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Arthur")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdateMutablePersistablePerson() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var person1 = MutablePersistablePerson(id: nil, name: "Arthur")
|
||||
try person1.insert(dbPool)
|
||||
var person2 = MutablePersistablePerson(id: nil, name: "Barbara")
|
||||
try person2.insert(dbPool)
|
||||
|
||||
person1.name = "Craig"
|
||||
try person1.update(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM persons ORDER BY id")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person1.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Craig")
|
||||
XCTAssertEqual(rows[1].value(named: "id") as Int64, person2.id!)
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "Barbara")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeleteMutablePersistablePerson() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var person1 = MutablePersistablePerson(id: nil, name: "Arthur")
|
||||
try person1.insert(dbPool)
|
||||
var person2 = MutablePersistablePerson(id: nil, name: "Barbara")
|
||||
try person2.insert(dbPool)
|
||||
|
||||
try person1.delete(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM persons ORDER BY id")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person2.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Barbara")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsMutablePersistablePerson() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var person = MutablePersistablePerson(id: nil, name: "Arthur")
|
||||
try person.insert(dbPool)
|
||||
XCTAssertTrue(person.exists(dbPool))
|
||||
|
||||
try person.delete(dbPool)
|
||||
|
||||
XCTAssertFalse(person.exists(dbPool))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - MutablePersistableCountry
|
||||
|
||||
func testInsertMutablePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var country = MutablePersistableCountry(rowID: nil, isoCode: "FR", name: "France")
|
||||
try country.insert(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT rowID, * FROM countries")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdateMutablePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var country1 = MutablePersistableCountry(rowID: nil, isoCode: "FR", name: "France")
|
||||
try country1.insert(dbPool)
|
||||
var country2 = MutablePersistableCountry(rowID: nil, isoCode: "US", name: "United States")
|
||||
try country2.insert(dbPool)
|
||||
|
||||
country1.name = "France Métropolitaine"
|
||||
try country1.update(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT rowID, * FROM countries ORDER BY rowID")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country1.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France Métropolitaine")
|
||||
XCTAssertEqual(rows[1].value(named: "rowID") as Int64, country2.rowID!)
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeleteMutablePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var country1 = MutablePersistableCountry(rowID: nil, isoCode: "FR", name: "France")
|
||||
try country1.insert(dbPool)
|
||||
var country2 = MutablePersistableCountry(rowID: nil, isoCode: "US", name: "United States")
|
||||
try country2.insert(dbPool)
|
||||
|
||||
try country1.delete(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT rowID, * FROM countries ORDER BY rowID")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country2.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsMutablePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var country = MutablePersistableCountry(rowID: nil, isoCode: "FR", name: "France")
|
||||
try country.insert(dbPool)
|
||||
XCTAssertTrue(country.exists(dbPool))
|
||||
|
||||
try country.delete(dbPool)
|
||||
|
||||
XCTAssertFalse(country.exists(dbPool))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - MutablePersistableCustomizedCountry
|
||||
|
||||
func testInsertMutablePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
var country = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country.insert(dbPool)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT rowID, * FROM countries")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdateMutablePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
var country1 = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country1.insert(dbPool)
|
||||
var country2 = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "US",
|
||||
name: "United States",
|
||||
willInsert: { },
|
||||
willUpdate: { },
|
||||
willSave: { },
|
||||
willDelete: { },
|
||||
willExists: { })
|
||||
try country2.insert(dbPool)
|
||||
|
||||
country1.name = "France Métropolitaine"
|
||||
try country1.update(dbPool)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 1)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT rowID, * FROM countries ORDER BY rowID")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country1.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France Métropolitaine")
|
||||
XCTAssertEqual(rows[1].value(named: "rowID") as Int64, country2.rowID!)
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeleteMutablePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
var country1 = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country1.insert(dbPool)
|
||||
var country2 = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "US",
|
||||
name: "United States",
|
||||
willInsert: { },
|
||||
willUpdate: { },
|
||||
willSave: { },
|
||||
willDelete: { },
|
||||
willExists: { })
|
||||
try country2.insert(dbPool)
|
||||
|
||||
try country1.delete(dbPool)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 1)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT rowID, * FROM countries ORDER BY rowID")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country2.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsMutablePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
var country = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country.insert(dbPool)
|
||||
|
||||
XCTAssertTrue(country.exists(dbPool))
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 1)
|
||||
|
||||
try country.delete(dbPool)
|
||||
|
||||
XCTAssertFalse(country.exists(dbPool))
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 1)
|
||||
XCTAssertEqual(existsCount, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,437 +0,0 @@
|
||||
import XCTest
|
||||
#if SQLITE_HAS_CODEC
|
||||
import GRDBCipher
|
||||
#else
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
private struct PersistablePerson : Persistable {
|
||||
var name: String?
|
||||
var age: Int?
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["name": name, "age": age]
|
||||
}
|
||||
}
|
||||
|
||||
private class PersistablePersonClass : Persistable {
|
||||
var id: Int64?
|
||||
var name: String?
|
||||
var age: Int?
|
||||
|
||||
init(id: Int64?, name: String?, age: Int?) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.age = age
|
||||
}
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "name": name, "age": age]
|
||||
}
|
||||
|
||||
func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.id = rowID
|
||||
}
|
||||
}
|
||||
|
||||
private struct PersistableCountry : Persistable {
|
||||
var isoCode: String
|
||||
var name: String
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
}
|
||||
|
||||
private struct PersistableCustomizedCountry : Persistable {
|
||||
var isoCode: String
|
||||
var name: String
|
||||
let willInsert: Void -> Void
|
||||
let willUpdate: Void -> Void
|
||||
let willSave: Void -> Void
|
||||
let willDelete: Void -> Void
|
||||
let willExists: Void -> Void
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
|
||||
func insert(db: DatabaseWriter) throws {
|
||||
willInsert()
|
||||
try performInsert(db)
|
||||
}
|
||||
|
||||
func update(db: DatabaseWriter) throws {
|
||||
willUpdate()
|
||||
try performUpdate(db)
|
||||
}
|
||||
|
||||
func save(db: DatabaseWriter) throws {
|
||||
willSave()
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
func delete(db: DatabaseWriter) throws {
|
||||
willDelete()
|
||||
try performDelete(db)
|
||||
}
|
||||
|
||||
func exists(db: DatabaseReader) -> Bool {
|
||||
willExists()
|
||||
return performExists(db)
|
||||
}
|
||||
}
|
||||
|
||||
class DatabasePoolPersistableTests: GRDBTestCase {
|
||||
|
||||
override func setUpDatabase(dbWriter: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("setUp") { db in
|
||||
try db.execute(
|
||||
"CREATE TABLE persons (" +
|
||||
"id INTEGER PRIMARY KEY, " +
|
||||
"name TEXT NOT NULL, " +
|
||||
"age INT NOT NULL " +
|
||||
")")
|
||||
try db.execute(
|
||||
"CREATE TABLE countries (" +
|
||||
"isoCode TEXT NOT NULL PRIMARY KEY, " +
|
||||
"name TEXT NOT NULL " +
|
||||
")")
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - PersistablePerson
|
||||
|
||||
func testInsertPersistablePerson() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
let person = PersistablePerson(name: "Arthur", age: 42)
|
||||
try person.insert(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM persons")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Arthur")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - PersistablePersonClass
|
||||
|
||||
func testInsertPersistablePersonClass() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
let person = PersistablePersonClass(id: nil, name: "Arthur", age: 42)
|
||||
try person.insert(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM persons")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Arthur")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdatePersistablePersonClass() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
let person1 = PersistablePersonClass(id: nil, name: "Arthur", age: 42)
|
||||
try person1.insert(dbPool)
|
||||
let person2 = PersistablePersonClass(id: nil, name: "Barbara", age: 39)
|
||||
try person2.insert(dbPool)
|
||||
|
||||
person1.name = "Craig"
|
||||
try person1.update(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM persons ORDER BY id")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person1.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Craig")
|
||||
XCTAssertEqual(rows[1].value(named: "id") as Int64, person2.id!)
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "Barbara")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeletePersistablePersonClass() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
let person1 = PersistablePersonClass(id: nil, name: "Arthur", age: 42)
|
||||
try person1.insert(dbPool)
|
||||
let person2 = PersistablePersonClass(id: nil, name: "Barbara", age: 39)
|
||||
try person2.insert(dbPool)
|
||||
|
||||
try person1.delete(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM persons ORDER BY id")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person2.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Barbara")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsPersistablePersonClass() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
let person = PersistablePersonClass(id: nil, name: "Arthur", age: 42)
|
||||
try person.insert(dbPool)
|
||||
XCTAssertTrue(person.exists(dbPool))
|
||||
|
||||
try person.delete(dbPool)
|
||||
|
||||
XCTAssertFalse(person.exists(dbPool))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - PersistableCountry
|
||||
|
||||
func testInsertPersistableCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
let country = PersistableCountry(isoCode: "FR", name: "France")
|
||||
try country.insert(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM countries")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "FR")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdatePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var country1 = PersistableCountry(isoCode: "FR", name: "France")
|
||||
try country1.insert(dbPool)
|
||||
let country2 = PersistableCountry(isoCode: "US", name: "United States")
|
||||
try country2.insert(dbPool)
|
||||
|
||||
country1.name = "France Métropolitaine"
|
||||
try country1.update(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM countries ORDER BY isoCode")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "FR")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France Métropolitaine")
|
||||
XCTAssertEqual(rows[1].value(named: "isoCode") as String, "US")
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeletePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
let country1 = PersistableCountry(isoCode: "FR", name: "France")
|
||||
try country1.insert(dbPool)
|
||||
let country2 = PersistableCountry(isoCode: "US", name: "United States")
|
||||
try country2.insert(dbPool)
|
||||
|
||||
try country1.delete(dbPool)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM countries ORDER BY isoCode")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "US")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsPersistableCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
let country = PersistableCountry(isoCode: "FR", name: "France")
|
||||
try country.insert(dbPool)
|
||||
XCTAssertTrue(country.exists(dbPool))
|
||||
|
||||
try country.delete(dbPool)
|
||||
|
||||
XCTAssertFalse(country.exists(dbPool))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - PersistableCustomizedCountry
|
||||
|
||||
func testInsertPersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
let country = PersistableCustomizedCountry(
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country.insert(dbPool)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM countries")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "FR")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdatePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
var country1 = PersistableCustomizedCountry(
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country1.insert(dbPool)
|
||||
let country2 = PersistableCustomizedCountry(
|
||||
isoCode: "US",
|
||||
name: "United States",
|
||||
willInsert: { },
|
||||
willUpdate: { },
|
||||
willSave: { },
|
||||
willDelete: { },
|
||||
willExists: { })
|
||||
try country2.insert(dbPool)
|
||||
|
||||
country1.name = "France Métropolitaine"
|
||||
try country1.update(dbPool)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 1)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM countries ORDER BY isoCode")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "FR")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France Métropolitaine")
|
||||
XCTAssertEqual(rows[1].value(named: "isoCode") as String, "US")
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeletePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
let country1 = PersistableCustomizedCountry(
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country1.insert(dbPool)
|
||||
let country2 = PersistableCustomizedCountry(
|
||||
isoCode: "US",
|
||||
name: "United States",
|
||||
willInsert: { },
|
||||
willUpdate: { },
|
||||
willSave: { },
|
||||
willDelete: { },
|
||||
willExists: { })
|
||||
try country2.insert(dbPool)
|
||||
|
||||
try country1.delete(dbPool)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 1)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbPool, "SELECT * FROM countries ORDER BY isoCode")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "US")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsPersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
let country = PersistableCustomizedCountry(
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country.insert(dbPool)
|
||||
|
||||
XCTAssertTrue(country.exists(dbPool))
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 1)
|
||||
|
||||
try country.delete(dbPool)
|
||||
|
||||
XCTAssertFalse(country.exists(dbPool))
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 1)
|
||||
XCTAssertEqual(existsCount, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,416 +0,0 @@
|
||||
import XCTest
|
||||
#if SQLITE_HAS_CODEC
|
||||
import GRDBCipher
|
||||
#else
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
private struct MutablePersistablePerson : MutablePersistable {
|
||||
var id: Int64?
|
||||
var name: String?
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "name": name]
|
||||
}
|
||||
|
||||
mutating func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.id = rowID
|
||||
}
|
||||
}
|
||||
|
||||
private struct MutablePersistableCountry : MutablePersistable {
|
||||
var rowID: Int64?
|
||||
var isoCode: String
|
||||
var name: String
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
|
||||
mutating func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.rowID = rowID
|
||||
}
|
||||
}
|
||||
|
||||
private struct MutablePersistableCustomizedCountry : MutablePersistable {
|
||||
var rowID: Int64?
|
||||
var isoCode: String
|
||||
var name: String
|
||||
let willInsert: Void -> Void
|
||||
let willUpdate: Void -> Void
|
||||
let willSave: Void -> Void
|
||||
let willDelete: Void -> Void
|
||||
let willExists: Void -> Void
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
|
||||
mutating func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.rowID = rowID
|
||||
}
|
||||
|
||||
mutating func insert(db: DatabaseWriter) throws {
|
||||
willInsert()
|
||||
try performInsert(db)
|
||||
}
|
||||
|
||||
func update(db: DatabaseWriter) throws {
|
||||
willUpdate()
|
||||
try performUpdate(db)
|
||||
}
|
||||
|
||||
mutating func save(db: DatabaseWriter) throws {
|
||||
willSave()
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
func delete(db: DatabaseWriter) throws {
|
||||
willDelete()
|
||||
try performDelete(db)
|
||||
}
|
||||
|
||||
func exists(db: DatabaseReader) -> Bool {
|
||||
willExists()
|
||||
return performExists(db)
|
||||
}
|
||||
}
|
||||
|
||||
class DatabaseQueueMutablePersistableTests: GRDBTestCase {
|
||||
|
||||
override func setUpDatabase(dbWriter: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("setUp") { db in
|
||||
try db.execute(
|
||||
"CREATE TABLE persons (" +
|
||||
"id INTEGER PRIMARY KEY, " +
|
||||
"name NOT NULL " +
|
||||
")")
|
||||
try db.execute(
|
||||
"CREATE TABLE countries (" +
|
||||
"isoCode TEXT NOT NULL PRIMARY KEY, " +
|
||||
"name TEXT NOT NULL " +
|
||||
")")
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - MutablePersistablePerson
|
||||
|
||||
func testInsertMutablePersistablePerson() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var person = MutablePersistablePerson(id: nil, name: "Arthur")
|
||||
try person.insert(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM persons")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Arthur")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdateMutablePersistablePerson() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var person1 = MutablePersistablePerson(id: nil, name: "Arthur")
|
||||
try person1.insert(dbQueue)
|
||||
var person2 = MutablePersistablePerson(id: nil, name: "Barbara")
|
||||
try person2.insert(dbQueue)
|
||||
|
||||
person1.name = "Craig"
|
||||
try person1.update(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM persons ORDER BY id")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person1.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Craig")
|
||||
XCTAssertEqual(rows[1].value(named: "id") as Int64, person2.id!)
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "Barbara")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeleteMutablePersistablePerson() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var person1 = MutablePersistablePerson(id: nil, name: "Arthur")
|
||||
try person1.insert(dbQueue)
|
||||
var person2 = MutablePersistablePerson(id: nil, name: "Barbara")
|
||||
try person2.insert(dbQueue)
|
||||
|
||||
try person1.delete(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM persons ORDER BY id")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person2.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Barbara")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsMutablePersistablePerson() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var person = MutablePersistablePerson(id: nil, name: "Arthur")
|
||||
try person.insert(dbQueue)
|
||||
XCTAssertTrue(person.exists(dbQueue))
|
||||
|
||||
try person.delete(dbQueue)
|
||||
|
||||
XCTAssertFalse(person.exists(dbQueue))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - MutablePersistableCountry
|
||||
|
||||
func testInsertMutablePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var country = MutablePersistableCountry(rowID: nil, isoCode: "FR", name: "France")
|
||||
try country.insert(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT rowID, * FROM countries")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdateMutablePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var country1 = MutablePersistableCountry(rowID: nil, isoCode: "FR", name: "France")
|
||||
try country1.insert(dbQueue)
|
||||
var country2 = MutablePersistableCountry(rowID: nil, isoCode: "US", name: "United States")
|
||||
try country2.insert(dbQueue)
|
||||
|
||||
country1.name = "France Métropolitaine"
|
||||
try country1.update(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT rowID, * FROM countries ORDER BY rowID")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country1.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France Métropolitaine")
|
||||
XCTAssertEqual(rows[1].value(named: "rowID") as Int64, country2.rowID!)
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeleteMutablePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var country1 = MutablePersistableCountry(rowID: nil, isoCode: "FR", name: "France")
|
||||
try country1.insert(dbQueue)
|
||||
var country2 = MutablePersistableCountry(rowID: nil, isoCode: "US", name: "United States")
|
||||
try country2.insert(dbQueue)
|
||||
|
||||
try country1.delete(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT rowID, * FROM countries ORDER BY rowID")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country2.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsMutablePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var country = MutablePersistableCountry(rowID: nil, isoCode: "FR", name: "France")
|
||||
try country.insert(dbQueue)
|
||||
XCTAssertTrue(country.exists(dbQueue))
|
||||
|
||||
try country.delete(dbQueue)
|
||||
|
||||
XCTAssertFalse(country.exists(dbQueue))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - MutablePersistableCustomizedCountry
|
||||
|
||||
func testInsertMutablePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
var country = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country.insert(dbQueue)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT rowID, * FROM countries")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdateMutablePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
var country1 = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country1.insert(dbQueue)
|
||||
var country2 = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "US",
|
||||
name: "United States",
|
||||
willInsert: { },
|
||||
willUpdate: { },
|
||||
willSave: { },
|
||||
willDelete: { },
|
||||
willExists: { })
|
||||
try country2.insert(dbQueue)
|
||||
|
||||
country1.name = "France Métropolitaine"
|
||||
try country1.update(dbQueue)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 1)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT rowID, * FROM countries ORDER BY rowID")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country1.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France Métropolitaine")
|
||||
XCTAssertEqual(rows[1].value(named: "rowID") as Int64, country2.rowID!)
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeleteMutablePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
var country1 = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country1.insert(dbQueue)
|
||||
var country2 = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "US",
|
||||
name: "United States",
|
||||
willInsert: { },
|
||||
willUpdate: { },
|
||||
willSave: { },
|
||||
willDelete: { },
|
||||
willExists: { })
|
||||
try country2.insert(dbQueue)
|
||||
|
||||
try country1.delete(dbQueue)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 1)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT rowID, * FROM countries ORDER BY rowID")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "rowID") as Int64, country2.rowID!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsMutablePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
var country = MutablePersistableCustomizedCountry(
|
||||
rowID: nil,
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country.insert(dbQueue)
|
||||
|
||||
XCTAssertTrue(country.exists(dbQueue))
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 1)
|
||||
|
||||
try country.delete(dbQueue)
|
||||
|
||||
XCTAssertFalse(country.exists(dbQueue))
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 1)
|
||||
XCTAssertEqual(existsCount, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,437 +0,0 @@
|
||||
import XCTest
|
||||
#if SQLITE_HAS_CODEC
|
||||
import GRDBCipher
|
||||
#else
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
private struct PersistablePerson : Persistable {
|
||||
var name: String?
|
||||
var age: Int?
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["name": name, "age": age]
|
||||
}
|
||||
}
|
||||
|
||||
private class PersistablePersonClass : Persistable {
|
||||
var id: Int64?
|
||||
var name: String?
|
||||
var age: Int?
|
||||
|
||||
init(id: Int64?, name: String?, age: Int?) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.age = age
|
||||
}
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "name": name, "age": age]
|
||||
}
|
||||
|
||||
func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.id = rowID
|
||||
}
|
||||
}
|
||||
|
||||
private struct PersistableCountry : Persistable {
|
||||
var isoCode: String
|
||||
var name: String
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
}
|
||||
|
||||
private struct PersistableCustomizedCountry : Persistable {
|
||||
var isoCode: String
|
||||
var name: String
|
||||
let willInsert: Void -> Void
|
||||
let willUpdate: Void -> Void
|
||||
let willSave: Void -> Void
|
||||
let willDelete: Void -> Void
|
||||
let willExists: Void -> Void
|
||||
|
||||
static func databaseTableName() -> String {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
|
||||
func insert(db: DatabaseWriter) throws {
|
||||
willInsert()
|
||||
try performInsert(db)
|
||||
}
|
||||
|
||||
func update(db: DatabaseWriter) throws {
|
||||
willUpdate()
|
||||
try performUpdate(db)
|
||||
}
|
||||
|
||||
func save(db: DatabaseWriter) throws {
|
||||
willSave()
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
func delete(db: DatabaseWriter) throws {
|
||||
willDelete()
|
||||
try performDelete(db)
|
||||
}
|
||||
|
||||
func exists(db: DatabaseReader) -> Bool {
|
||||
willExists()
|
||||
return performExists(db)
|
||||
}
|
||||
}
|
||||
|
||||
class DatabaseQueuePersistableTests: GRDBTestCase {
|
||||
|
||||
override func setUpDatabase(dbWriter: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("setUp") { db in
|
||||
try db.execute(
|
||||
"CREATE TABLE persons (" +
|
||||
"id INTEGER PRIMARY KEY, " +
|
||||
"name TEXT NOT NULL, " +
|
||||
"age INT NOT NULL " +
|
||||
")")
|
||||
try db.execute(
|
||||
"CREATE TABLE countries (" +
|
||||
"isoCode TEXT NOT NULL PRIMARY KEY, " +
|
||||
"name TEXT NOT NULL " +
|
||||
")")
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - PersistablePerson
|
||||
|
||||
func testInsertPersistablePerson() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
let person = PersistablePerson(name: "Arthur", age: 42)
|
||||
try person.insert(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM persons")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Arthur")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - PersistablePersonClass
|
||||
|
||||
func testInsertPersistablePersonClass() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
let person = PersistablePersonClass(id: nil, name: "Arthur", age: 42)
|
||||
try person.insert(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM persons")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Arthur")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdatePersistablePersonClass() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
let person1 = PersistablePersonClass(id: nil, name: "Arthur", age: 42)
|
||||
try person1.insert(dbQueue)
|
||||
let person2 = PersistablePersonClass(id: nil, name: "Barbara", age: 39)
|
||||
try person2.insert(dbQueue)
|
||||
|
||||
person1.name = "Craig"
|
||||
try person1.update(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM persons ORDER BY id")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person1.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Craig")
|
||||
XCTAssertEqual(rows[1].value(named: "id") as Int64, person2.id!)
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "Barbara")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeletePersistablePersonClass() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
let person1 = PersistablePersonClass(id: nil, name: "Arthur", age: 42)
|
||||
try person1.insert(dbQueue)
|
||||
let person2 = PersistablePersonClass(id: nil, name: "Barbara", age: 39)
|
||||
try person2.insert(dbQueue)
|
||||
|
||||
try person1.delete(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM persons ORDER BY id")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "id") as Int64, person2.id!)
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "Barbara")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsPersistablePersonClass() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
let person = PersistablePersonClass(id: nil, name: "Arthur", age: 42)
|
||||
try person.insert(dbQueue)
|
||||
XCTAssertTrue(person.exists(dbQueue))
|
||||
|
||||
try person.delete(dbQueue)
|
||||
|
||||
XCTAssertFalse(person.exists(dbQueue))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - PersistableCountry
|
||||
|
||||
func testInsertPersistableCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
let country = PersistableCountry(isoCode: "FR", name: "France")
|
||||
try country.insert(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM countries")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "FR")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdatePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var country1 = PersistableCountry(isoCode: "FR", name: "France")
|
||||
try country1.insert(dbQueue)
|
||||
let country2 = PersistableCountry(isoCode: "US", name: "United States")
|
||||
try country2.insert(dbQueue)
|
||||
|
||||
country1.name = "France Métropolitaine"
|
||||
try country1.update(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM countries ORDER BY isoCode")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "FR")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France Métropolitaine")
|
||||
XCTAssertEqual(rows[1].value(named: "isoCode") as String, "US")
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeletePersistableCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
let country1 = PersistableCountry(isoCode: "FR", name: "France")
|
||||
try country1.insert(dbQueue)
|
||||
let country2 = PersistableCountry(isoCode: "US", name: "United States")
|
||||
try country2.insert(dbQueue)
|
||||
|
||||
try country1.delete(dbQueue)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM countries ORDER BY isoCode")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "US")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsPersistableCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
let country = PersistableCountry(isoCode: "FR", name: "France")
|
||||
try country.insert(dbQueue)
|
||||
XCTAssertTrue(country.exists(dbQueue))
|
||||
|
||||
try country.delete(dbQueue)
|
||||
|
||||
XCTAssertFalse(country.exists(dbQueue))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - PersistableCustomizedCountry
|
||||
|
||||
func testInsertPersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
let country = PersistableCustomizedCountry(
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country.insert(dbQueue)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM countries")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "FR")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France")
|
||||
}
|
||||
}
|
||||
|
||||
func testUpdatePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
var country1 = PersistableCustomizedCountry(
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country1.insert(dbQueue)
|
||||
let country2 = PersistableCustomizedCountry(
|
||||
isoCode: "US",
|
||||
name: "United States",
|
||||
willInsert: { },
|
||||
willUpdate: { },
|
||||
willSave: { },
|
||||
willDelete: { },
|
||||
willExists: { })
|
||||
try country2.insert(dbQueue)
|
||||
|
||||
country1.name = "France Métropolitaine"
|
||||
try country1.update(dbQueue)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 1)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM countries ORDER BY isoCode")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "FR")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "France Métropolitaine")
|
||||
XCTAssertEqual(rows[1].value(named: "isoCode") as String, "US")
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testDeletePersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
let country1 = PersistableCustomizedCountry(
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country1.insert(dbQueue)
|
||||
let country2 = PersistableCustomizedCountry(
|
||||
isoCode: "US",
|
||||
name: "United States",
|
||||
willInsert: { },
|
||||
willUpdate: { },
|
||||
willSave: { },
|
||||
willDelete: { },
|
||||
willExists: { })
|
||||
try country2.insert(dbQueue)
|
||||
|
||||
try country1.delete(dbQueue)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 1)
|
||||
XCTAssertEqual(existsCount, 0)
|
||||
|
||||
let rows = Row.fetchAll(dbQueue, "SELECT * FROM countries ORDER BY isoCode")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(rows[0].value(named: "isoCode") as String, "US")
|
||||
XCTAssertEqual(rows[0].value(named: "name") as String, "United States")
|
||||
}
|
||||
}
|
||||
|
||||
func testExistsPersistableCustomizedCountry() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
var insertCount: Int = 0
|
||||
var updateCount: Int = 0
|
||||
var saveCount: Int = 0
|
||||
var deleteCount: Int = 0
|
||||
var existsCount: Int = 0
|
||||
let country = PersistableCustomizedCountry(
|
||||
isoCode: "FR",
|
||||
name: "France",
|
||||
willInsert: { insertCount += 1 },
|
||||
willUpdate: { updateCount += 1 },
|
||||
willSave: { saveCount += 1 },
|
||||
willDelete: { deleteCount += 1 },
|
||||
willExists: { existsCount += 1 })
|
||||
try country.insert(dbQueue)
|
||||
|
||||
XCTAssertTrue(country.exists(dbQueue))
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 1)
|
||||
|
||||
try country.delete(dbQueue)
|
||||
|
||||
XCTAssertFalse(country.exists(dbQueue))
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
XCTAssertEqual(saveCount, 0)
|
||||
XCTAssertEqual(deleteCount, 1)
|
||||
XCTAssertEqual(existsCount, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -62,33 +62,33 @@ private struct MutablePersistableCustomizedCountry : MutablePersistable {
|
||||
self.rowID = rowID
|
||||
}
|
||||
|
||||
mutating func insert(db: DatabaseWriter) throws {
|
||||
mutating func insert(db: Database) throws {
|
||||
willInsert()
|
||||
try performInsert(db)
|
||||
}
|
||||
|
||||
func update(db: DatabaseWriter) throws {
|
||||
func update(db: Database) throws {
|
||||
willUpdate()
|
||||
try performUpdate(db)
|
||||
}
|
||||
|
||||
mutating func save(db: DatabaseWriter) throws {
|
||||
mutating func save(db: Database) throws {
|
||||
willSave()
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
func delete(db: DatabaseWriter) throws {
|
||||
func delete(db: Database) throws {
|
||||
willDelete()
|
||||
try performDelete(db)
|
||||
}
|
||||
|
||||
func exists(db: DatabaseReader) -> Bool {
|
||||
func exists(db: Database) -> Bool {
|
||||
willExists()
|
||||
return performExists(db)
|
||||
}
|
||||
}
|
||||
|
||||
class DatabaseMutablePersistableTests: GRDBTestCase {
|
||||
class MutablePersistableTests: GRDBTestCase {
|
||||
|
||||
override func setUpDatabase(dbWriter: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
+6
-6
@@ -72,33 +72,33 @@ private struct PersistableCustomizedCountry : Persistable {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
|
||||
func insert(db: DatabaseWriter) throws {
|
||||
func insert(db: Database) throws {
|
||||
willInsert()
|
||||
try performInsert(db)
|
||||
}
|
||||
|
||||
func update(db: DatabaseWriter) throws {
|
||||
func update(db: Database) throws {
|
||||
willUpdate()
|
||||
try performUpdate(db)
|
||||
}
|
||||
|
||||
func save(db: DatabaseWriter) throws {
|
||||
func save(db: Database) throws {
|
||||
willSave()
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
func delete(db: DatabaseWriter) throws {
|
||||
func delete(db: Database) throws {
|
||||
willDelete()
|
||||
try performDelete(db)
|
||||
}
|
||||
|
||||
func exists(db: DatabaseReader) -> Bool {
|
||||
func exists(db: Database) -> Bool {
|
||||
willExists()
|
||||
return performExists(db)
|
||||
}
|
||||
}
|
||||
|
||||
class DatabasePersistableTests: GRDBTestCase {
|
||||
class PersistableTests: GRDBTestCase {
|
||||
|
||||
override func setUpDatabase(dbWriter: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
@@ -8,14 +8,18 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
XCTAssertEqual(Int.fetchOne(dbQueue, "SELECT COUNT(*) FROM data")!, 1)
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,8 +29,10 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -49,8 +55,10 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -73,22 +81,30 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.changePassphrase("newSecret")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (2)")
|
||||
XCTAssertEqual(Int.fetchOne(dbQueue, "SELECT COUNT(*) FROM data")!, 2)
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("INSERT INTO data (value) VALUES (2)")
|
||||
}
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "newSecret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
XCTAssertEqual(Int.fetchOne(dbQueue, "SELECT COUNT(*) FROM data")!, 2)
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,14 +114,18 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool()
|
||||
XCTAssertEqual(Int.fetchOne(dbPool, "SELECT COUNT(*) FROM data")!, 1)
|
||||
dbPool.read { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,8 +135,10 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -138,8 +160,10 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -161,22 +185,28 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.changePassphrase("newSecret")
|
||||
try dbPool.execute("INSERT INTO data (value) VALUES (2)")
|
||||
XCTAssertEqual(Int.fetchOne(dbPool, "SELECT COUNT(*) FROM data")!, 2)
|
||||
try dbPool.write { db in
|
||||
try db.execute("INSERT INTO data (value) VALUES (2)")
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "newSecret"
|
||||
let dbPool = try makeDatabasePool()
|
||||
XCTAssertEqual(Int.fetchOne(dbPool, "SELECT COUNT(*) FROM data")!, 2)
|
||||
dbPool.read { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,14 +216,18 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbPool.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool()
|
||||
XCTAssertEqual(Int.fetchOne(dbPool, "SELECT COUNT(*) FROM data")!, 1)
|
||||
dbPool.read { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,8 +237,10 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbPool.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -226,8 +262,10 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbPool.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -250,22 +288,28 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbPool.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.changePassphrase("newSecret")
|
||||
try dbPool.execute("INSERT INTO data (value) VALUES (2)")
|
||||
XCTAssertEqual(Int.fetchOne(dbPool, "SELECT COUNT(*) FROM data")!, 2)
|
||||
try dbPool.write { db in
|
||||
try db.execute("INSERT INTO data (value) VALUES (2)")
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "newSecret"
|
||||
let dbPool = try makeDatabasePool()
|
||||
XCTAssertEqual(Int.fetchOne(dbPool, "SELECT COUNT(*) FROM data")!, 2)
|
||||
dbPool.read { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,15 +319,19 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = nil
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("PRAGMA key = 'secret'")
|
||||
try dbQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("PRAGMA key = 'secret'")
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
XCTAssertEqual(Int.fetchOne(dbQueue, "SELECT COUNT(*) FROM data")!, 1)
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,9 +341,11 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = nil
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.execute("PRAGMA key = 'secret'")
|
||||
try dbQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try dbQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("PRAGMA key = 'secret'")
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -318,21 +368,27 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
dbConfiguration.passphrase = nil
|
||||
let plainTextDBQueue = try makeDatabaseQueue("plaintext.sqlite")
|
||||
try plainTextDBQueue.execute("CREATE TABLE data (value INTEGER)")
|
||||
try plainTextDBQueue.execute("INSERT INTO data (value) VALUES (1)")
|
||||
try plainTextDBQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE data (value INTEGER)")
|
||||
try db.execute("INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let encryptedDBQueue = try makeDatabaseQueue("encrypted.sqlite")
|
||||
|
||||
try plainTextDBQueue.execute("ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"])
|
||||
try plainTextDBQueue.execute("SELECT sqlcipher_export('encrypted')")
|
||||
try plainTextDBQueue.execute("DETACH DATABASE encrypted")
|
||||
try plainTextDBQueue.inDatabase { db in
|
||||
try db.execute("ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"])
|
||||
try db.execute("SELECT sqlcipher_export('encrypted')")
|
||||
try db.execute("DETACH DATABASE encrypted")
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue("encrypted.sqlite")
|
||||
XCTAssertEqual(Int.fetchOne(dbQueue, "SELECT COUNT(*) FROM data")!, 1)
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,20 +169,22 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
XCTAssertTrue(error.sql == nil)
|
||||
XCTAssertEqual(error.description, "SQLite error 19: FOREIGN KEY constraint failed")
|
||||
|
||||
// Arthur inserted (migration 1), Barbara (migration 3) not inserted.
|
||||
var rows = Row.fetchAll(dbQueue, "SELECT * FROM persons")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
var row = rows.first!
|
||||
XCTAssertEqual(row.value(named: "name") as String, "Arthur")
|
||||
|
||||
// persons table has no "tmp" column (migration 2)
|
||||
XCTAssertEqual(Array(row.columnNames), ["id", "name"])
|
||||
|
||||
// Bobby inserted (migration 1), not deleted by migration 2.
|
||||
rows = Row.fetchAll(dbQueue, "SELECT * FROM pets")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
row = rows.first!
|
||||
XCTAssertEqual(row.value(named: "name") as String, "Bobby")
|
||||
dbQueue.inDatabase { db in
|
||||
// Arthur inserted (migration 1), Barbara (migration 3) not inserted.
|
||||
var rows = Row.fetchAll(db, "SELECT * FROM persons")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
var row = rows.first!
|
||||
XCTAssertEqual(row.value(named: "name") as String, "Arthur")
|
||||
|
||||
// persons table has no "tmp" column (migration 2)
|
||||
XCTAssertEqual(Array(row.columnNames), ["id", "name"])
|
||||
|
||||
// Bobby inserted (migration 1), not deleted by migration 2.
|
||||
rows = Row.fetchAll(db, "SELECT * FROM pets")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
row = rows.first!
|
||||
XCTAssertEqual(row.value(named: "name") as String, "Bobby")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class Person : Record {
|
||||
]
|
||||
}
|
||||
|
||||
override func insert(db: DatabaseWriter) throws {
|
||||
override func insert(db: Database) throws {
|
||||
// This is implicitely tested with the NOT NULL constraint on creationDate
|
||||
if creationDate == nil {
|
||||
creationDate = NSDate()
|
||||
|
||||
@@ -62,7 +62,7 @@ class PersonWithModifiedCaseColumns: Record {
|
||||
]
|
||||
}
|
||||
|
||||
override func insert(db: DatabaseWriter) throws {
|
||||
override func insert(db: Database) throws {
|
||||
// This is implicitely tested with the NOT NULL constraint on creationDate
|
||||
if creationDate == nil {
|
||||
creationDate = NSDate()
|
||||
|
||||
@@ -36,12 +36,12 @@ class PersonWithOverrides : Person {
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override func insert(db: DatabaseWriter) throws {
|
||||
override func insert(db: Database) throws {
|
||||
lastSavingMethod = .Insert
|
||||
try super.insert(db)
|
||||
}
|
||||
|
||||
override func update(db: DatabaseWriter) throws {
|
||||
override func update(db: Database) throws {
|
||||
lastSavingMethod = .Update
|
||||
try super.update(db)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user