Esempio n. 1
0
def RelStorageConfigurationFactory(key, dbconfig):
    if not RELSTORAGE:
        raise Exception("You must install the relstorage package before you can use "
                        "it as a dabase adapter.")
    config = dbconfig.get('configuration', {})
    options = Options(**dbconfig['options'])
    if dbconfig['type'] == 'postgres':
        from relstorage.adapters.postgresql import PostgreSQLAdapter
        dsn = "dbname={dbname} user={username} host={host} password={password} port={port}".format(**dbconfig['dsn'])  # noqa
        adapter = PostgreSQLAdapter(dsn=dsn, options=options)
    rs = RelStorage(adapter=adapter, options=options)
    db = DB(rs)
    try:
        conn = db.open()
        rootobj = conn.root()
        if not IDatabase.providedBy(rootobj):
            alsoProvides(rootobj, IDatabase)
        transaction.commit()
    except:
        pass
    finally:
        rootobj = None
        conn.close()
        db.close()
    rs = RelStorage(adapter=adapter, options=options)
    db = RequestAwareDB(rs, **config)
    return Database(key, db)
Esempio n. 2
0
 def make_adapter(self):
     from relstorage.adapters.postgresql import PostgreSQLAdapter
     if self.keep_history:
         db = base_dbname
     else:
         db = base_dbname + '_hf'
     return PostgreSQLAdapter(
         dsn='dbname=%s user=relstoragetest password=relstoragetest' % db,
         options=Options(keep_history=self.keep_history),
     )
Esempio n. 3
0
def main():
    logging.basicConfig(
        stream=sys.stderr,
        level=logging.DEBUG,
        format='%(asctime)s [%(name)s] %(levelname)s %(message)s')
    log.info("Opening")
    adapter = PostgreSQLAdapter()
    storage = RelStorage(adapter)
    db = DB(storage)
    log.info("Filling")
    fill_db(db)
    log.info("Packing")
    start = time.time()
    db.pack()
    end = time.time()
    log.info("Packed in %0.3f seconds", end - start)
Esempio n. 4
0
 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.postgresql import PostgreSQLAdapter
     db = db_names[name]
     if not keep_history:
         db += '_hf'
     dsn = ('dbname=%s user=relstoragetest '
            'password=relstoragetest' % db)
     options = Options(keep_history=keep_history,
                       shared_blob_dir=shared_blob_dir,
                       blob_dir=os.path.abspath(blob_dir),
                       **kw)
     adapter = PostgreSQLAdapter(dsn=dsn, options=options)
     storage = RelStorage(adapter, name=name, options=options)
     storage.zap_all()
     return storage
Esempio n. 5
0
 def make_adapter(self, options, db=None):
     return PostgreSQLAdapter(
         dsn=self.__get_adapter_zconfig_dsn(db),
         options=options,
     )
Esempio n. 6
0
 def create(self, options):
     from relstorage.adapters.postgresql import PostgreSQLAdapter
     return PostgreSQLAdapter(
         dsn=self.config.dsn,
         options=options,
     )
Esempio n. 7
0
 def factory(options):
     from relstorage.adapters.postgresql import PostgreSQLAdapter
     return PostgreSQLAdapter(dsn=dsn, options=options)
Esempio n. 8
0
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='******',
        password='******',
        dsn=dsn,
        options=Options(keep_history=keep_history),
        )
else:
    raise AssertionError("which database?")

s = RelStorage(a)