def load_spatialite(con, connection_record):
    """Load spatialite extension as described in
    https://geoalchemy-2.readthedocs.io/en/latest/spatialite_tutorial.html"""
    import sqlite3
    con.enable_load_extension(True)
    cur = con.cursor()
    libs = [('mod_spatialite', 'sqlite3_modspatialite_init'), (
        'mod_spatialite.so', 'sqlite3_modspatialite_init'), (
        'libspatialite.so', 'sqlite3_extension_init')]
    found = False
    for lib, entry_point in libs:
        try:
            cur.execute("select load_extension('{}', '{}')".format(lib,
                entry_point))
        except sqlite3.OperationalError:
            continue
        else:
            found = True
            break
    if not found:
        raise RuntimeError('Cannot find any suitable spatialite module')
    cur.close()
    con.enable_load_extension(False)
