Skip to content

Commit 45d0653

Browse files
committed
Merge branch 'master' of github.com:fnc12/sqlite-orm-swift
2 parents a289c2b + 5c224d1 commit 45d0653

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SQLiteORM-Swift is an ORM library for SQLite3 built with Swift 5
1414
* **Intuitive syntax**
1515
* **Comfortable interface - one call per single query**
1616
* **CRUD support**
17+
* **Aggregate functions support**
1718
* **Does not depend on `Codable` protocol**
1819
* **The only dependency** - SQLite3
1920
* **In memory database support** - provide `:memory:` or empty filename
@@ -130,6 +131,55 @@ for user in allUsers {
130131
}
131132
```
132133

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+
if let 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+
if let 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+
if let 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+
133183
# Migrations functionality
134184

135185
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

Comments
 (0)