def create_db(path, github=False): path = os.path.expanduser(path) if os.path.exists(path): raise DatabaseException("Database '{}' already exists" .format(path)) print("creating database ...".format(path)) db = sqlite3.connect(path) c = db.cursor() if github: script = smith.sql_script('create-gh-samples-db') else: script = smith.sql_script('create-samples-db') c.executescript(script) c.close() db.commit()
def connect_to_database(db_path): """ Connect to database. If database does not exist, create it. :param db_path: Path to database file :return: Connection to database. """ if not os.path.exists(db_path): db = sqlite3.connect(db_path) c = db.cursor() script = smith.sql_script('create-samples-db') c.executescript(script) c.close() return db else: return sqlite3.connect(db_path)
def create_new(path): """ Create a new Parboil database. :param path: Path to database to create. :return: Parboil class instance of newly created database. :throws DatabaseException: If file already exists. """ path = os.path.expanduser(path) if os.path.exists(path): raise DatabaseException("Database '{}' already exists" .format(path)) print("creating database ...".format(path)) db = sqlite3.connect(path) c = db.cursor() script = smith.sql_script('create-parboil-db') c.executescript(script) c.close() return Database(path)