mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
Merge branch 'master' of github.com:groue/GRDB.swift into Swift3bis
Conflicts: GRDB/Record/Persistable.swift
This commit is contained in:
commit
3989f0c332
3 files changed
+16
-5
No files matched your search
@@ -503,7 +503,7 @@ final class DataMapper {
|
||||
// Fail early if primary key does not resolve to a database row.
|
||||
let primaryKeyColumns = primaryKey?.columns ?? []
|
||||
let primaryKeyValues = databaseValues(for: primaryKeyColumns, inDictionary: persistentDictionary)
|
||||
GRDBPrecondition(primaryKeyValues.contains { !$0.isNull }, "invalid primary key in \(persistable)")
|
||||
GRDBPrecondition(primaryKeyValues.contains { !$0.isNull }, "record can not be identified. persistentDictionary must contain non-nil value(s) for the key(s) \(primaryKeyColumns.joined(separator: ","))")
|
||||
|
||||
// Update everything but primary key
|
||||
var updatedColumns = persistentDictionary.keys.removing(contentsOf: primaryKeyColumns)
|
||||
@@ -533,7 +533,7 @@ final class DataMapper {
|
||||
// Fail early if primary key does not resolve to a database row.
|
||||
let primaryKeyColumns = primaryKey?.columns ?? []
|
||||
let primaryKeyValues = databaseValues(for: primaryKeyColumns, inDictionary: persistentDictionary)
|
||||
GRDBPrecondition(primaryKeyValues.contains { !$0.isNull }, "invalid primary key in \(persistable)")
|
||||
GRDBPrecondition(primaryKeyValues.contains { !$0.isNull }, "record can not be identified. persistentDictionary must contain non-nil value(s) for the key(s) \(primaryKeyColumns.joined(separator: ","))")
|
||||
|
||||
let query = DeleteQuery(
|
||||
tableName: databaseTableName,
|
||||
@@ -547,7 +547,7 @@ final class DataMapper {
|
||||
// Fail early if primary key does not resolve to a database row.
|
||||
let primaryKeyColumns = primaryKey?.columns ?? []
|
||||
let primaryKeyValues = databaseValues(for: primaryKeyColumns, inDictionary: persistentDictionary)
|
||||
GRDBPrecondition(primaryKeyValues.contains { !$0.isNull }, "invalid primary key in \(persistable)")
|
||||
GRDBPrecondition(primaryKeyValues.contains { !$0.isNull }, "record can not be identified. persistentDictionary must contain non-nil value(s) for the key(s) \(primaryKeyColumns.joined(separator: ","))")
|
||||
|
||||
let query = ExistsQuery(
|
||||
tableName: databaseTableName,
|
||||
|
||||
@@ -1549,6 +1549,8 @@ Add the [TableMapping](#tablemapping-protocol) protocol and you can stop writing
|
||||
```swift
|
||||
let persons = Person.filter(emailColumn != nil).order(nameColumn).fetchAll(db)
|
||||
let person = Person.fetchOne(db, key: 1)
|
||||
let person = Person.fetchOne(db, key: ["email": "arthur@example.com"])
|
||||
let countries = Country.fetchAll(db, keys: ["FR", "US"])
|
||||
```
|
||||
|
||||
To learn more about querying records, check the [query interface](#the-query-interface).
|
||||
@@ -1590,7 +1592,15 @@ let person = Person.fetchOne(db, key: 1)!
|
||||
try person.delete(db)
|
||||
```
|
||||
|
||||
For batch deletions, you have to execute an [SQL query](#executing-updates):
|
||||
The [TableMapping](#tablemapping-protocol) protocol gives you methods that delete according to primary key or any unique index:
|
||||
|
||||
```swift
|
||||
try Person.deleteOne(db, key: 1)
|
||||
try Person.deleteOne(db, key: ["email": "arthur@example.com"])
|
||||
try Country.deleteAll(db, keys: ["FR", "US"])
|
||||
```
|
||||
|
||||
Other deletions require an [SQL query](#executing-updates):
|
||||
|
||||
```swift
|
||||
try db.execute("DELETE FROM persons")
|
||||
@@ -1602,7 +1612,7 @@ try db.execute("DELETE FROM persons")
|
||||
[Record](#record-class) subclasses and types that adopt the [TableMapping](#tablemapping-protocol) protocol can be counted:
|
||||
|
||||
```swift
|
||||
let personWithEmailCount = Person.filter(email != nil).fetchCount(db) // Int
|
||||
let personWithEmailCount = Person.filter(emailColumn != nil).fetchCount(db) // Int
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -46,3 +46,4 @@ Reading list:
|
||||
- https://www.zetetic.net/sqlcipher/
|
||||
- https://sqlite.org/sharedcache.html
|
||||
- Amazing tip from Xcode labs: add a EXCLUDED_SOURCE_FILE_NAMES build setting to conditionally exclude sources for different configuration: https://twitter.com/zats/status/74386298602026496
|
||||
- SQLITE_ENABLE_SQLLOG: http://mjtsai.com/blog/2016/07/19/sqlite_enable_sqllog/
|
||||
Reference in new issue
Block a user