Skip to content

Commit 8a278a1

Browse files
WIP: Add GRDB demo app
1 parent a79ec5c commit 8a278a1

33 files changed

+2253
-8
lines changed

Demo/GRDB Demo/GRDB Demo.xcodeproj/project.pbxproj

Lines changed: 710 additions & 0 deletions
Large diffs are not rendered by default.

Demo/GRDB Demo/GRDB Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata

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

Demo/GRDB Demo/GRDB Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"platform" : "ios",
6+
"size" : "1024x1024"
7+
},
8+
{
9+
"appearances" : [
10+
{
11+
"appearance" : "luminosity",
12+
"value" : "dark"
13+
}
14+
],
15+
"idiom" : "universal",
16+
"platform" : "ios",
17+
"size" : "1024x1024"
18+
},
19+
{
20+
"appearances" : [
21+
{
22+
"appearance" : "luminosity",
23+
"value" : "tinted"
24+
}
25+
],
26+
"idiom" : "universal",
27+
"platform" : "ios",
28+
"size" : "1024x1024"
29+
},
30+
{
31+
"idiom" : "mac",
32+
"scale" : "1x",
33+
"size" : "16x16"
34+
},
35+
{
36+
"idiom" : "mac",
37+
"scale" : "2x",
38+
"size" : "16x16"
39+
},
40+
{
41+
"idiom" : "mac",
42+
"scale" : "1x",
43+
"size" : "32x32"
44+
},
45+
{
46+
"idiom" : "mac",
47+
"scale" : "2x",
48+
"size" : "32x32"
49+
},
50+
{
51+
"idiom" : "mac",
52+
"scale" : "1x",
53+
"size" : "128x128"
54+
},
55+
{
56+
"idiom" : "mac",
57+
"scale" : "2x",
58+
"size" : "128x128"
59+
},
60+
{
61+
"idiom" : "mac",
62+
"scale" : "1x",
63+
"size" : "256x256"
64+
},
65+
{
66+
"idiom" : "mac",
67+
"scale" : "2x",
68+
"size" : "256x256"
69+
},
70+
{
71+
"idiom" : "mac",
72+
"scale" : "1x",
73+
"size" : "512x512"
74+
},
75+
{
76+
"idiom" : "mac",
77+
"scale" : "2x",
78+
"size" : "512x512"
79+
}
80+
],
81+
"info" : {
82+
"author" : "xcode",
83+
"version" : 1
84+
}
85+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "pslogo.svg",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
Lines changed: 14 additions & 0 deletions
Loading
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import GRDB
2+
import PowerSync
3+
4+
/// PowerSync client side schema
5+
let listsTable = Table(
6+
name: "lists",
7+
columns: [
8+
.text("name"),
9+
.text("owner_id")
10+
]
11+
)
12+
13+
struct List: Codable, Equatable, Identifiable, FetchableRecord, PersistableRecord {
14+
var id: String
15+
var name: String
16+
var ownerId: String
17+
18+
static var databaseTableName = "lists"
19+
20+
21+
enum CodingKeys: String, CodingKey {
22+
case id
23+
case name
24+
case ownerId = "owner_id"
25+
}
26+
27+
enum Columns {
28+
static let id = Column(CodingKeys.id)
29+
static let name = Column(CodingKeys.name)
30+
static let ownerId = Column(CodingKeys.ownerId)
31+
}
32+
33+
static let todos = hasMany(
34+
Todo.self, key: "todos",
35+
using: ForeignKey([Todo.Columns.listId], to: [Columns.id])
36+
)
37+
}
38+
39+
/// Result for displaying lists in the main view
40+
struct ListWithTodoCounts: Decodable, Hashable, Identifiable, FetchableRecord {
41+
var id: String
42+
var name: String
43+
var pendingCount: Int
44+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Foundation
2+
import GRDB
3+
import PowerSync
4+
5+
/// PowerSync client side schema
6+
let todosTable = Table(
7+
name: "todos",
8+
columns: [
9+
.text("name"),
10+
.text("list_id"),
11+
// Conversion should automatically be handled by GRDB
12+
.integer("completed"),
13+
.text("completed_at")
14+
]
15+
)
16+
17+
struct Todo: Codable, Equatable, Identifiable, FetchableRecord, PersistableRecord {
18+
var id: String
19+
var name: String
20+
var listId: String
21+
var isCompleted: Bool
22+
var completedAt: Date?
23+
24+
static var databaseTableName = "todos"
25+
26+
enum CodingKeys: String, CodingKey {
27+
case id
28+
case name
29+
case listId = "list_id"
30+
case isCompleted = "completed"
31+
case completedAt = "completed_at"
32+
}
33+
34+
enum Columns {
35+
static let id = Column(CodingKeys.id)
36+
static let name = Column(CodingKeys.name)
37+
static let listId = Column(CodingKeys.listId)
38+
static let isCompleted = Column(CodingKeys.isCompleted)
39+
static let completedAt = Column(CodingKeys.completedAt)
40+
}
41+
}

0 commit comments

Comments
 (0)