mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Documentation
This commit is contained in:
1 parent
0544fc1f09
commit
110a8e28a8
4 files changed
+11
-8
No files matched your search
@@ -67,10 +67,11 @@ public enum DatabaseValue : Equatable {
|
||||
let value: Double? = databaseValue.value()
|
||||
|
||||
**WARNING**: type casting requires a very careful use of the `as` operator
|
||||
(see [rdar://problem/21676393](http://openradar.appspot.com/radar?id=4951414862249984)):
|
||||
(see [rdar://21676393](http://openradar.appspot.com/radar?id=4951414862249984)):
|
||||
|
||||
databaseValue.value()! as Int // OK: Int
|
||||
databaseValue.value() as Int? // OK: Int?
|
||||
databaseValue.value() as! Int // NO NO NO DON'T DO THAT!
|
||||
databaseValue.value() as? Int // NO NO NO DON'T DO THAT!
|
||||
|
||||
Your custom types that adopt the DatabaseValueConvertible protocol handle
|
||||
|
||||
+4
-2
@@ -63,11 +63,12 @@ public struct Row: CollectionType {
|
||||
let value: Double? = row.value(atIndex: 0)
|
||||
|
||||
**WARNING**: type casting requires a very careful use of the `as` operator
|
||||
(see [rdar://problem/21676393](http://openradar.appspot.com/radar?id=4951414862249984)):
|
||||
(see [rdar://21676393](http://openradar.appspot.com/radar?id=4951414862249984)):
|
||||
|
||||
row.value(atIndex: 0)! as Int // OK: Int
|
||||
row.value(atIndex: 0) as Int? // OK: Int?
|
||||
row.value(atIndex: 0) as? Int // NO NO NO DON'T DO THAT!
|
||||
row.value(atIndex: 0) as! Int // NO NO NO DON'T DO THAT!
|
||||
|
||||
Your custom types that adopt the DatabaseValueConvertible protocol handle
|
||||
their own conversion from raw SQLite values. Yet, here is the reference for
|
||||
@@ -127,10 +128,11 @@ public struct Row: CollectionType {
|
||||
let value: Double? = row.value(named: "count")
|
||||
|
||||
**WARNING**: type casting requires a very careful use of the `as` operator
|
||||
(see [rdar://problem/21676393](http://openradar.appspot.com/radar?id=4951414862249984)):
|
||||
(see [rdar://21676393](http://openradar.appspot.com/radar?id=4951414862249984)):
|
||||
|
||||
row.value(named: "count")! as Int // OK: Int
|
||||
row.value(named: "count") as Int? // OK: Int?
|
||||
row.value(named: "count") as! Int // NO NO NO DON'T DO THAT!
|
||||
row.value(named: "count") as? Int // NO NO NO DON'T DO THAT!
|
||||
|
||||
Your custom types that adopt the DatabaseValueConvertible protocol handle
|
||||
|
||||
@@ -248,9 +248,9 @@ public class RowModel : RowConvertible, DatabaseTableMapping, DatabaseStorable {
|
||||
} else {
|
||||
// No statement means that there is no column to update.
|
||||
//
|
||||
// I remember opening rdar://problem/10236982 because CoreData
|
||||
// was crashing with entities without any attribute. So let's
|
||||
// accept RowModel that don't have any column to update.
|
||||
// I remember opening rdar://10236982 because CoreData was crashing
|
||||
// with entities without any attribute. So let's accept RowModel
|
||||
// that don't have any column to update.
|
||||
exists = self.exists(db)
|
||||
}
|
||||
|
||||
|
||||
@@ -268,7 +268,7 @@ let bookCount64: Int64 = row.value(named: "bookCount")!
|
||||
let hasBooks: Bool = row.value(named: "bookCount")! // false when 0
|
||||
```
|
||||
|
||||
**WARNING**: type casting requires a very careful use of the `as` operator (see [rdar://problem/21676393](http://openradar.appspot.com/radar?id=4951414862249984)):
|
||||
**WARNING**: type casting requires a very careful use of the `as` operator (see [rdar://21676393](http://openradar.appspot.com/radar?id=4951414862249984)):
|
||||
|
||||
```swift
|
||||
row.value(named: "bookCount")! as Int // OK: Int
|
||||
@@ -561,7 +561,7 @@ All types that adopt this protocol can be used wherever the built-in types `Int`
|
||||
|
||||
The `databaseValue` property returns [DatabaseValue](GRDB/Core/DatabaseValue.swift), an enum for the five types supported by SQLite: NULL, integer, real, string and blob.
|
||||
|
||||
The `fromDatabaseValue()` factory method returns an instance of your custom type if the databaseValue contains a suitable value.
|
||||
The `fromDatabaseValue()` factory method returns an instance of your custom type, if the databaseValue contains a suitable value.
|
||||
|
||||
As an example, let's write an alternative to the built-in [NSDate](#nsdate-and-nsdatecomponents) behavior, and store dates as timestamps. Our sample DatabaseTimestamp type applies all the best practices for a great GRDB.swift integration:
|
||||
|
||||
|
||||
Reference in new issue
Block a user