Skip to main content

A Plone control panel for SQL Alchemy connection strings

Project description

Introduction

This package provides a simple control panel and storage for SQLAlchemy connection strings. It presents a form where one can add and remove named connections, and a GS import and export step to manage these.

This package does not provide SQLAlchemy integration itself; use a library like zope.sqlalchemy or collective.lead instead.

Example usage:

from zope.app.component.hooks import getSite
from collective.saconnect.interfaces import ISQLAlchemyConnectionStrings

saconnect = ISQLAlchemyConnectionStrings(getSite())
myconnection = saconnect['myidentifier']

ISQLAlchemyConnectionStrings acts as a simple dictionary, although it’s keys and values must be simple strings.

To import connection strings through GenericSetup, simply include a file named saconnections.xml in your profile, with a top-level ‘connections’ element and one ‘connection’ element per connection, with name and string attributes:

<?xml version="1.0"?>
<connections>
 <connection name="bar" string="sqlite:////path/to/bar.sqlite"/>
 <connection name="foo" string="oracle://username:password/tnsnamethere"/>
</connections>

To remove any of the connections, use the ‘remove’ attribute:

<?xml version="1.0"?>
<connections>
  <connection name="bar" remove=""/>
</connections>

If you cache your SQLAlchemy connections, you may want to listen for the IObjectModifiedEvent for ISQLAlchemyConnectionStrings; the event includes the key of the modified string, so you can easily refresh your database connections:

<subscriber
    handler=".mymodule.saconnectionUpdated"
    for="collective.saconnect.interfaces.ISQLAlchemyConnectionStrings
         zope.lifecycleevent.interfaces.IObjectModifiedEvent"
    />
def saconnectionUpdated(connections, event):
    if 'myconnectionstring' in event.descriptions:
        getUtility(IDatabase, u'myconnection').invalidate()

Credits

Development sponsored by

Elkjøp Nordic AS

Design and development

Martijn Pieters at Jarn

Changelog

1.1 - 2009-03-17

  • Fixed editing existing entries. [mj]

1.0 - 2009-03-17

  • Initial release [mj]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

collective.saconnect-1.1.tar.gz (7.3 kB view details)

Uploaded Source

File details

Details for the file collective.saconnect-1.1.tar.gz.

File metadata

File hashes

Hashes for collective.saconnect-1.1.tar.gz
Algorithm Hash digest
SHA256 0dc4129dbbac5b2015a7d72481f1619e565b427391b9ed6401d4d64aa9ba5436
MD5 f8ff2d6553a5b0f5b696807700feaf71
BLAKE2b-256 9115099462db2be33611d6881aa221bda046a510cbc18a3ecc3809f2d60bd205

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page