Skip to content

Commit

Permalink
added sqlite wal mode enable logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Umed Khudoiberdiev authored and imnotjames committed Aug 19, 2020
1 parent a9d8b0b commit 1eed6d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/driver/sqlite/SqliteConnectionOptions.ts
Expand Up @@ -26,9 +26,18 @@ export interface SqliteConnectionOptions extends BaseConnectionOptions {
* Since SQLite cannot handle parallel saves this error cannot be avoided.
*
* To simplify life's of those who have this error this particular option sets a timeout within which ORM will try
* to perform requested write operation again and again until it recieves SQLITE_BUSY error.
* to perform requested write operation again and again until it receives SQLITE_BUSY error.
*
* Enabling WAL can improve your app performance and face less SQLITE_BUSY issues.
* Time in milliseconds.
*/
readonly busyErrorRetry?: number;

/**
* Enables WAL mode. By default its disabled.
*
* @see https://www.sqlite.org/wal.html
*/
readonly enableWAL?: boolean;

}
11 changes: 10 additions & 1 deletion src/driver/sqlite/SqliteQueryRunner.ts
Expand Up @@ -4,6 +4,7 @@ import {AbstractSqliteQueryRunner} from "../sqlite-abstract/AbstractSqliteQueryR
import {SqliteConnectionOptions} from "./SqliteConnectionOptions";
import {SqliteDriver} from "./SqliteDriver";
import {Broadcaster} from "../../subscriber/Broadcaster";
import {IsolationLevel} from "../types/IsolationLevel";

/**
* Runs queries on a single sqlite database connection.
Expand Down Expand Up @@ -83,4 +84,12 @@ export class SqliteQueryRunner extends AbstractSqliteQueryRunner {
await execute();
});
}
}

async startTransaction(isolationLevel?: IsolationLevel): Promise<void> {
if ((this.connection.options as SqliteConnectionOptions).enableWAL === true) {
await this.query("PRAGMA journal_mode = WAL");
}

return super.startTransaction(isolationLevel);
}
}

0 comments on commit 1eed6d1

Please sign in to comment.