如何在金字塔框架中使用spacespaceite? (或其他?)

时间:2019-07-09 15:45:20

标签: python sqlalchemy geometry pyramid spatialite

[编辑]

尝试在Windows中重现this。该怎么做?

即使我将dll文件放在%PATH%中定义的目录中,也可以尝试使用/不使用完整路径,使用/不使用文件扩展名,使用'//'或'\',使用libspatialite-4.dll或用前面提到的所有组合来执行...  dbapi_conn.execute(“ SELECT load_extension('mod_spatialite.dll')”)

例如,我尝试了这种组合:

def load_spatialite(dbapi_conn, connection_record):
    dbapi_conn.load_extension('C:\\Scripts\\mod_spatialite.dll')
    # dbapi_conn.load_extension('C:\\Scripts\\libspatialite-4.dll')
    # dbapi_conn.load_extension('mod_spatialite')
    # dbapi_conn.load_extension('mod_spatialite.dll')
    # dbapi_conn.execute("SELECT load_extension('C:\\pyramid\\risc\\api\\Scripts\\mod_spatialite.dll')")
    # dbapi_conn.execute("SELECT load_extension('mod_spatialite.dll')")
    # dbapi_conn.execute("SELECT load_extension('mod_spatialite')")
    # dbapi_conn.load_extension('C:/Scripts\mod_spatialite.dll')

一个简单的问题,但对我来说却是一个难题:如何在金字塔框架中使用spacespaceite?

首先,有我的环境:

  

Windows 10:
  Python版本:3.6.8
  本地数据库:sqlite(用于spacespaceite)
  远程数据库:postgresql

我发现很多示例,它们使用create_enginelibsqlite3mod_spatialite之类的lib在pysqlite3中的spatialite的{​​{3}}的模块参数中设置了spacespaceite就我而言,我使用setup.py和pip一起安装(软件包在create_engine中定义)

我的问题是,我没有控制pyramid.reload_templates = true pyramid.reload_assets = true pyramid.debug_authorization = true pyramid.debug_notfound = false pyramid.debug_routematch = true pyramid.default_locale_name = en pyramid.includes = pyramid_debugtoolbar pyramid_tm sqlalchemy.url = sqlite:///%(here)s/risc.sqlite ,该引擎来自ini的设置,因此我认为我必须通过ini文件传递该设置,但是我没有得到它。我找不到使用与我相同的组合环境(Windows,金字塔,spacerite)的任何代码示例。

有ini文件的设置:

from sqlalchemy import engine_from_config
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import configure_mappers
import zope.sqlalchemy


# run configure_mappers after defining all of the models to ensure
# all relationships can be setup
configure_mappers()


def get_engine(settings, prefix='sqlalchemy.'):
    return engine_from_config(settings, prefix)


def get_session_factory(engine):
    factory = sessionmaker()
    factory.configure(bind=engine)
    return factory


def get_tm_session(session_factory, transaction_manager):
    dbsession = session_factory()
    zope.sqlalchemy.register(dbsession, transaction_manager=transaction_manager)
    return dbsession


def includeme(config):
    settings = config.get_settings()
    settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager'

    # use pyramid_tm to hook the transaction lifecycle to the request
    config.include('pyramid_tm')

    # use pyramid_retry to retry a request when transient exceptions occur
    config.include('pyramid_retry')

    session_factory = get_session_factory(get_engine(settings))
    config.registry['dbsession_factory'] = session_factory

    # make request.dbsession available for use in Pyramid
    config.add_request_method(
        # r.tm is the transaction manager used by pyramid_tm
    lambda r: get_tm_session(session_factory, r.tm),
    'dbsession',
    reify=True
)

创建引擎的代码:

setup.py

还有requires = [ 'bcrypt', 'docutils', 'plaster_pastedeploy', 'pyramid', 'pyramid_debugtoolbar', 'pyramid_retry', 'pyramid_tm', 'sqlalchemy', 'transaction', 'zope.sqlalchemy', 'waitress', 'sphinx', 'flake8', 'pyLint', 'pg8000', 'geoalchemy2', 'spatialite' ]

的设置模块
server_name

我敢肯定我会错过一些东西,但是我找不到自己的方式。我对此没有什么暗示。

谢谢

0 个答案:

没有答案