__all__ = [
    'create_engine',
]

import sqlalchemy


def create_engine(
        db_uri, *,
        check_same_thread=False,
        echo=False,
        pragmas=()):

    engine = sqlalchemy.create_engine(
        db_uri,
        echo=echo,
        connect_args={
            'check_same_thread': check_same_thread,
        },
    )

    @sqlalchemy.event.listens_for(engine, 'connect')
    def do_connect(dbapi_connection, _):
        # Stop pysqlite issue commit automatically.
        dbapi_connection.isolation_level = None
        # Enable foreign key.
        cursor = dbapi_connection.cursor()
        cursor.execute("PRAGMA foreign_keys = ON")
        for name, value in pragmas:
            cursor.execute("PRAGMA %s = %s" % (name, value))
        cursor.close()

    @sqlalchemy.event.listens_for(engine, 'begin')
    def do_begin(connection):
        connection.execute('BEGIN EXCLUSIVE')

    return engine

@@ -615,25 +615,25 @@
 sor.execute(
-%22
+'
 PRAGMA forei
@@ -644,17 +644,17 @@
 eys = ON
-%22
+'
 )%0A      
@@ -710,17 +710,17 @@
 execute(
-%22
+'
 PRAGMA %25
@@ -729,9 +729,9 @@
 = %25s
-%22
+'
  %25 (

Replace double quotes with single quotes