Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.4"),
.package(
url: "https://github.com/pointfreeco/swift-structured-queries",
from: "0.24.0",
from: "0.27.0",
traits: [
.trait(name: "StructuredQueriesTagged", condition: .when(traits: ["SQLiteDataTagged"]))
]
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.9.0"),
.package(url: "https://github.com/pointfreeco/swift-sharing", from: "2.3.0"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.4"),
.package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.24.0"),
.package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.27.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.5.0"),
],
targets: [
Expand Down
5 changes: 0 additions & 5 deletions Sources/SQLiteData/CloudKit/Internal/CloudKitFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,4 @@
return share.publicPermission == .readWrite
|| share.currentUserParticipant?.permission == .readWrite
}

@DatabaseFunction("sqlitedata_icloud_syncEngineIsSynchronizingChanges")
func syncEngineIsSynchronizingChanges() -> Bool {
_isSynchronizingChanges
}
#endif
12 changes: 6 additions & 6 deletions Sources/SQLiteData/CloudKit/Internal/Triggers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
}
.update { $0._isDeleted = true }
} when: { _ in
!SyncEngine.isSynchronizingChanges()
!SyncEngine.$isSynchronizing
}
)
}
Expand All @@ -158,7 +158,7 @@
}
.delete()
} when: { _ in
SyncEngine.isSynchronizingChanges()
SyncEngine.$isSynchronizing
}
)
}
Expand Down Expand Up @@ -263,7 +263,7 @@
)
)
} when: { _ in
!SyncEngine.isSynchronizingChanges()
!SyncEngine.$isSynchronizing
}
)
}
Expand Down Expand Up @@ -323,7 +323,7 @@
)
)
} when: { old, new in
old._isDeleted.eq(new._isDeleted) && !SyncEngine.isSynchronizingChanges()
old._isDeleted.eq(new._isDeleted) && !SyncEngine.$isSynchronizing
}
)
}
Expand All @@ -344,7 +344,7 @@
)
)
} when: { old, new in
!old._isDeleted && new._isDeleted && !SyncEngine.isSynchronizingChanges()
!old._isDeleted && new._isDeleted && !SyncEngine.$isSynchronizing
}
)
}
Expand Down Expand Up @@ -453,7 +453,7 @@
)
}
.where {
!SyncEngine.isSynchronizingChanges()
!SyncEngine.$isSynchronizing
&& $0.parentRecordName.is(nil)
&& !$hasPermission($0.share)
}
Expand Down
13 changes: 9 additions & 4 deletions Sources/SQLiteData/CloudKit/SyncEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
.execute(db)
}
db.add(function: $currentTime)
db.add(function: $syncEngineIsSynchronizingChanges)
db.add(function: SyncEngine.$isSynchronizing)
db.add(function: $didUpdate)
db.add(function: $didDelete)
db.add(function: $hasPermission)
Expand Down Expand Up @@ -864,12 +864,17 @@
)
}

/// A query expression that can be used in SQL queries to determine if the ``SyncEngine``
/// is currently writing changes to the database.
/// Whether or not the ``SyncEngine`` is currently writing changes to the database.
///
/// See <doc:CloudKit#Updating-triggers-to-be-compatible-with-synchronization> for more info.
@DatabaseFunction("sqlitedata_icloud_syncEngineIsSynchronizingChanges")
public static var isSynchronizing: Bool {
_isSynchronizingChanges
}

@available(*, deprecated, message: "Use 'SyncEngine.$isSynchronizing', instead.")
public static func isSynchronizingChanges() -> some QueryExpression<Bool> {
$syncEngineIsSynchronizingChanges()
$isSynchronizing
}

private var sendingChangesCount: Int {
Expand Down
6 changes: 3 additions & 3 deletions Sources/SQLiteData/Documentation.docc/Articles/CloudKit.md
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ or CloudKit is updating the data.

[FTS]: https://sqlite.org/fts5.html

To customize this behavior you can use the ``SyncEngine/isSynchronizingChanges()`` SQL expression.
To customize this behavior you can use the projected ``SyncEngine/isSynchronizing`` SQL expression.
It represents a custom database function that is installed in your database connection, and it will
return true if the write to your database originates from the sync engine. You can use it in a
trigger like so:
Expand All @@ -759,7 +759,7 @@ trigger like so:
"""
CREATE TEMPORARY TRIGGER "…"
AFTER DELETE ON "…"
FOR EACH ROW WHEN NOT \(SyncEngine.isSynchronizingChanges())
FOR EACH ROW WHEN NOT \(SyncEngine.$isSynchronizing)
BEGIN
END
Expand All @@ -776,7 +776,7 @@ Model.createTemporaryTrigger(
after: .insert { new in
// ...
} when: { _ in
!SyncEngine.isSynchronizingChanges()
!SyncEngine.$isSynchronizing
}
)
```
Expand Down
16 changes: 8 additions & 8 deletions Tests/SQLiteDataTests/CloudKitTests/SchemaChangeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@
│ ), │
│ share: nil, │
│ _isDeleted: false, │
hasLastKnownServerRecord: true,
isShared: false,
_hasLastKnownServerRecord: true, │
_isShared: false, │
│ userModificationTime: 0 │
│ ) │
└────────────────────────────────────────────────────────────────────┘
Expand Down Expand Up @@ -251,8 +251,8 @@
│ ), │
│ share: nil, │
│ _isDeleted: false, │
hasLastKnownServerRecord: true,
isShared: false,
_hasLastKnownServerRecord: true, │
_isShared: false, │
│ userModificationTime: 1 │
│ ) │
└────────────────────────────────────────────────────────────────────┘
Expand Down Expand Up @@ -363,8 +363,8 @@
│ ), │
│ share: nil, │
│ _isDeleted: false, │
hasLastKnownServerRecord: true,
isShared: false,
_hasLastKnownServerRecord: true, │
_isShared: false, │
│ userModificationTime: 0 │
│ ) │
└────────────────────────────────────────────────────────────────────┘
Expand Down Expand Up @@ -410,8 +410,8 @@
│ ), │
│ share: nil, │
│ _isDeleted: false, │
hasLastKnownServerRecord: true,
isShared: false,
_hasLastKnownServerRecord: true, │
_isShared: false, │
│ userModificationTime: 0 │
│ ) │
└────────────────────────────────────────────────────────────────────┘
Expand Down