Skip to content

Commit baafffe

Browse files
wip attachments
1 parent 3209c98 commit baafffe

File tree

11 files changed

+1320
-10
lines changed

11 files changed

+1320
-10
lines changed

Package.resolved

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ let package = Package(
1616
targets: ["PowerSync"]),
1717
],
1818
dependencies: [
19-
.package(url: "https://github.com/powersync-ja/powersync-kotlin.git", exact: "1.0.0-BETA28.0"),
19+
.package(path: "/Users/stevenontong/Documents/platform_code/powersync/powersync-kotlin"),
20+
// .package(url: "https://github.com/powersync-ja/powersync-kotlin.git", exact: "1.0.0-BETA28.0"),
2021
.package(url: "https://github.com/powersync-ja/powersync-sqlite-core-swift.git", "0.3.12"..<"0.4.0")
2122
],
2223
targets: [

Sources/PowerSync/Kotlin/KotlinAdapter.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PowerSyncKotlin
22

3+
34
internal struct KotlinAdapter {
45
struct Index {
56
static func toKotlin(_ index: IndexProtocol) -> PowerSyncKotlin.Index {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Enum for the attachment state
3+
*/
4+
public enum AttachmentState: Int {
5+
case queuedDownload
6+
case queuedUpload
7+
case queuedDelete
8+
case synced
9+
case archived
10+
}
11+
12+
/**
13+
* Struct representing an attachment
14+
*/
15+
public struct Attachment {
16+
let id: String
17+
let timestamp: Int
18+
let filename: String
19+
let state: Int
20+
let localUri: String?
21+
let mediaType: String?
22+
let size: Int64?
23+
/**
24+
* Specifies if the attachment has been synced locally before. This is particularly useful
25+
* for restoring archived attachments in edge cases.
26+
*/
27+
let hasSynced: Int?
28+
29+
public init(
30+
id: String,
31+
filename: String,
32+
state: Int,
33+
timestamp: Int = 0,
34+
hasSynced: Int? = 0,
35+
localUri: String? = nil,
36+
mediaType: String? = nil,
37+
size: Int64? = nil,
38+
) {
39+
self.id = id
40+
self.timestamp = timestamp
41+
self.filename = filename
42+
self.state = state
43+
self.localUri = localUri
44+
self.mediaType = mediaType
45+
self.size = size
46+
self.hasSynced = hasSynced
47+
}
48+
49+
func with(filename: String? = nil, state: Int? = nil, hasSynced: Int? = nil, localUri: String? = nil, mediaType: String? = nil, size: Int64? = nil ) -> Attachment {
50+
return Attachment(
51+
id: self.id,
52+
filename: self.filename,
53+
state: state ?? self.state,
54+
hasSynced: hasSynced ?? self.hasSynced,
55+
localUri: localUri ?? self.localUri,
56+
mediaType: mediaType ?? self.mediaType,
57+
size: size ?? self.size,
58+
)
59+
}
60+
61+
public static func fromCursor(_ cursor: SqlCursor) throws -> Attachment {
62+
return Attachment(
63+
id: try cursor.getString(name: "id"),
64+
filename: try cursor.getString(name: "filename"),
65+
state: try cursor.getLong(name: "state"),
66+
timestamp: try cursor.getLong(name: "timestamp"),
67+
hasSynced: try cursor.getLongOptional(name: "has_synced"),
68+
localUri: try cursor.getStringOptional(name: "local_uri"),
69+
mediaType: try cursor.getStringOptional(name: "media_type"),
70+
size: try cursor.getLongOptional(name: "size")?.int64Value,
71+
)
72+
}
73+
}
74+

0 commit comments

Comments
 (0)