本文整理汇总了Python中ming.create_datastore函数的典型用法代码示例。如果您正苦于以下问题:Python create_datastore函数的具体用法?Python create_datastore怎么用?Python create_datastore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_datastore函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: command
def command(self):
self._setup_logging()
self._load_migrations()
from .runner import run_migration, reset_migration, show_status, set_status
bind = create_engine(self.options.connection_url)
if self.options.database is None:
datastores = [
create_datastore(db, bind=bind)
for db in bind.conn.database_names()
if db not in ('admin', 'local') ]
else:
datastores = [ create_datastore(self.options.database, bind=bind) ]
for ds in datastores:
self.log.info('Migrate DB: %s', ds.database)
if self.options.status_only:
show_status(ds)
elif self.options.force:
set_status(ds, self._target_versions())
elif self.options.reset:
reset_migration(ds, dry_run=self.options.dry_run)
else:
run_migration(ds, self._target_versions(), dry_run=self.options.dry_run)
try:
ds.conn.disconnect()
ds._conn = None
except: # MIM doesn't do this
pass
示例2: setUp
def setUp(self):
self.datastore = create_datastore('mim:///test_db')
self.session = ODMSession(bind=self.datastore)
class GrandParent(MappedClass):
class __mongometa__:
name='grand_parent'
session=self.session
_id = FieldProperty(int)
class Parent(MappedClass):
class __mongometa__:
name='parent'
session = self.session
_id = FieldProperty(int)
grandparent_id = ForeignIdProperty('GrandParent')
grandparent = RelationProperty('GrandParent')
children = RelationProperty('Child')
class Child(MappedClass):
class __mongometa__:
name='child'
session = self.session
_id = FieldProperty(int)
parent_id = ForeignIdProperty('Parent', allow_none=True)
parent = RelationProperty('Parent')
Mapper.compile_all()
self.GrandParent = GrandParent
self.Parent = Parent
self.Child = Child
示例3: includeme
def includeme(config):
engine = create_datastore(os.getenv(config.registry.settings['mongo_url_env'], 'openrosetta'))
session.bind = engine
Mapper.compile_all()
for mapper in Mapper.all_mappers():
session.ensure_indexes(mapper.collection)
config.add_tween('openrosetta.models.ming_autoflush_tween', over=EXCVIEW)
示例4: setUp
def setUp(self):
self.bind = create_datastore('mim:///testdb')
self.bind.conn.drop_all()
self.bind.db.coll.insert(
{'_id':'foo', 'a':2,
'b': { 'c': 1, 'd': 2, 'e': [1,2,3],
'f': [ { 'g': 1 }, { 'g': 2 } ] },
'x': {} })
self.coll = self.bind.db.coll
示例5: setUp
def setUp(self):
self.datastore = create_datastore('mim:///test_db')
session = Session(bind=self.datastore)
self.session = ODMSession(session)
basic = collection('basic', session)
class Basic(object):
pass
self.session.mapper(Basic, basic)
self.basic = basic
self.Basic = Basic
示例6: create_ming_datastore
def create_ming_datastore(conf):
from ming import create_datastore
url = conf['ming.url']
database = conf.get('ming.db', '')
try:
connection_options = get_partial_dict('ming.connection', conf)
except AttributeError:
connection_options = {}
if database and url[-1] != '/':
url += '/'
ming_url = url + database
return create_datastore(ming_url, **connection_options)
示例7: setUp
def setUp(self):
self.datastore = create_datastore('mim:///test_db')
self.session = ThreadLocalODMSession(Session(bind=self.datastore))
class Parent(MappedClass):
class __mongometa__:
name='parent'
session = self.session
_id = FieldProperty(S.ObjectId)
Mapper.compile_all()
self.Parent = Parent
self.create_app = TestApp(MingMiddleware(self._wsgi_create_object))
self.remove_app = TestApp(MingMiddleware(self._wsgi_remove_object))
self.remove_exc = TestApp(MingMiddleware(self._wsgi_remove_object_exc))
示例8: __init__
def __init__(self, path = None, dbtype = 'auto'):
"""
path - Path to store sandbox files.
dbtype - Type of the dabatabse. [auto|mongo|ming]
"""
if 'LUNA_TEST_DBTYPE' in os.environ:
dbtype = os.environ['LUNA_TEST_DBTYPE']
if not path:
self.path = tempfile.mkdtemp(prefix='luna')
else:
# can cause race condition, but ok
if not os.path.exists(path):
os.makedirs(path)
self.path = path
self._dbconn = None
self._mingdatastore = None
self._mongopath = self.path + "/mongo"
if not os.path.exists(self._mongopath):
os.makedirs(self._mongopath)
self._mongoprocess = None
if dbtype == 'auto':
try:
self._start_mongo()
self.dbtype = 'mongo'
except OSError:
self._mingdatastore = ming.create_datastore('mim:///' + str(uuid.uuid4()))
self._dbconn = self._mingdatastore.db.luna
self.dbtype = 'ming'
elif dbtype == 'mongo':
self._start_mongo()
self.dbtype = 'mongo'
else:
self._mingdatastore = ming.create_datastore('mim:///' + str(uuid.uuid4()))
self._dbconn = self._mingdatastore.db.luna
self.dbtype = 'ming'
self._create_luna_homedir()
示例9: setupClass
def setupClass(cls):
if ming is None:
raise SkipTest('Ming not available...')
cls.basic_session = Session(create_datastore('mim:///'))
cls.s = ODMSession(cls.basic_session)
class Author(MappedClass):
class __mongometa__:
session = cls.s
name = 'wiki_author'
_id = FieldProperty(schema.ObjectId)
name = FieldProperty(str)
pages = RelationProperty('WikiPage')
class WikiPage(MappedClass):
class __mongometa__:
session = cls.s
name = 'wiki_page'
_id = FieldProperty(schema.ObjectId)
title = FieldProperty(str)
text = FieldProperty(str)
order = FieldProperty(int)
author_id = ForeignIdProperty(Author)
author = RelationProperty(Author)
cls.Author = Author
cls.WikiPage = WikiPage
Mapper.compile_all()
cls.author = Author(name='author1')
author2 = Author(name='author2')
WikiPage(title='Hello', text='Text', order=1, author=cls.author)
WikiPage(title='Another', text='Text', order=2, author=cls.author)
WikiPage(title='ThirdOne', text='Text', order=3, author=author2)
cls.s.flush()
cls.s.clear()
示例10: dict
from ming import create_datastore
from ming.odm import ThreadLocalODMSession
from litminer import config
auth = dict(config["mongodb"])
uri = auth.pop("uri",None)
session = ThreadLocalODMSession(
bind=create_datastore(uri=uri,authenticate=auth)
)
示例11: __init__
def __init__(self, mongo_uri):
if mongo_uri[0]=='$':
mongo_uri = os.getenv(mongo_uri[1:])
self.mongo_engine = create_datastore(mongo_uri)
示例12: setUp
def setUp(self):
self.mg = ming.create_datastore('mim://', db='nba', **kwargs)
self.nbam = NBAMongo(self.mg.db)
self.games = []
self.standings = []
self._get_scoreboard()
示例13: setUp
def setUp(self):
self.bind = create_datastore('mim:///testdb')
self.bind.conn.drop_all()
示例14: setUp
def setUp(self):
self.ds = create_datastore("mim:///test")
self.Session = Session(bind=self.ds)
self.TestFS = fs.filesystem("test_fs", self.Session)
示例15: create_datastore
from ming import Session, create_datastore
from ming import Document, Field, schema
import json
import urllib2
bind = create_datastore('mongodb://localhost/paperMiningTest')
session = Session(bind)
class Paper(Document):
class __mongometa__:
session = session
name = 'paperCoCitation'
id = Field(str)
cocitation = Field([]) #put cite paper id
if __name__ == '__main__':
baseUrl = "http://140.118.175.209/paper/cocitation.php?ids="
with open('paperId.json') as data_file:
data = json.load(data_file)
for paperId in data["CitationId"]:
url = baseUrl + str(paperId)
arr = = json.load(urllib2.urlopen(url))
if len(arr) is not 0:
cocitationRelationDic = arr[0]
paperRel = Paper(dict(id = cocitationRelationDic["id"],cocitation = cocitationRelationDic["co_citation"]))
paperRel.m.save()
print paperRel
else:
print "No cocitation"