Documentation WIP

This commit is contained in:
Gwendal Roué committed 2015-07-06 12:43:40 +02:00
1 parent 3587ae435c
commit 0fb7fb7d06
2 files changed
+28 -1

No files matched your search

+28
View File
@@ -65,6 +65,34 @@ public final class DatabaseQueue {
// MARK: - Database access
// IMPLEMENTATON NOTE
//
// When one sees code like:
//
// try dbQueue.inDatabase { db in
// try db.execute("INSERT ...")
// }
//
// One can wonder why there is no direct DatabaseQueue.execute() methods:
//
// // Look, Ma! No block!
// try dbQueue.execute("INSERT ...")
//
// Well, this is on purpose. Let's imagine what would happen if such method
// would exist:
//
// try dbQueue.execute("INSERT ...")
// let id = dbQueue.lastInsertedRowID
//
// Boom. The user feels like he can load the last inserted row ID, and he
// has just introduced a bug: between the two lines of code, some other
// statements may have been executed in other threads: the last inserted row
// ID may well be irrelevant.
//
// So until lastInsertedRowID is only accessible through the result of the
// statement execution, we don't provide any dbQueue.execute() function. And
// for consistency, no dbQueue.fetchXXX() method :-)
/**
Executes a throwing block in the database queue.
-1
View File
@@ -3,6 +3,5 @@
- [ ] db.fetch(RowModel.type, primaryKeys:[...]) // several primary keys
- [ ] Investigate INSERT OR REPLACE
- [ ] Add bindings to SQLiteError, so that one known the value that could not be updated/inserted.
- [ ] Document why execute and fetch methods will never be added to DatabaseQueue, and one always has to execute a block. It is because code like `dbQueue.execute("INSERT..."); let id = dbQueue.lastInsertedRowID` would be *unsafe*.
- [ ] Pierlo complains that databaseDictionary returns a dictionary of values when updateFromDatabaseRow eats a Row. See if we can do something about that.
- [ ] db.fetch(RowModel.type, primaryKey: Bindings) in unsafe because there are chances that array bindings don't match the order of primary key columns. Rethink fetching by primary key for RowModels with primary keys that span accross multiple columns.