Package couchdbkit :: Package ext :: Package pylons :: Module db
[hide private]
[frames] | no frames]

Source Code for Module couchdbkit.ext.pylons.db

 1  # -*- coding: utf-8 - 
 2  # 
 3  # This file is part of couchdbkit released under the MIT license.  
 4  # See the NOTICE for more information. 
 5   
 6  import os.path 
 7   
 8  from ...client import Server 
 9  from ...designer import pushapps 
10  from ...schema import Document 
11   
12 -def init_from_config(config):
13 """Initialize the database given a pylons config. This assumes the 14 configuration format layed out on the wiki. This will only initialize the 15 primary database. 16 17 This prefixes the database name with test_ if we're running unit tests. 18 """ 19 uri = config['couchdb.uri'] 20 dbname = config['couchdb.dbname'] 21 22 config['couchdb.db'] = init_db(uri, dbname) 23 config['couchdb.fixtures'] = os.path.join(config['pylons.paths']['root'], "fixtures")
24
25 -def init_db(uri, dbname, main_db=True):
26 """Returns a db object and syncs the design documents on demand. 27 If main_db is set to true then all models will use that one by default. 28 """ 29 server = Server(uri) 30 31 db = server.get_or_create_db(dbname) 32 if main_db: 33 Document.set_db(db) 34 return db
35
36 -def sync_design(db, path):
37 """Synchronizes the design documents with the database passed in.""" 38 pushapps(path, db)
39
40 -def default_design_path(config):
41 """Returns full path to the default design documents path, it's _design in 42 the pylons root path 43 """ 44 return os.path.join(config['pylons.paths']['root'], "_design")
45