You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ SQLiteORM-Swift is an ORM library for SQLite3 built with Swift 5
14
14
***Intuitive syntax**
15
15
***Comfortable interface - one call per single query**
16
16
***CRUD support**
17
+
***Aggregate functions support**
17
18
***Does not depend on `Codable` protocol**
18
19
***The only dependency** - SQLite3
19
20
***In memory database support** - provide `:memory:` or empty filename
@@ -130,6 +131,55 @@ for user in allUsers {
130
131
}
131
132
```
132
133
134
+
# Aggregate functions
135
+
136
+
```swift
137
+
// SELECT AVG(id) FROM users
138
+
let averageId =try storage.avg(\User.id)
139
+
140
+
// SELECT AVG(birth_date) FROM users
141
+
let averageBirthDate =try storage.avg(\User.birthDate)
142
+
143
+
// SELECT COUNT(*) FROM users
144
+
let usersCount =try storage.count(all: User.self)
145
+
146
+
// SELECT COUNT(id) FROM users
147
+
let countId =try storage.count(\User.id)
148
+
149
+
// SELECT COUNT(image_url) FROM users
150
+
let countImageUrl =try storage.count(\User.imageUrl)
151
+
152
+
// SELECT GROUP_CONCAT(id) FROM users
153
+
let concatedUserId =try storage.groupConcat(\User.id)
154
+
155
+
// SELECT GROUP_CONCAT(id, '---') FROM users
156
+
let concatedUserIdWithDashes =try storage.groupConcat(\User.id, separator: "---")
157
+
158
+
// SELECT MAX(id) FROM users
159
+
iflet maxId =try storage.max(\User.id) {
160
+
print("maxId = \(maxId)")
161
+
} else {
162
+
print("maxId is nil")
163
+
}
164
+
165
+
// SELECT MIN(id) FROM users
166
+
iflet minId =try storage.min(\User.id) {
167
+
print("minId = \(minId)")
168
+
} else {
169
+
print("maxId is nil")
170
+
}
171
+
172
+
// SELECT SUM(id) FROM users
173
+
iflet sumId =try storage.sum(\User.id) {
174
+
print("sumId = \(sumId)")
175
+
} else {
176
+
print("sumId is nil")
177
+
}
178
+
179
+
// SELECT TOTAL(id) FROM users
180
+
let totalId =try storage.total(\User.id)
181
+
```
182
+
133
183
# Migrations functionality
134
184
135
185
There are no explicit `up` and `down` functions that are used to be used in migrations. Instead `SQLiteORM` offers `syncSchema` function that takes responsibility of comparing actual db file schema with one you specified in `Storage` init call and if something is not equal it alters or drops/creates schema.
0 commit comments