my environment:
Windows 10:
Python version: 3.6.8
Local database: sqlite (for spatialite)
Remote database: postgresql
I find a lot of exemples where spatialite is set in the module parameter for the engine in create_engine using lib like libsqlite3, mod_spatialite, pysqlite3 in my case I use spatialiteinstall with pip (package define in setup.py)
My problem is then I don't have the control of create_engine, in the engine comming from settings in ini so I think that I have to pass the setting by the ini file but I did'nt get it. I didn't find any good example of code using same combination environment as mine (windows, pyramid, spatialite).
There are the settings of ini file:
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.sqliteCode where the engine is create:
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
)And the settings module of 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'
]I'm pretty sure than I miss a little something, but I'm not able to find it my way. I little hint will be appreciated on this one.
Thanks
Â
Â
Hi Michael,
Â
I never used spatialite. But from looking at your example code, you seem to create a “simple sqlite” connection, whereas somehow this extension needs to be loaded. From what a quick google search revealed, there seems not to exist some special connection string, that does the magic to load this extension.
Â
Looking here: https://datasette.readthedocs.io/en/stable/spatialite.html#spatial-indexing-latitude-longitude-columns it looks like you’re missing
Â
conn.enable_load_extension(True)
conn.load_extension('/usr/local/lib/mod_spatialite.dylib')
Â
which I would guess belongs into your `get_tm_session` function. Try debugging into that and see if it works on `dbsession` or some property on it.
Â
Hope that helps, Andi
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/15188080-e8eb-4e72-bf32-14dadf302909%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'mod_spatialite', # Ubuntu
'mod_spatialite.so', # Ubuntu
'mod_spatialite.dylib', # macOS
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-...@googlegroups.com.
def load_spatialite(dbapi_conn, connection_record):
dbapi_conn.enable_load_extension(True)
dbapi_conn.load_extension('C:\\Scripts\\mod_spatialite.dll')