Configure a Data source name for Zope
Project description
visaplan.zope.reldb
This package simply provides the configuration of a Data source name (DSN), e.g. for use with SQLAlchemy.
For the heavy lifting of integration of database transactions of your relational database (like PostgreSQL or whatever) with the ZODB, you’ll likely want to use something like zope.sqlalchemy, which in turn requires sqlalchemy to talk to the database. However, zope.sqlalchemy doesn’t offer a configuration method for the DSN. This packages offers to store this DSN in the Zope configuration file (parts/clientN/etc/zope.conf).
The idea is: You might have several instances of your Zope (for production, testing, development …), and every now and then you replicate the productive data. With the DSN stored in the ZODB, you’d have this information replicated as well, which might not work for you; you might have different databases on the same database server, or the production server connects to the database by socket which is not possible in your development instance, or whatever.
Features
Stores a DSN string in the Zope configuration and provides a get_dsn function.
With SQLAlchemy installed,
creates an Engine and a DBSession, and
provides an optional .legacy.SQLWrapper context manager class which sports a few simple insert, update, delete, select and query methods
With zope.sqlalchemy installed as well, registers that DBSession for the transaction machinery integration.
Installation
Add the package to your product requirements somehow; since we’ll need to add a product configuration as well, you’ll most likely add it to your eggs value in your buildout script (buildout.cfg):
[buildout] ... eggs = your.fancy.product visaplan.zope.reldb
Add a product configuration there as well, containing your data source name:
[buildout] ... [instance_base] ... zope-conf-additional = <product-config reldb> dsn postgresql+psycopg2://localhost/mydb </product-config>
(We follow the convention used by the UnifiedInstaller here; your section(s) might be named differently.)
After running bin/buildout and restarting your Zope instance, the product configuration should have been added to your zope.conf file(s), and your.fancy.product can read the DSN string by calling visaplan.zope.reldb.get_dsn (or, if you have SQLAlchemy, directly use visaplan.zope.reldb.engine.engine).
Remark
“But, can’t my product simply do all this by itself?!”
Sure. Having this as a package helps / helped us to switch a whole bunch of packages from usage of Zope database adapters (stored in the ZODB) to sqlalchemy (with a DSN configured in the zope.conf file(s)).
Contribute
Issue Tracker: https://github.com/visaplan/zope.reldb/issues
Source Code: https://github.com/visaplan/zope.reldb
Support
If you are having issues, please let us know; please use the issue tracker mentioned above.
License
The project is licensed under the GPLv2.
Futher reading
The SQLAlchemy documentation about Database URLs
Contributors
Tobias Herp, tobias.herp@visaplan.com
Changelog
1.0.0 (unreleased)
Initial release. [tobiasherp]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file visaplan.zope.reldb-1.0.0.dev2.tar.gz
.
File metadata
- Download URL: visaplan.zope.reldb-1.0.0.dev2.tar.gz
- Upload date:
- Size: 27.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9449754953bafb7a1fd6bf99922c7ac2e7d865f4c5abe5af1cc5660cbf06733c |
|
MD5 | 3132f7abd2e7fc36683757af43c2e5b4 |
|
BLAKE2b-256 | 29e0a2a9eb09075973d324501e32c44a34821b79e18e03a919fb38be64f34cbc |