def getRelstorageConnection(host='localhost', port=3306, user='******', passwd=None, db='zodb', socket=None, keep_history=False): from relstorage.storage import RelStorage from relstorage.adapters.mysql import MySQLAdapter connectionParams = { 'host': host, 'port': port, 'user': user, 'passwd': passwd, 'db': db, } if socket: connectionParams['unix_socket'] = socket kwargs = { 'keep_history': keep_history, } from relstorage.options import Options adapter = MySQLAdapter(options=Options(**kwargs), **connectionParams) storage = RelStorage(adapter, **kwargs) from ZODB import DB db = DB(storage, 0) return db
def create(self, options): from relstorage.adapters.mysql import MySQLAdapter params = {} for key in self.config.getSectionAttributes(): value = getattr(self.config, key) if value is not None: params[key] = value return MySQLAdapter(options=options, **params)
def make_adapter(self, options): from relstorage.adapters.mysql import MySQLAdapter if self.keep_history: db = base_dbname else: db = base_dbname + '_hf' return MySQLAdapter( options=options, db=db, user='******', passwd='relstoragetest', )
def __init__(self, db_uri): uri = urlparse(db_uri) self.mysql = MySQLAdapter(host=uri.hostname, port=uri.port, user=uri.username, passwd=uri.password, db=uri.path[1:], options=Options(keep_history=False)) self.storage = RelStorage(adapter=self.mysql) self.db = ZODB.DB(self.storage) with self.db.transaction() as c: if "nodes" not in c.root(): c.root.nodes = BTrees.OOBTree.BTree() if "classes" not in c.root(): c.root.classes = BTrees.OOBTree.BTree()
def testRelstorage(): import ZODB, transaction from ZODB import FileStorage, DB from relstorage.adapters.mysql import MySQLAdapter from relstorage.storage import RelStorage from MySQLdb import OperationalError server = 'peat.ucd.ie' username = '******' password = '******' project = 'test' port = 8080 adapter = MySQLAdapter(host=server, user=username, passwd=password, db=project, port=port) storage = RelStorage(adapter, shared_blob_dir=False, blob_dir='tempblob') db = DB(storage) connection = db.open() print storage connection = db.open() dbroot = connection.root() data = dbroot['data'] print data def addfile(fname): myblob = Blob() b = myblob.open('w') o = open(fname) data = o.read() b.write(data) print b.name b.close() return myblob '''f='gogh.chambre-arles.jpg' b=addfile(f) data['aaa'] = FileRecord(name=f,blob=b)''' #t = transaction.get() #t.commit() return
def create_storage(name, blob_dir, shared_blob_dir=shared_blob_dir, keep_history=keep_history, **kw): from relstorage.storage import RelStorage from relstorage.adapters.mysql import MySQLAdapter db = db_names[name] if not keep_history: db += '_hf' options = Options( keep_history=keep_history, shared_blob_dir=shared_blob_dir, blob_dir=os.path.abspath(blob_dir), **kw) adapter = MySQLAdapter( options=options, db=db, user='******', passwd='relstoragetest', ) storage = RelStorage(adapter, name=name, options=options) storage.zap_all() return storage
def make_adapter(self, options, db=None): return MySQLAdapter( options=options, **self.__get_adapter_options(db) )
def factory(options): from relstorage.adapters.mysql import MySQLAdapter return MySQLAdapter(options=options, **settings)
import transaction from persistent.mapping import PersistentMapping import random import os logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) use = 'oracle' keep_history=True if use == 'mysql': from relstorage.adapters.mysql import MySQLAdapter a = MySQLAdapter( db='packtest', user='******', passwd='relstoragetest', options=Options(keep_history=keep_history), ) elif use == 'postgresql': from relstorage.adapters.postgresql import PostgreSQLAdapter a = PostgreSQLAdapter(dsn= "dbname='packtest' " 'user=relstoragetest ' 'password=relstoragetest', options=Options(keep_history=keep_history), ) elif use == 'oracle': from relstorage.adapters.oracle import OracleAdapter dsn = os.environ.get('ORACLE_TEST_DSN', 'XE') a = OracleAdapter( user='******',
import logging import sys format = '%(asctime)s [%(name)s] %(levelname)s %(message)s' logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=format) import transaction from relstorage.storage import RelStorage from relstorage.options import Options from relstorage.adapters.mysql import MySQLAdapter from ZODB.DB import DB options = Options() adapter = MySQLAdapter(db='shane', options=options) storage = RelStorage(adapter, options=options) db = DB(storage) conn = db.open() root = conn.root() root['x'] = root.get('x', 0) + 1 transaction.commit() conn.close() db.pack()