# Path: voeventdb/server/database/models.py
# def _grab_xpath(root, xpath, converter=lambda x: x):
# def _has_bad_coords(root, stream):
#     def to_odict(self, exclude=None):
#     def from_etree(root, received=pytz.UTC.localize(datetime.utcnow())):
#     def _reformatted_prettydict(self, valformat=str):
#     def __repr__(self):
#     def __str__(self):
#     def from_etree(root):
#     def __repr__(self):
#     def from_etree(root):
# class OdictMixin(object):
# class Voevent(Base, OdictMixin):
# class Cite(Base, OdictMixin):
# class Coord(Base, OdictMixin):
# 
# Path: voeventdb/server/database/config.py
# def make_db_url(admin_db_params, dbname):
# def make_testdb_url(dbsuffix):


import sqlalchemy
from sqlalchemy.exc import OperationalError
from voeventdb.server.database.models import Base
from voeventdb.server.database.config import q3c_batch
from __future__ import absolute_import



def check_database_exists(db_url):
    engine = sqlalchemy.create_engine(db_url)
    try:
        conn = engine.connect()
        conn.execute("select 1").scalar()
        conn.close()
        return True
    except OperationalError:
        return False
    finally:
        engine.dispose()


def create_empty_database(admin_db_url, new_db_name):
    engine = sqlalchemy.create_engine(admin_db_url)
    conn = engine.connect()
    conn.execute('commit')
    conn.execute('create database "{}"'.format(new_db_name))
    conn.close()
    engine.dispose()
    
    
def delete_database(admin_db_url, drop_db_name):
    engine = sqlalchemy.create_engine(admin_db_url)
    conn = engine.connect()

# Path: voeventdb/server/database/models.py
# def _grab_xpath(root, xpath, converter=lambda x: x):
# def _has_bad_coords(root, stream):
#     def to_odict(self, exclude=None):
#     def from_etree(root, received=pytz.UTC.localize(datetime.utcnow())):
#     def _reformatted_prettydict(self, valformat=str):
#     def __repr__(self):
#     def __str__(self):
#     def from_etree(root):
#     def __repr__(self):
#     def from_etree(root):
# class OdictMixin(object):
# class Voevent(Base, OdictMixin):
# class Cite(Base, OdictMixin):
# class Coord(Base, OdictMixin):
# 
# Path: voeventdb/server/database/config.py
# def make_db_url(admin_db_params, dbname):
# def make_testdb_url(dbsuffix):


# Path: voeventdb/server/database/db_utils.py
import sqlalchemy
from sqlalchemy.exc import OperationalError
from voeventdb.server.database.models import Base
from voeventdb.server.database.config import q3c_batch

from __future__ import absolute_import



def check_database_exists(db_url):
    engine = sqlalchemy.create_engine(db_url)
    try:
        conn = engine.connect()
        conn.execute("select 1").scalar()
        conn.close()
        return True
    except OperationalError:
        return False
    finally:
        engine.dispose()


def create_empty_database(admin_db_url, new_db_name):
    engine = sqlalchemy.create_engine(admin_db_url)
    conn = engine.connect()
    conn.execute('commit')
    conn.execute('create database "{}"'.format(new_db_name))
    conn.close()
    engine.dispose()
    
    
def delete_database(admin_db_url, drop_db_name):
    engine = sqlalchemy.create_engine(admin_db_url)
    conn = engine.connect()

    conn.execute('commit')