Skip to content

Commit

Permalink
Use journal_mode = WAL on annotations.db
Browse files Browse the repository at this point in the history
as originally intended
  • Loading branch information
olsen232 committed Aug 17, 2023
1 parent bf5a2f7 commit a6f1fc2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion kart/annotations/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def ignore_readonly_db(session):

@contextlib.contextmanager
def _annotations_session(db_path):
engine = sqlite_engine(db_path)
engine = sqlite_engine(db_path, journal_mode="WAL")
sm = sessionmaker(bind=engine)
inspector = sqlalchemy.inspect(engine)
is_readonly = None
Expand Down
6 changes: 4 additions & 2 deletions kart/sqlalchemy/gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class Db_GPKG(BaseDb):
preparer = SQLiteIdentifierPreparer(SQLiteDialect())

@classmethod
def create_engine(cls, path, **kwargs):
def create_engine(cls, path, *, journal_mode=None, **kwargs):
def _on_connect(pysqlite_conn, connection_record):
pysqlite_conn.isolation_level = None
pysqlite_conn.enable_load_extension(True)
pysqlite_conn.load_extension(spatialite_path)
pysqlite_conn.enable_load_extension(False)
dbcur = pysqlite_conn.cursor()
if journal_mode:
dbcur.execute(f"PRAGMA journal_mode = {journal_mode};")
dbcur.execute("SELECT EnableGpkgMode();")
dbcur.execute("PRAGMA foreign_keys = ON;")
dbcur.execute(f"PRAGMA cache_size = -{cls.GPKG_CACHE_SIZE_MiB * 1024};")
Expand Down Expand Up @@ -64,7 +66,7 @@ def list_tables(cls, sess, db_schema=None):

@classmethod
def pk_name(cls, sess, db_schema=None, table=None):
""" Find the primary key for a GeoPackage table """
"""Find the primary key for a GeoPackage table"""

# Requirement 150:
# A feature table or view SHALL have a column that uniquely identifies the
Expand Down
4 changes: 3 additions & 1 deletion kart/sqlalchemy/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import sqlalchemy


def sqlite_engine(path):
def sqlite_engine(path, *, journal_mode=None):
"""
An engine for non-spatial, non-GPKG sqlite databases.
"""

def _on_connect(pysqlite_conn, connection_record):
pysqlite_conn.isolation_level = None
dbcur = pysqlite_conn.cursor()
if journal_mode:
dbcur.execute(f"PRAGMA journal_mode = {journal_mode};")
dbcur.execute("PRAGMA foreign_keys = ON;")

path = os.path.expanduser(path)
Expand Down

0 comments on commit a6f1fc2

Please sign in to comment.