Configuration.maximumReaderCount replaces DatabasePool initializer option

This commit is contained in:
Gwendal Roué committed 2016-05-19 18:10:36 +02:00
1 parent 7772749e88
commit 9dbf992c40
5 files changed
+53 -27

No files matched your search

+13
View File
@@ -1,6 +1,19 @@
Release Notes
=============
## Next Release
**Breaking Changes**
- The maximum number of reader connections in a database pool is now configured in a Configuration object.
```diff
final class DatabasePool {
- init(path: String, configuration: Configuration = default) throws
+ init(path: String, configuration: Configuration = default, maximumReaderCount: Int = default) throws
```
## 0.65.0
Released May 19, 2016
+35 -21
View File
@@ -17,20 +17,32 @@ public struct Configuration {
// MARK: - Misc options
/// If true, foreign key constraints are checked.
///
/// Default: true
public var foreignKeysEnabled: Bool = true
/// If true, database modifications are disallowed.
///
/// Default: false
public var readonly: Bool = false
/// A function that is called on every statement executed by the database.
///
/// Default: nil
public var trace: TraceFunction?
// MARK: - Encryption
#if SQLITE_HAS_CODEC
/// The passphrase for encrypted database
/// The passphrase for encrypted database.
///
/// Default: nil
public var passphrase: String?
#endif
// MARK: - File Attributes
/// The file attributes that should be applied to the database files (see
@@ -43,45 +55,47 @@ public struct Configuration {
/// `-shm` and `-wal` files.
///
/// GRDB will apply file attributes to all those files.
///
/// Default: nil
public var fileAttributes: [String: AnyObject]? = nil
// MARK: - Transactions
/// The default kind of transaction.
///
/// Default: Immediate
public var defaultTransactionKind: TransactionKind = .Immediate
// MARK: - Concurrency
/// The behavior in case of SQLITE_BUSY error. See https://www.sqlite.org/rescode.html#busy
///
/// Default: ImmediateError
public var busyMode: BusyMode = .ImmediateError
/// The maximum number of concurrent readers (applies to database
/// pools only).
///
/// Default: 5
public var maximumReaderCount: Int = 5
// MARK: - Internal
// MARK: - Factory Configuration
/// Creates a factory configuration
public init() { }
// MARK: - Not Public
var threadingMode: ThreadingMode = .Default
var SQLiteConnectionDidOpen: (() -> ())?
var SQLiteConnectionWillClose: ((SQLiteConnection) -> ())?
var SQLiteConnectionDidClose: (() -> ())?
// MARK: - Factory Configuration
/// Returns a factory configuration:
///
/// - readonly: false
/// - fileAttributes: nil
/// - foreignKeysEnabled: true
/// - trace: nil
/// - defaultTransactionKind: .Immediate
/// - busyMode: .ImmediateError
public init() { }
// MARK: - SQLite flags
var sqliteOpenFlags: Int32 {
return threadingMode.sqliteOpenFlags | (readonly ? SQLITE_OPEN_READONLY : (SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE))
var SQLiteOpenFlags: Int32 {
return threadingMode.SQLiteOpenFlags | (readonly ? SQLITE_OPEN_READONLY : (SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE))
}
}
+2 -2
View File
@@ -104,7 +104,7 @@ public final class Database {
init(path: String, configuration: Configuration, schemaCache: DatabaseSchemaCacheType) throws {
// See https://www.sqlite.org/c3ref/open.html
var sqliteConnection: SQLiteConnection = nil
let code = sqlite3_open_v2(path, &sqliteConnection, configuration.sqliteOpenFlags, nil)
let code = sqlite3_open_v2(path, &sqliteConnection, configuration.SQLiteOpenFlags, nil)
guard code == SQLITE_OK else {
throw DatabaseError(code: code, message: String.fromCString(sqlite3_errmsg(sqliteConnection)))
}
@@ -280,7 +280,7 @@ enum ThreadingMode {
case MultiThread
case Serialized
var sqliteOpenFlags: Int32 {
var SQLiteOpenFlags: Int32 {
switch self {
case .Default:
return 0
+3 -3
View File
@@ -30,8 +30,8 @@ public final class DatabasePool {
/// - configuration: A configuration.
/// - maximumReaderCount: The maximum number of readers. Default is 5.
/// - throws: A DatabaseError whenever an SQLite error occurs.
public init(path: String, configuration: Configuration = Configuration(), maximumReaderCount: Int = 5) throws {
GRDBPrecondition(maximumReaderCount > 1, "maximumReaderCount must be at least 1")
public init(path: String, configuration: Configuration = Configuration()) throws {
GRDBPrecondition(configuration.maximumReaderCount > 0, "configuration.maximumReaderCount must be at least 1")
// Database Store
store = try DatabaseStore(path: path, attributes: configuration.fileAttributes)
@@ -64,7 +64,7 @@ public final class DatabasePool {
readerConfig.readonly = true
readerConfig.defaultTransactionKind = .Deferred // Make it the default. Other transaction kinds are forbidden by SQLite in read-only connections.
readerPool = Pool<SerializedDatabase>(maximumCount: maximumReaderCount)
readerPool = Pool<SerializedDatabase>(maximumCount: configuration.maximumReaderCount)
readerPool.makeElement = { [unowned self] in
let serializedDatabase = try! SerializedDatabase(
path: path,
-1
View File
@@ -1,5 +1,4 @@
- [ ] FetchedRecordsController: see if we can replace identity comparison function with a function that returns an Equatable value (beware the generics trouble). See if this can help optimize memory use, and use a sortedMerge() algorithm.
- [ ] DatabasePool: move maximumReaderCount to Configuration
- [ ] GRDBCipher: remove limitations on iOS or OS X versions
- [ ] FetchedRecordsController: take inspiration from https://github.com/jflinter/Dwifft
- [ ] What is the SQLITE_OPEN_WAL open flag?