Parses a database URL in this format:
    [database type]://[username]:[password]@[host]:[port]/[database name]

    or, for cloud SQL:
    [database type]://[username]:[password]@[project_id]:[instance_name]/[database name]

def parse(url):
    """
    Parses a database URL in this format:
    [database type]://[username]:[password]@[host]:[port]/[database name]

    or, for cloud SQL:
    [database type]://[username]:[password]@[project_id]:[instance_name]/[database name]
    """
    config = {}

    url = urlparse.urlparse(url)

    # Remove query strings.
    path = url.path[1:]
    path = path.split('?', 2)[0]

    try:
        port = url.port
        hostname = url.hostname
    except ValueError:
        port = None
        if url.scheme == 'rdbms':
            # local appengine stub requires INSTANCE parameter
            config['INSTANCE'] = url.netloc.split('@')[-1]
            hostname = None
        else:
            hostname = "/cloudsql/{}".format(url.netloc.split('@')[-1])

    config.update({
        'NAME': path,
        'USER': url.username,
        'PASSWORD': url.password,
        'HOST': hostname,
        'PORT': port,
    })

    if url.scheme in SCHEMES:
        config['ENGINE'] = SCHEMES[url.scheme]

    return config