diff --git a/README.md b/README.md
index db20536..19190e1 100644
--- a/README.md
+++ b/README.md
@@ -80,6 +80,7 @@ Boolean values can be one of:
| Defer Foreign Keys | `_defer_foreign_keys` \| `_defer_fk` | `boolean` | For more information see [PRAGMA defer_foreign_keys](https://www.sqlite.org/pragma.html#pragma_defer_foreign_keys) |
| Foreign Keys | `_foreign_keys` \| `_fk` | `boolean` | For more information see [PRAGMA foreign_keys](https://www.sqlite.org/pragma.html#pragma_foreign_keys) |
| Ignore CHECK Constraints | `_ignore_check_constraints` | `boolean` | For more information see [PRAGMA ignore_check_constraints](https://www.sqlite.org/pragma.html#pragma_ignore_check_constraints) |
+| Journal Mode | `_journal` |
- DELETE
- TRUNCATE
- PERSIST
- MEMORY
- WAL
- OFF
| For more information see [PRAGMA journal_mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) |
| Mode | `mode` | | Access Mode of the database. For more information see [SQLite Open](https://www.sqlite.org/c3ref/open.html) |
| Mutex Locking | `_mutex` | | Specify mutex mode. |
| Recursive Triggers | `_recursive_triggers` \| `_rt` | `boolean` | For more information see [PRAGMA recursive_triggers](https://www.sqlite.org/pragma.html#pragma_recursive_triggers) |
diff --git a/sqlite3.go b/sqlite3.go
index 4b79aac..3855882 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -838,6 +838,10 @@ func errorString(err Error) string {
// This pragma enables or disables the enforcement of CHECK constraints.
// The default setting is off, meaning that CHECK constraints are enforced by default.
//
+// _journal=MODE
+// Set journal mode for the databases associated with the current connection.
+// https://www.sqlite.org/pragma.html#pragma_journal_mode
+//
// _recursive_triggers=Boolean | _rt=Boolean
// Enable or disable recursive triggers.
//
@@ -863,6 +867,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
caseSensitiveLike := -1
deferForeignKeys := -1
ignoreCheckConstraints := -1
+ journalMode := "DELETE"
foreignKeys := -1
recursiveTriggers := -1
@@ -1022,6 +1027,19 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
}
}
+ // Journal Mode (_journal)
+ //
+ // https://www.sqlite.org/pragma.html#pragma_journal_mode
+ //
+ if val := params.Get("_journal"); val != "" {
+ switch strings.ToUpper(val) {
+ case "DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF":
+ journalMode = strings.ToUpper(val)
+ default:
+ return nil, fmt.Errorf("Invalid _journal: %v, expecting value of 'DELETE TRUNCATE PERSIST MEMORY WAL OFF'", val)
+ }
+ }
+
// Recursive Triggers (_recursive_triggers)
//
// https://www.sqlite.org/pragma.html#pragma_recursive_triggers
@@ -1118,6 +1136,13 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
}
}
+ // Journal Mode
+ // Because default Journal Mode is DELETE this PRAGMA can always be executed.
+ if err := exec(fmt.Sprintf("PRAGMA journal_mode = %s;", journalMode)); err != nil {
+ C.sqlite3_close_v2(db)
+ return nil, err
+ }
+
// Recursive Triggers
if recursiveTriggers > -1 {
if err := exec(fmt.Sprintf("PRAGMA recursive_triggers = %d;", recursiveTriggers)); err != nil {