Пример #1
0
def create_collection_document(data):
    """Create collection in Database"""

    constructor = Constructor()
    name = data.get('name')
    constructor.factory(kind='Collection', create=True, name=name)
    create_meta_collection_doc(data, 'document')

    return True
Пример #2
0
def create_collection_edge(data):
    """Create edge in Database"""

    constructor = Constructor()
    name = data.get('name')
    constructor.factory(kind='Edges', create=True, name=name)
    create_meta_collection_doc(data, 'edge')

    return True
Пример #3
0
def create_graph(data):
    """Create graph in Database"""

    constructor = Constructor()
    name = data.get('name')
    links = data.get('links')
    constructor.factory(kind='Graph', create=True, name=name, links=links)

    return True
Пример #4
0
def create_meta_collections():
    """Creates meta collections."""
    constructor = Constructor()

    try:
        constructor.factory(kind='Collection',
                            create=True,
                            name=app_config.META_COLLECTION,
                            create_indexes=False)
    except exceptions.CollectionAlreadyExist:
        pass

    try:
        constructor.factory(kind='Collection',
                            create=True,
                            name=app_config.META_GRAPH,
                            create_indexes=False)
    except exceptions.CollectionAlreadyExist:
        pass

    try:
        constructor.factory(kind='Collection',
                            create=True,
                            name=app_config.META_QUERY,
                            create_indexes=False)
    except exceptions.CollectionAlreadyExist:
        pass

    try:
        constructor.factory(kind='Collection',
                            create=True,
                            name=app_config.INTERNAL_METADATA,
                            create_indexes=False)
    except exceptions.CollectionAlreadyExist:
        pass
Пример #5
0
def patch_document(name, key, data):
    """Partial update document from Database"""

    document = get_document(name, key)

    spec = app.config['SPECS'].get('documents_partial')
    util.json_validate(spec).validate(data)

    for key in data:
        if key == 'properties':
            for idx in data[key]:
                document['properties'][idx] = data[key][idx]
        elif key == 'properties_metadata':
            for idx in data[key]:
                document['properties_metadata'][idx] = data[key][idx]
        elif key == 'name':
            if data[key]:
                document[key] = data[key]
        else:
            document[key] = data[key]

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection', name=name)

    inst_doc = Document(inst_coll)
    doc = inst_doc.update_document(document)

    return doc
Пример #6
0
def update_edge(name, key, data):
    """Update edge from Database"""

    get_edge(name, key)

    spec = app.config['SPECS'].get('edges')
    util.json_validate(spec).validate(data)
    edge = {
        '_key': key,
        '_from': data['from'],
        '_to': data['to'],
        'id': data['id'],
        'name': data['name'],
        'provider': data['provider'],
        'timestamp': data['timestamp'],
        'properties': data.get('properties'),
        'metadata': data.get('metadata')
    }

    constructor = Constructor()
    inst_edge = constructor.factory(kind='Edges', name=name)

    inst_doc = Document(inst_edge)
    doc = inst_doc.update_document(edge)

    return doc
Пример #7
0
def patch_document(name, key, data):
    """Partial update document from Database"""

    document = get_document(name, key)

    for key in data:
        if key == 'properties':
            for idx in data[key]:
                document['properties'][idx] = data[key][idx]
        elif key == 'properties_metadata':
            for idx in data[key]:
                document['properties_metadata'][idx] = data[key][idx]
        elif key == 'name':
            if data[key]:
                document[key] = data[key]
        else:
            document[key] = data[key]

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection', name=name)

    inst_doc = Document(inst_coll)
    doc = inst_doc.update_document(document)

    return doc
Пример #8
0
def patch_edge(name, key, data):
    """Partial update edge from Database"""

    edge = get_edge(name, key)
    for key in data:
        if key == 'from':
            edge['_from'] = data[key]
        elif key == 'to':
            edge['_to'] = data[key]
        elif key == 'properties':
            for idx in data[key]:
                edge['properties'][idx] = data[key][idx]
        elif key == 'properties_metadata':
            for idx in data[key]:
                edge['properties_metadata'][idx] = data[key][idx]
        elif key == 'name':
            if data[key]:
                edge[key] = data[key]
        else:
            edge[key] = data[key]

    constructor = Constructor()
    inst_edge = constructor.factory(kind='Edges', name=name)

    inst_doc = Document(inst_edge)
    doc = inst_doc.update_document(edge)

    return doc
Пример #9
0
def patch_edge(name, key, data):
    """Partial update edge from Database"""

    edge = get_edge(name, key)

    spec = app.config['SPECS'].get('edges_partial')
    util.json_validate(spec).validate(data)
    for key in data:
        if key == 'from':
            edge['_from'] = data[key]
        elif key == 'to':
            edge['_to'] = data[key]
        elif key == 'properties':
            for idx in data[key]:
                edge['properties'][idx] = data[key][idx]
        elif key == 'properties_metadata':
            for idx in data[key]:
                edge['properties_metadata'][idx] = data[key][idx]
        elif key == 'name':
            if data[key]:
                edge[key] = data[key]
        else:
            edge[key] = data[key]

    constructor = Constructor()
    inst_edge = constructor.factory(kind='Edges', name=name)

    inst_doc = Document(inst_edge)
    doc = inst_doc.update_document(edge)

    return doc
Пример #10
0
def delete_edge(name, key):
    """Get edge from Database"""

    constructor = Constructor()
    inst_edge = constructor.factory(kind='Edges', name=name)

    inst_doc = Document(inst_edge)
    doc = inst_doc.delete_document(key)

    return True
Пример #11
0
def get_edge(name, key):
    """Get edge from Database"""

    constructor = Constructor()
    inst_edge = constructor.factory(kind='Edges', name=name)

    inst_doc = Document(inst_edge)
    doc = inst_doc.get_document(key)

    return doc
Пример #12
0
def get_document(name, key):
    """Get document from Database"""

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection', name=name)

    inst_doc = Document(inst_coll)
    doc = inst_doc.get_document(key)

    return doc
Пример #13
0
def delete_document(name, key):
    """Get document from Database"""

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection', name=name)

    inst_doc = Document(inst_coll)
    doc = inst_doc.delete_document(key)

    return True
Пример #14
0
def create_collection_edge(data):
    """Create edge in Database"""

    spec = app.config['SPECS'].get('collections')
    util.json_validate(spec).validate(data)

    constructor = Constructor()
    name = data.get('name')
    edge = constructor.factory(
        kind='Edges', create=True, name=name)

    return True
Пример #15
0
def create_collection_document(data):
    """Create collection in Database"""

    spec = app.config['SPECS'].get('collections')
    util.json_validate(spec).validate(data)

    constructor = Constructor()
    name = data.get('name')
    collection = constructor.factory(
        kind='Collection', create=True, name=name)

    return True
Пример #16
0
def update_query(key, data):
    """Update query in Database"""

    query = make_query(data)

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection',
                                    name=app.config['META_QUERY'])

    inst_doc = Document(inst_coll)
    doc = inst_doc.update_document(query)

    return doc
Пример #17
0
def create_query(data):
    """Create query in Database"""

    query = make_query(data)

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection',
                                    name=config.META_QUERY)

    inst_doc = Document(inst_coll)
    doc = inst_doc.create_document(query)

    return doc
Пример #18
0
def create_graph(data):
    """Create graph in Database"""

    spec = app.config['SPECS'].get('graphs')
    util.json_validate(spec).validate(data)

    constructor = Constructor()
    name = data.get('name')
    links = data.get('links')
    graph = constructor.factory(
        kind='Graph', create=True, name=name, links=links)

    return True
Пример #19
0
def create_meta_collection_doc(data, kind):
    """Create document in meta_collection"""

    constructor = Constructor()
    inst_coll = constructor.factory(
        kind='Collection', name=config.META_COLLECTION)

    inst_doc = Document(inst_coll)
    document = {
        '_key': data.get('name'),
        'name': data.get('name'),
        'alias': data.get('alias'),
        'kind': kind,
        'icon': data.get('icon'),
    }
    doc = inst_doc.create_document(document)

    return doc
Пример #20
0
def create_meta_graph_doc(data):
    """Create document in meta_graph"""

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection',
                                    name=app.config['META_GRAPH'])

    inst_doc = Document(inst_coll)
    document = {
        '_key': data.get('name'),
        'name': data.get('name'),
        'links': data.get('links'),
        'alias': data.get('alias'),
        'icon': data.get('icon'),
        'description': data.get('description'),
    }
    doc = inst_doc.create_document(document)

    return doc
Пример #21
0
def create_edge(name, data):
    """Create document-edge in Database"""

    constructor = Constructor()
    inst_edge = constructor.factory(kind='Edges', name=name)
    edge = {
        '_key': util.make_key(data),
        '_from': data['from'],
        '_to': data['to'],
        'id': data['id'],
        'name': data.get('name', ''),
        'provider': data['provider'],
        'timestamp': data['timestamp'],
        'properties': data.get('properties'),
        'properties_metadata': data.get('properties_metadata')
    }

    inst_doc = Document(inst_edge)
    doc = inst_doc.create_document(edge)

    return doc
Пример #22
0
def create_document(name, data):
    """Create document in Database"""

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection', name=name)

    document = data
    document = {
        '_key': util.make_key(data),
        'id': data['id'],
        'name': data.get('name', ''),
        'provider': data['provider'],
        'timestamp': data['timestamp'],
        'properties': data.get('properties'),
        'properties_metadata': data.get('properties_metadata')
    }

    inst_doc = Document(inst_coll)
    doc = inst_doc.create_document(document)

    return doc
Пример #23
0
def update_document(name, key, data):
    """Update document from Database"""

    get_document(name, key)
    document = {
        '_key': key,
        'id': data['id'],
        'name': data.get('name', ''),
        'provider': data['provider'],
        'timestamp': data['timestamp'],
        'properties': data.get('properties'),
        'properties_metadata': data.get('properties_metadata')
    }

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection', name=name)

    inst_doc = Document(inst_coll)
    doc = inst_doc.update_document(document)

    return doc
Пример #24
0
def update_edge(name, key, data):
    """Update edge from Database"""

    get_edge(name, key)
    edge = {
        '_key': key,
        '_from': data['from'],
        '_to': data['to'],
        'id': data['id'],
        'name': data.get('name', ''),
        'provider': data['provider'],
        'timestamp': data['timestamp'],
        'properties': data.get('properties'),
        'properties_metadata': data.get('properties_metadata')
    }

    constructor = Constructor()
    inst_edge = constructor.factory(kind='Edges', name=name)

    inst_doc = Document(inst_edge)
    doc = inst_doc.update_document(edge)

    return doc
Пример #25
0
def create_edge(name, data):
    """Create document-edge in Database"""

    spec = app.config['SPECS'].get('edges')
    util.json_validate(spec).validate(data)

    constructor = Constructor()
    inst_edge = constructor.factory(kind='Edges', name=name)
    edge = {
        '_key': util.make_key(data),
        '_from': data['from'],
        '_to': data['to'],
        'id': data['id'],
        'name': data['name'],
        'provider': data['provider'],
        'timestamp': data['timestamp'],
        'properties': data.get('properties'),
        'metadata': data.get('metadata')
    }

    inst_doc = Document(inst_edge)
    doc = inst_doc.create_document(edge)

    return doc
Пример #26
0
def create_document(name, data):
    """Create document in Database"""

    spec = app.config['SPECS'].get('documents')
    util.json_validate(spec).validate(data)

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection', name=name)

    document = data
    document = {
        '_key': util.make_key(data),
        'id': data['id'],
        'name': data['name'],
        'provider': data['provider'],
        'timestamp': data['timestamp'],
        'properties': data.get('properties'),
        'metadata': data.get('metadata')
    }

    inst_doc = Document(inst_coll)
    doc = inst_doc.create_document(document)

    return doc
Пример #27
0
def update_document(name, key, data):
    """Update document from Database"""

    get_document(name, key)

    spec = app.config['SPECS'].get('documents')
    util.json_validate(spec).validate(data)
    document = {
        '_key': key,
        'id': data['id'],
        'name': data['name'],
        'provider': data['provider'],
        'timestamp': data['timestamp'],
        'properties': data.get('properties'),
        'metadata': data.get('metadata')
    }

    constructor = Constructor()
    inst_coll = constructor.factory(kind='Collection', name=name)

    inst_doc = Document(inst_coll)
    doc = inst_doc.update_document(document)

    return doc
Пример #28
0
def create_meta_collections():
    """Creates meta collections."""
    constructor = Constructor()

    try:
        constructor.factory(kind='Collection',
                            create=True,
                            name=app_config.META_COLLECTION)
    except exceptions.CollectionAlreadyExist:
        pass

    try:
        constructor.factory(kind='Collection',
                            create=True,
                            name=app_config.META_GRAPH)
    except exceptions.CollectionAlreadyExist:
        pass

    try:
        constructor.factory(kind='Collection',
                            create=True,
                            name=app_config.META_QUERY)
    except exceptions.CollectionAlreadyExist:
        pass