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: Documentation/Index.md
+11-6Lines changed: 11 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -537,18 +537,23 @@ let query = users.select(email) // SELECT "email" FROM "users"
537
537
By default, [`Query`](#queries) objects select every column of the result set (using `SELECT *`). We can use the `select` function with a list of [expressions](#expressions) to return specific columns instead.
538
538
539
539
``` swift
540
-
let query = users.select(id, email)
540
+
for user in users.select(id, email) {
541
+
println("id: \(user[id]), email: \(user[email])")
542
+
// id: 1, email: alice@mac.com
543
+
}
541
544
// SELECT "id", "email" FROM "users"
542
545
```
543
546
544
-
<!-- TODO
545
-
We can select aggregate values using [aggregate functions](#aggregate-sqlite-functions).
547
+
We can access the results of more complex expressions by holding onto a reference of the expression itself.
546
548
547
549
``` swift
548
-
let query = users.select(count(*))
549
-
// SELECT count(*) FROM "users"
550
+
let sentence = name +" is "+cast(age) as Expression<String?>+" years old!"
551
+
for user in users.select(sentence) {
552
+
println(user[sentence])
553
+
// Optional("Alice is 30 years old!")
554
+
}
555
+
// SELECT ((("name" || ' is ') || CAST ("age" AS TEXT)) || ' years old!') FROM "users"
0 commit comments