Beispiel #1
0
def remove(ctx, collection_id, property_):
    """Removes a collection"""
    get_session_project_client().collection.remove(identity=collection_id,
                                                   property=property_)
    if property_:
        click.echo('Property removed')
    else:
        click.echo('Collection removed')
Beispiel #2
0
def update(ctx, collection_id, filter_, operation):
    """Update documents"""
    click.echo(
        'Updated documents: %s' %
        get_session_project_client().documents.update(
            collection=collection_id, operation=operation,
            filter=filter_)['updated'])
Beispiel #3
0
def get_file(ctx, document_id, collection_id, property_):
    """Returns a file content"""
    with click.open_file('-', 'w') as stdout:
        for file_part in get_session_project_client().document.get_file(
                identity=document_id, collection=collection_id,
                property=property_):
            stdout.write(file_part)
Beispiel #4
0
def create(ctx, data, collection_id, pretty):
    """Creates a document"""
    echo_json(get_session_project_client().document.create(
        data=data,
        collection=collection_id,
    ),
              pretty=pretty)
Beispiel #5
0
def update(ctx, document_id, collection_id, data, property_, pretty):
    """Updates a document"""
    echo_json(get_session_project_client().document.update(
        data=data,
        collection=collection_id,
        identity=document_id,
        property=property_),
              pretty=pretty)
Beispiel #6
0
def update(ctx, collection_id, data, property_):
    """Updates a collection"""
    response = get_session_project_client().collection.update(
        identity=collection_id, data=data, property=property_)
    if property_:
        click.echo('Property updated')
    else:
        click.echo('Collection updated')
Beispiel #7
0
def upsert(ctx, collection_id, filter_, operation):
    """Update or insert document"""
    response = get_session_project_client().documents.upsert(
        collection=collection_id, filter=filter_, operation=operation)
    if response.get('upsertedId'):
        click.echo('Created document with identity %s' %
                   response.get('upsertedId'))
    else:
        click.echo('Updated documents: %s' % response.get('updated'))
Beispiel #8
0
def save(ctx, collection_id, data, property_):
    """Saves a collection"""
    response = get_session_project_client().collection.save(
        identity=collection_id, data=data, property=property_)
    if property_:
        click.echo('Property saved')
    elif response['created']:
        click.echo('Collection created')
    else:
        click.echo('Collection updated')
Beispiel #9
0
def find(ctx, collection_id, filter_, text_, fields, fields_exclude, pretty,
         sort):
    """Find documents"""
    for document in get_session_project_client().documents.find(
            collection=collection_id,
            filter=filter_,
            text=text_,
            fields=fields,
            fields_exclude=fields_exclude,
            sort=sort):
        echo_json(document, pretty=pretty)
Beispiel #10
0
def count(ctx, collection_id, filter_, text_):
    """Number of documents"""
    click.echo(get_session_project_client().documents.count(
        collection=collection_id, filter=filter_, text=text_))
Beispiel #11
0
def remove(ctx, document_id, collection_id):
    """Removes a document"""
    get_session_project_client().document.remove(identity=document_id,
                                                 collection=collection_id)
    click.echo('Document removed')
Beispiel #12
0
def create(ctx, data):
    """Creates a collection"""
    get_session_project_client().collection.create(data=data)
    click.echo('Collection created')
Beispiel #13
0
def count(ctx, filter_, text_):
    """Number of collections"""
    click.echo(get_session_project_client().collections.count(filter=filter_,
                                                              text=text_))
Beispiel #14
0
def find(ctx, filter_, text_, pretty):
    """Find collections"""
    for collection in get_session_project_client().collections.find(
            filter=filter_, text=text_):
        echo_json(collection, pretty=pretty)
Beispiel #15
0
def get(ctx, document_id, collection_id, property_, pretty):
    """Returns a document"""
    echo_json(get_session_project_client().document.get(
        identity=document_id, collection=collection_id, property=property_),
              pretty=pretty)
Beispiel #16
0
def remove(ctx, collection_id, filter_):
    """Removes documents"""
    click.echo('Removed documents: %s' %
               get_session_project_client().documents.remove(
                   collection=collection_id, filter=filter_)['deleted'])
Beispiel #17
0
def get(ctx, collection_id, pretty, property_):
    """Returns a collection"""
    echo_json(get_session_project_client().collection.get(
        identity=collection_id, property=property_),
              pretty=pretty)